About Adam Young

Once upon a time I was an Army Officer, but that was long ago. Now I work as a Software Engineer. I climb rocks, play saxophone, and spend way too much time in front of a computer.

Deadpoint

When you throw something straight up in the air, there is a point where it has no movement at all. Before this point, it is rising, after this point it is falling. But for an instant, it is floating. This is the deadpoint.

Thanks, Randall!

(Courtesy of Randall Munroe)

When climbing, you want your body at the deadpoint when grabbing a climbing hold. If you grab before the deadpoint, your own momentum will continue to carry you upward and off the hold. If you grab after the deadpoint, your downward momentum will put additional strain on your fingers, making it harder to hold on. If you grab exactly at the deadpoint, you will maximize your ability to hold on to small holds.

Don’t do Java bean properties in C++

The reason why Java has the bean API is to ensure that the caller does not delete the object when setting it.

void setX(String val){

if (val == null) return;

this.x = val;

}

This is not necessary in C++, since the parent object owns the memory of the child object.  The equivalent C++ code would be simple

o.x = val;

If you want to do validation (see my earlier posts about regex validation) use a subclass that does the validation in its constructor and assignment operator.

Basic Body Position for Rock Climbing

The first rule of climbing is to climb on straight arms.

Compare these two pictures.

the_x.jpegbent_arms.jpeg

The climber in the first picture is supporting his weight on his skeleton. In both pictures, the climbers are actively using the muscles that keep the fingers curled, but the first climber is using only those muscles, the second climber is using far more. Aside from the obvious bicep and latissimus dorsai muscles, the bent arm position in the second picture shows a climber stressing out the muscles in the forearm. It is this mistake, spending too much time on bent arms, that is responsible for the pumped feeling a new climber gets after a few climbs. There is a tendon system that runs down your arm and connects to your back. when you climb on straight arms, you hang on this tendon system. It is a holdover from our monkey ancestors that swung through the trees. Remember crossing the monkey bars as a kid? You swung from straight arm to straight arm. When you climb up, you want to use straight arms, too.

Try this simple experiment:

Hold a book by the two fingers, one at the top of the binding, one at the bottom. If you hold the spine perfectly vertical, the pages splay out. If you tilt the book so the the top is no longer over the bottom, the whole book will rotate so the open pages are all pointed straight at the ground.

In geometry, we learn that a triangle is defined by three points, and that a plane is also defined by three points. We can make a triangle out of our book example with one point on the top of the spine, one on the bottom of the spine, and one in the center of gravity. What we see is that the plane defined by these three points will always rotate itself to align perpendicular to the ground. The two fixed points act like the hinges on a poorly hung door. The door will always swing to point toward the center of the earth.

This holds true for climbing. The simplest example is a climber holding on with both hands and no feet. The climber naturally dangles toward the ground. For people, the center of balance is typically the abdomen. Thus the triangle is formed by the two hands and the navel.

.the_triangle.png

In order to move smoothly, you are going to be holding on to the wall with only two points of contacts much of the time. In order to it is far more important that you align the triangle of you body with the ground. If you don’t you will be fighting your bodies tendency to rotate. One way that climbers do this is to only move one limb at a time while keeping three in contact with the wall. This limits your options significantly. The other way is to try and overuse the muscles of the forearm to battle the rotation, causing premature flame-out.

The longest line of the body if from hand to opposite side foot. This follows either the red or green line of the body. Note that where these two lines cross is near the center of balance.

the_x.png

Let’s put together these items. The longest line of the body is from one foot to the opposite side hand, and this line crosses through the center of balance. We want to keep the center of balance in line with the contact points on the wall. This leads to body positions similar to the one displayed below.

in_line.jpeg

First and foremost, the climber is holding on with a straight left arm. This climbers body is in line from left hand, through abdomen, to right foot. His left foot and right arm counter balance each other to keep his body in line. If he finds his center of balance is off, he can adjust either limb to bring it back aligned. If he moves is right hand in or out along the dotted red line, his center of balance will adjust in or out parallel to that line. Additionally, he can move his hand in a circle and adjust his center of balance accordingly as well.

in_line_hand_adjust.png

His left leg follows the same rules. If he extends it out along the red dotted line,it pulls his center of gravity out along it. If he lowers his leg along the circle, he pulls his center of gravity in toward his body.

in_line_foot_adjust.png

The general pattern in climbing, especially in the gym, it reach up with the inside arm, and then to pivot so that arm becomes the outside arm. When you reach up with your left hand, you left hip will be pressed against the wall. Once you have that hold, you will pivot so that your right hand is against the wall. The climber in the picture above could well end up in a position similar to this:

right_side_against_wall.jpeg

The climber is leaning back against the side pull held by the left hand. He flags his left foot to provide a counter balance. This moves his center of gravity toward the line between his right foot and his left hand. If he continues to torque around on this axis, he can push with his toe against the wall to provide a counter force. Once he grabs the hold with his right, he is likely to step through so his left hip is against the wall, standing on the outside of the left foot. This pattern of alternating the hip against the wall while reaching with the inside arm is a motion similar to swimming or salsa dancing.

Contrast this with an attempt to use both limbs on the same side of the body. When the climber lets go with the right hand, and unloads the right foot, gravity pivots his body around the axis of the two remaining points of contact and the climber ends swinging out from the wall, a movement called “Barn Dooring”

barn_door.png

Here the green line shows the axis of the pivot, and the red arrow the movement of the swing.

C++ optimization for string16

Since wchar_t is 32 bits on Linux, I need to transform wstring to a different type in order to call the ODBC functions. The Windows code, on the other hand, can just use wstrings c_str() function to access the internal representation of the string. My goal is to minimize the code differences between platforms. On Linux, I will create a new class for string16 see earlier post). On Windows, I will just typedef wstring to string16. My hope then is to get the OS specific code down to the Linux implementation of string16, and to have the typedef optimize away the differences.

Here is a simplified version of the code that will be built and run on Windows:

typedef wstring& sqlstring;

void dothing(wstring s){
sqlstring sql(s);
wcout << sql << endl;
}

void doanother(wstring s){
wcout << s << endl;
}

And the result of building and disassembling using g++. Note that the code is the same. Hopefully Windos C++ complier will behave the same.

0000000000400ae0 <_Z9doanotherSbIwSt11char_traitsIwESaIwEE>:
400ae0: 48 83 ec 08 sub $0x8,%rsp
400ae4: 48 89 fe mov %rdi,%rsi
400ae7: bf c0 12 60 00 mov $0x6012c0,%edi
400aec: e8 07 fe ff ff callq 4008f8 <_ZStlsIwSt11char_traitsIwESaIwEERSt13basic_ostreamIT_T0_ES7_R
KSbIS4_S5_T1_E@plt>
400af1: 48 83 c4 08 add $0x8,%rsp
400af5: 48 89 c7 mov %rax,%rdi
400af8: e9 0b fe ff ff jmpq 400908 <_ZSt4endlIwSt11char_traitsIwEERSt13basic_ostreamIT_T0_ES6_@pl
t>
400afd: 90 nop
400afe: 66 90 xchg %ax,%ax

0000000000400b00 <_Z7dothingSbIwSt11char_traitsIwESaIwEE>:
400b00: 48 83 ec 08 sub $0x8,%rsp
400b04: 48 89 fe mov %rdi,%rsi
400b07: bf c0 12 60 00 mov $0x6012c0,%edi
400b0c: e8 e7 fd ff ff callq 4008f8 <_ZStlsIwSt11char_traitsIwESaIwEERSt13basic_ostreamIT_T0_ES7_R
KSbIS4_S5_T1_E@plt>
400b11: 48 83 c4 08 add $0x8,%rsp
400b15: 48 89 c7 mov %rax,%rdi
400b18: e9 eb fd ff ff jmpq 400908 <_ZSt4endlIwSt11char_traitsIwEERSt13basic_ostreamIT_T0_ES6_@pl
t>
400b1d: 90 nop
400b1e: 66 90 xchg %ax,%ax

Reading C++ symbols in a binary

objdump -t will pull the raw symbols out of an elf binary, but it is mangled format like this

0000000000000000       F *UND*  0000000000000006              _ZNSt13basic_ostreamIwSt11char_traitsIwEElsEPFRS2_S3_E@@GLIBCXX_3.4

c++ file will translate this to a human readly string that maps to the rigianlfunction definition:

 adyoung@adyoung-devd$ echo _ZNSt13basic_ostreamIwSt11char_traitsIwEElsEPFRS2_S3_E@@GLIBCXX_3.4 | c++filt
std::basic_ostream<wchar_t, std::char_traits<wchar_t> >::operator<<(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& (*)(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >&))@@GLIBCXX_3.4

To do this for an entire file, you want to print only the last column, a task custom made for awk:

 objdump -t   casttest | awk ‘{print $(NF)}’ | c++filt

Dreams of the wrong uniform

People often talk about the dream where they are back in High School, and they have a test, but they haven’t studied.

My stress dreams involve USMA.  I am invariably in the wrong place and in the wrong uniform.  Here are a few variations:

It is graduation day.  My company is in Full Dress over White, marching to Michie Stadium.  I am in civilian clothes.

I am running across north Area in PT clothes and the yellow windbreaker we were issued back then.   I have to get changed into As-for-class and get to lunch formation.

I am walking around in Dress Gray and under my long overcoat.  I realize I am no longer authorized to wear it, and so I have to get back to my hotel room to change before someone sees me.

All of these dreams have the same stress feeling I had a decade and a half ago. Hail Alma Mater Dear…

D & D

A slew of popular sites have posted homages to Gary Gygax, one of the original creators of Dungeons and Dragons.

Like many geek kids, I was in to D&. Note that we always referred to it this way, not by the full title. Aside from Dungeons and Dragons being to unwieldy to say, we didn’t need all those extra syllables. It was D&D and we knew what we meant.

Steve Graber, older brother to my friend Brian, got us introduced when we were in, I’m going to guess fourth grade. Steve had learned to play with a mythical friend of his that I never ended up meeting. He was a 12 year leading a group of us 9 year olds on our first adventure. We played in the shed house My. Graber built in the back yard. It had a large picnic table that we all could fit around. It was Our Place. Oh, sure, there were not “keep out” signs, but no-one would come in there.

I was already in to Science Fiction. My Dad had worked on the Apollo Project back before. He taught my Sister and me about gravity and how solar system objects revolve around each other. I was drawing space ships and playing Star Wars. But the D&D game fired my imagination with the added dimension of Fantasy.

I’ve always been a reader. I was way above grade level before I ran into D&D. So I can’t claim that the game got me reading. But it did direct me at history. The monsters of D&D lead me to mythology, first Greek, and then Norse. From King Arthur and the Knights of the Round Table I learned about weapons and castles, horses and armor. Other sources lead me to Greek Phalanxes and Roman Legions.

I won’t claim that D&D alone put me on the road to applying to West Point. But D&D certainly was encouraged the ideal of Chivalry. The numbers and data tracking appealed to the budding computer scientist in me. The books were great fuel for my reading furnace. The Paladin and Ranger characters, coupled with the physical training I got from Wrestling, made a pretty convincing ideal.

I came across an old Dungeon Masters (DM) Log I had. It recorded many of the adventures I lead when I was 10-14 years old. I always ended up DM, I guess since I was always arraigning games. While you get to play as a DM, you need to keep a part of you reserved, preventing you from fully immersing in the game. I enjoyed orchestrating the games. I think this, too, was a form of leadership training that helped bring me to applying to USMA.

One thing that has waned over the years has been my interest in the fighting aspect of it. It is harder and harder for me to enjoy a game that simulates killing, even if it is wretched, evil creatures. The profession of soldier makes you aware of killing, even if you never have to perform the act (I never did). The concepts of Good and Evil as Absolutes are too easily thrown about. I’ve seen the potential to do evil (in Hebrew Yetsir Ha Ra) in my own soul and realize that to many people, I would be considered evil. I do still love the concepts of Law and Chaos, but find them to be complimentary, both required for any system to work. I’ve also realized that the game has to be tailored to the ability levels of the characters or they will be quickly killed off. The universe is not so nice as to only push adversity in our way that is just difficult enough to force us to grow, but not so bad as to maim us for life. As a new Dad, I have a newfound respect for life, especially in its most vulnerable stages.

The Game of Dungeons and Dragons provided me with a great outlet It proved to be a wonderful seed for creativity, and a great learning tool for data management.