Thursday, January 7, 2010

Day 4

Unfortunately much of today was spent doing things other than writing code, but I still was able to gather some useful information. I attended another iteration meeting with a different client today, and naturally it was a bit different. I also began designing through uml documentation, my text box's final form.

What I learned today:

Underlining Principles of being a Software Craftsman:

*Estimating tasks and using the point system - Accurately assessing how long any task will take, how difficult it will be, and thus how many points it should be worth, is never easy. The points might initially be based off of man ours, but quickly a point becomes a point based on how many points you judged another similar task would take. This means the point system is usually indefinite. Especially when you just begin talking about a feature or task, write it on a note card, and are suddenly trying to guess the full extent of its complexity. Of course any developer will get better and better at this over time, but still can be surprised that a task took three times as long as he/she thought.
One strategy that I saw today to counteract this issue is having a group of developers all vote at once on a feature. They would hold out there hands and on three stick out fingers according to how many points they thought the task was worth, as if they were playing a game of rock paper scissors. This can increase the accuracy of the estimation, when you average all of the guesses together, but it still isn't perfect.
The challenge in estimating points leads to the challenge in calculating a team's average velocity (where velocity is how many points they finish in an iteration). A team's velocity might be 18 one iteration, and just a few weeks later it might suddenly be half that. This makes me think that there has to be a better and more accurate way of judging the speed of any group of developers, but I haven't thought of one yet...

*Taking a step back and looking at the big picture - After Spiking out my text box for a few days, I got a pretty good understanding of how each and every piece should work. I was constantly fiddling, moving things around, trying out new ideas, and experimenting with different strategies. I was pretty confident that I understood how to make a text box.
Then Micah asked me to design the text box, how I would write it in my final version, in its entirety. He told me to write it down on paper using the UML design structure. So after I did a little research, I got a pen and paper and started drawing boxes and connecting lines together. The more I drew the worse everything got. It wasn't long before I realized a pen... just wasn't going to work out. Micah of course already knew this, and by the time I went over to him he was holding a pencil and big eraser for me to use.
I tried again, and this time I had an even better idea of how I wanted my system to work. As I began to tie my classes together started holding more and more of my task in my brain at once. Then there was a single moment when an awesome wave rushed through me and I realized I had moved out several levels of abstraction and was now holding my entire project in my brain in full detail. It was at this point that I began noticing many patterns, and a repetitive nature I had not seen when I was first hacking away at my code.
This was my Rubik's Cube moment. When I saw strategies I could use to solve my problem as a whole rather than side by side. I felt like an architect who had just made a model of my building, tore it down, and began making sketches.
I think this is another thing that defines a Craftsman. A Craftsman will have the ability to see the big picture, and draw lines between what seemed to be unconnected places.

General Knowledge of Language:

Unfortunately I didn't do a whole lot of coding today so I didn't learn any general rules of languages.

Specific Knowledge:

*Macs and PCs use the ctrl and command buttons quite differently. On a Mac you can use Cmd to jump to opposing ends of text (in a text box) and use Alt to jump to the end of a word. A PC however uses Ctrl to jump to the end of words, and for Java Swing text boxes at least, Alt doesn't let you do a arrow jumping... I know this is world shaking, but it is interesting none the less. Also, Ctrl C is actually an ASCII character.

Thats all for today. Lots of driving through thick snow, and sitting in on iteration meetings.

Wednesday, January 6, 2010

Day 3

Once again today I worked on finishing up the text box, getting mouse selection, copy paste cut, select all, and other similar features. I also sat in on an iteration meeting with one of 8thLight's clients.

What I learned today:

Underlining Principles of being a Software Craftsman:

* Customer Interaction - A Craftsman needs to always know that he can never know exactly what his customer wants. Most of the time, not even the customer knows what he/she wants at the start of a project. This is why it is important to have a constant feed back process and interaction between the Craftsman and the customer. When you consider any craft like wood work, designing a building, or painting a portrait, there is always in interaction between the crafter and his customer. A carpenter asks the customer what they want, and perhaps shows some styles that the customer might like before making the table, or dresser, or anything of the like. An architect will typically write up several drafts, present them, and the make changes according to the requests of the customer. A painter painting a portrait has his customer directly in front of him/her. All these crafts require Craftsman/Customer interaction.

Software has to take this interaction even one step further. Software isn't like a chair, that has one main purpose. It isn't like a building, that once built, requires minimal to no interaction at all with the architect. And it is quite different that painting a portrait, which has the complete specifications laid out in front of it and just needs some flavor. No, software is a constantly changing, continuously dynamic, and relentlessly evolving entity that can't simply be spelled out at the start. Software's interactive nature alone requires it to be nurtured to fruition. All these crafts have another thing in common though... When the customer gets the end result, they know whether or not they like it.
This is another thing that separates a coder from a Craftsman. A Craftsman must care about his/her craft and remain on a ceaseless quest to improve and satisfy. It is because of this truth that a Craftsman must always be working with the customer. If the customer isn't sure what they are looking for, then the Craftsman sure as h*ll better find out before spending weeks developing a product. If the customer knows what they are looking for, but can't quite explain it completely or clearly, then the Craftsman needs to be interacting and presenting little demos to divulge what the customer is picturing. However, this picture is always subject to change.

Even after discovering what the customer is looking for, they might not want that two months later, and instead have a new picture or strategy in mind. This is why the Agile Method teaches all programmers to use iterations. Don't write the whole project all at once. Write small bits at a time, and every one or two weeks (or sooner if it is reasonable) demonstrate the product and make sure you are still going in the write direction.

General Knowledge of Language:

* When using a language like Java, or C, with huge libraries already built in, be weary that anything you are writing might already exist in the library. I wrote a few methods today, nothing huge but still took a decent chunk of time, that already existed in the Java libraries. Though the preexisting methods weren't exactly what I needed, I at least could have used them as templates to save myself some time.

* String buffers rule. If ever you have a batch of text, constantly subject to change, use a StringBuffer instead of a regular String. Anytime you add to a String you are actually creating a whole new string with the new text included into it. With a StringBuffer you can just add stuff anywhere you want quite cheaply.

Specific Knowledge:

More on making text boxes.
* Making selection really useable. Once you have a batch of text selected, there is a lot you have to be able to do with it.
- Deselecting: There are actually hordes of ways to deselect text, such as: clicking but not dragging in the box, clicking and dragging on empty space inside the box, (depending on preferences) clicking outside the box, pressing an arrow key, pressing tab, and a few more too. All of these need to be implemented before you can even begin to think you have a tolerable selection system.
- Deleting selected text: Naturally you can do this by hitting the delete or BackSpace button, but you can also replace the text with another character. This can be a little interesting when replacing the text with a capital letter (holding shift - the same key you use to select with arrow keys. I checked to see if shift was pressed to see if I was in selection mode, so this popped up as a tiny bug), though not to difficult.
-Moving the cursor to opposite ends of the selection: When you select some texts starting on the left and ending on the right and then you hit the left arrow (while everything is still selected) you need to pop the cursor back to where it started instead of one left of where it is now.
- Batch selecting: Since there are a few keys you can hold to manipulate your scrolling (like holding command or alt and then an arrow key) you have to keep track of several manipulators at once.
*In Java, all the extra keys like shift, alt, cntrl, and command are manipulators with their own codes. When several of these are being held at once, the manipulators just add up to unique numbers. They are all actually 1 bit in a binary string, so for example shift is bit 1 and when it is held and you call e.getManipulators (where e is a KeyEvent) it returns 1.
Cntrl is bit 2, when getManipulators is called it returns 2.
Cmd is bit 3, and returns 4.
Alt is bit 4, and returns 8.
When shift and cmd are both pressed, getManipulators will return 5. So in order to tell if I still needed to be selecting text while multiple manipulators were being held, I just used the mod function to check to make sure the manipulators result was odd (thus shift is being held). Then I could cmd shift select all text, or alt select some of the text.
*To Alt select I also needed to search for the nearest space, to stop at the end of the word.

-Finally, there was the Copy Paste Cut ordeal. At first I tried out using a local string to be my personal clipboard. This worked painlessly enough. Just had to make sure the cursor ended up in the right spot, and the proper text was copied and unselected and such.
Then I had to put my fake clipboard into the real system clipboard. Luckily Java has a nice Toolkit that gives this to you. Toolkit.getDefaultToolkit().getSystemClipboard() - The system clipboard uses something called a Transferable for it contents.
Putting text in was easy enough. I used a StringSelection object (which is a Transferable) and then pushed that into the clipboard.
Getting the text back out was only slightly more complicated since a Transferable can be text or pictures, or other unedigeties, thus I had to make sure it was holding text. Did so with this:
Transferable contents = systemClipboard.getContents(null);
boolean hasText = (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
Then if hasText was true, I did a try catch to see if I could put the text into a String and voila!

* Mouse selection: Fortunately there was some built in stuff to make mouse selection a little bit easier, but there was still a lot to think about to get it to work. The TextLayout object I was using to hold the text for the text box had a method called hitTextChar( int x, int y) which returns a TextHitInfo. You can then use the TextHitInfo to get the index of the character, see if you click the leading or trailing edge of the character, and all sorts of other useful tidbits.
Keeping track of the cursor, and selection indices could be a little tricky... especially around the edges, but not quite as hard as I had first imagined. I ended up using most of the same code I used for scroll selecting, with a few tweaks.

Thats pretty much all. There are probably some things I forgot to mention, and still a few things I have to do to make it completely smooth and wonderful. Then of course I have to rewrite most of it using TDD. It wasn't nearly as simple as I had first imagined. Such is always the case. Murphy's Law never fails. Things always take 3 times as long as you think. Even if you realize this, and compensate, it will take 3 times as long as your new estimate. Thats why I have decided to say everyone of my tasks and stories will take until the end of the universe to complete! Doncha want me on your corporate team now? I'll only ever surprise you with my speediness.

Tuesday, January 5, 2010

Day 2

Today I spent most of my time working on making a text box. It sounds menial, but surprisingly there is a lot to it.

Let me first try out my organization strategy again, and with it I will explain what I learned about the challenges of the dreaded text box.

What I learned today:

Underlining Principles of being a Software Craftsman:

* Spiking - Although this is not directly an Agile method, it can be used as a strategy to practice being Agile. Spiking is a technique a developer will apply when they really have no idea how to write their project or task. Without knowledge of the organization, specific details, or even general gist of how he/she will write the code it is often exceedingly difficult to write any meaningful tests. In the end, this could slow him/her down. One way to get around this is to use spiking. The developer will just start writing code and trying several strategies to figure out which ones are the best fit to the problem. Whether it be just a few lines, or even a quick semi-functional program, Spiking can be used to gain a greater understanding of both the solution and the problem. Once he/she has sufficient understanding of the problem, or at least a good place to start, he/she would delete the written code and start again from scratch with TDD.

An analogy I thought of that describes this strategy or pattern is how one goes about solving a Rubik's Cube. If it is your first time ever solving a Rubik's Cube, you will likely try and do it one side at a time. You will do a few spins, move some blocks around, get your first side and leap with glee with your success. Then you will try getting another side, and in the process discover you have mess up the first side before you can get both. You plow on through and you start throwing confetti as you get your second side. Then comes the third side... and then the fourth... and the fifth... And finally when there is just the one side left, and you are terribly frustrated that it took you two years to get the fifth side, since you couldn't seem to keep the first and fourth ones together, you just throw down the cube. Every single turn you made messed up one or more sides. You never finish the cube.

This is the wrong way to solve a Rubik's Cube and the wrong way to write software. A learned cuber will know that you don't necessarily solve it one side at a time, but instead use strategies that allow you to decouple all the sides leaving you the ability to get them all at once. Though you wont get one side quite as fast (unless of course, as most learned cubers can, you can solve it uber fast), you will finish the whole cube much faster.

This is similar to the difference between writing clean, well tested, organized, decoupled, and readable code vs. just hacking away to get things to work. But to do this requires just a bit of foresight. Though in some cases you can simply write tests and they will lead you to an excellent solution, it is also possible you will write a flurry of tests that have nothing to do with an end solution. Just as it is important to know strategies to solve a Rubik's Cube, it is important to have some understanding of your software endeavor so that you may learn not to solve your problem one side at a time, and instead write effective tests that open the doors to solving the entire cube.

General Knowledge of Language:

Nothing that stands out. Lots of little tidbits about the Java libraries and mouse and key press events.

Specific Knowledge:

* Writing a text box requires a lot of work...
- The cursor: The cursor alone can be quite tricky to write. When you consider that it is just a vertical line that you draw in between letters and not some magical object that just glides to its proper location, you can likely see it requires some thought.
* First off, you need to make sure it doesn't get drawn on top of the letters. This means you must have some way to know the exact size and spacing that every single character requires.
* Then you must be certain it can scroll back and forth. Thus, there has to be something keeping track of where the cursor is in relation to not only the text box, the text itself. So it needs an X coordinate, as well as some character relation coordinate. I used a index that keeps track of its index in the string, and I update it for any left-right scrolling, deleting, and adding of characters.
* It has to be able to move with relation to spaces. Though easy, it is something to think about.
* It has to blink. I used a separate thread that pops it on and off with a 500ms sleep
* Finally, although there might be other things I am forgetting at the moment, it can't ever leave the text box. Thus your indexer wont always match the require X coordinate. I used an offset to make sure it never left the box when typing more than could in the box.

- Scrolling: Moving the visible letters side to side when there are more than can fit in the text box. Equally challenging as making the cursor since there are several offsets to keep track of, or at least many ways in which the text offset can change.
- Highlighting & Selecting with the arrows: Highlighting isn't too bad once you have a solid cursor. All you need to do is fill a rectangle from where the cursor was to where it is, and then draw the letters on top of that. Its selecting the letters that is more of the challenge. You need some way of grabbing the highlighted text, even though the highlight is just a rectangle. This can be done if you are keeping track of the relative index of the cursor to the characters, thus when you highlight you encapsulate both the X coordinates of the cursor, and characters of the text between the indices.
- Selecting with the mouse: This I am yet to complete, but it isn't easy by the looks of it. Since you no longer have any meaningful use of the cursor, you have to calculate which characters to select based solely on the X coors. This gets even more challenging since you can also be clicking on letters of varying sizes rather than conveniently between them.

There is a lot more to making text boxes than I had first imagined, and I haven't even dived fully into the issue, thus the scope of the problem is probably even lager than I imagine now.

It is a good thing I have been Spiking, because had I tried to write this straight away, I would have made a huge mess, and spent even longer doing it. Now at least when I write it for real, I will have some strategies to get it done right.

Other General coding goodies:

Nothing that comes to mind.

Monday, January 4, 2010

Day 1

Today was my first day working as an Apprentice at 8thLight. I will be working under Micah Martin for the next three months, soaking up all the knowledge I can.

I am not yet sure how I want to format my posts, so the next few shall be experimental.

What I learned today:

Underlining Principles of being a Software Craftsman:

* Communication - One of the fundamental and most crucial skills required by any software developer must be communication. A software developer not only writes code that communicates to the computer his/her intentions, but also code that communicates to all other developers whom may read your code in hopes to build upon your work.
This essential duality will help to define how I will learn to become a Craftsman. While I write any software, I must constantly keep three interpreters in mind. The computer being first, because obviously if the computer can't use it, its not worth much. Myself being second, since if I can't even understand my code, it really must be pretty crappy and I wont be able to work with it later. Finally, and perhaps most importantly, I must write code that another developer can easily follow. I think this last notion is what separates and developer from a Craftsman.

General Knowledge of Language:

* Though this is rather obvious to any experienced Java developer, and used to be quite obvious to me, I had a flutter in understanding today that I do not wish to have again. In any class method there is always an implied this. before objects.

* Java Threads - when creating a thread, the right way to make a quick and simple thread is to make it Runnable. By doing so, and check me if I am wrong, you will have a default run() method that will be called when you call .start() on the thread object.

Specific Knowledge:

* Java Swing uses a pyramid structure of panels to create any frame. The main Frame is the base structure, and on it will be many panels. Each panel can have several other panels inside of it, along with text boxes or buttons and things of the like.
When there is a mouse_click event, the event is first handed to the main Frame, which then checks the x,y coors of the click and scans all of the children panels to see which of them is at the clicked coor. Then this panel scans all of its panels or other widget thingies until it finds the one at the clicked coor. This goes on until there is either a panel with no children or the click is on a button widget or something of that nature. The mouse_click event is then handled by that object in whatever manner it feels.
Limelight props are also actually panels - called PropPanels, and have a similar structure.

Other General coding goodies:

* I learned there is an enormous depth to making text box cursors. Making it show up is easy enough, but it just goes down hill from there.

Extras:

* Angelique taught me quite a bit about my taxes, Simple IRA, health care plans and so forth. Fun fun.

* Also a fair amount about domains and hosting. Bought my first domain! JustinMMartin.com Still have to get something up there though.

All in all, a successful day.