Book Review: Secrets of the Rockstar Programmers

For my summer software reading I choose Secrets of the Rockstar Programmers by Ed Burns (yes I know the title is a bit cheesy…).  The book contains interviews with several male programmers, who have been in industry for at least 10 years, and have made significant contributions to in pure software such as creating a framework like Spring, or working on .NET architecture.

I thoroughly enjoyed the book, and the format makes it easy to digest.  However, it took me a while to get through, because I wanted to mentally process each programmer’s hard and soft skills, and lifestyle.  I thought it was an accurate depiction of what I believed the life of a programmer to be, and what it took to be stellar in the field of software.

There are a few common themes amongst these rock stars.  The vast majority of them have trouble with work life balance, the exception being British programmers, such as Adrian Colyer, CTO of SpringSource, who spends weekend with his family.  But for the rest, life is about solving problems and thinking about problems all the time.  The younger programmers, especially, have trouble balancing a family life, and attest to the fact the have to be told spend time with family or have learned to make time.  As far as hard skills go, Burns spent most of his time asking how these programmers keep up with technology trends, which blogs they read, and how to spot the latest language fads.  When it comes to soft skills, a few believe it is important to have a business sense if you want to advance, but there are a few in the minority, who would rather focus their efforts on development and technology.

I also enjoyed the historical perspective of the book.  Burns interviews programmers who pretty much started out with punch-cards, to those who have never had to manage memory.  Having been an electrical engineer, it is very interesting to see how hardware technology improved the overall productivity of programmers, and from the software side it peaked my curiosity of what’s to come in areas such as cloud computing and thinking about the computer as a network rather than an individual self-contained processing unit.

After finishing the book I started thinking of issues that I felt the book did not handle, the most obvious being there were no female programmers interviewed!  While I don’t believe it necessarily detracts from the essence of the book and what it takes to be a rockstar programmer, I think it highlights one of the fundamental problems that exists in the software industry: lack of female role models.  Those who did exist such as Grace Hopper, have yet to be  replaced by a new generation.  And I don’t think it is because software is particularly difficult, there are plenty of women surgeons and lawyers.

Leaving aside the gender bias, I also thought the book was too biased in interviewing programmers who worked for purely software based companies like Microsoft, SpringSource, and Sun.  While I think programmers at these companies are highly capable individuals, IMHO, they do not have the same resource constraints (both programmers and technology), and consumer driven issues such as security and high availability that programmers at places like Amazon.com, Facebook, and Mint.com face.  It has hardly, if any programmers like myself, who work for consumer web services, and are constantly fighting to solve scalability, security, and performance issues.  I would have liked to have learned about how people handle thinking about such issues given the fact that the age of the Internet is causing more software engineers to go into web services.

Overall, I would highly recommend reading Burns’ book, especially for those who are a few years out of college like myself, who are wondering what the next steps are in their career, and interested in learning from those who have paved the way.

Table Tips

Everyone once in awhile I get have to go for coding mode to designing and writing HTML and CSS for an internal tool or translating it into Velocity.  I’ve learned to use Firebug to debug most HTML and CSS issues.  Lately, I’ve been running into table formatting and layout issues, here are few tags and settings you can use or play with to help you resolve yours.

1.  rowspace: when this attribute is used, usually defining a table cell, it will take up space in the current row, and the row below, so watch out for any strange formatting.

2. valign: aligns font either to the top, bottom, or middle of a table cell.

3. td: make sure all rows in your table have the same number of table cells otherwise your table elements will be incorrectly formatted.  A caveat to this is if you use colspan and specify the number of td’s you want, then you dont have to explicitly use “<td></td>”.  Also if you are using th (headers) make sure that you have the same number of th’s as td’s.

4. input type=”hidden”: I love using this when submitting forms, because I can place an id of the object that the form is referencing, and then parse it out of a HttpServletRequest.

5. class: use this as much as possible and define your classes in CSS.  One thing I love doing is referencing the CSS file in Firebug and changing it on the fly.  To do this just open Firebug in Firefox, select ‘CSS’, and choose the file you want to edit from the ‘Edit’. Then you can easy change the values of the elements, and the changes are instantly rendered in the browser.  If you don’t want to see the changes then just refresh the page.  This doesn’t persist anything to your CSS files, it just helps you figure out what looks good.

Technical Interviewing 101

Having been at Mint.com for nearly 3 years I have had the unique opportunity of interviewing each of my bosses, and several of my co-workers.  Not to sound like a sycophant, but there is a reason why we hired each one of them.  During the interview process they surpassed all their peers in terms of having a passion for technology, engineering aptitude, stellar communication skills, and being curious enough to try the product prior to the interview!  I realize that not everyone is a “Rock Star Programmer” of the Ed Burns persuasion.  But there is some basic homework that needs to be done prior to each interview.

1. Brush up on algorithms:  I ask pretty basic freshman or sophomore level CS questions that I find people fail time and time again.  If you’ve been in industry for awhile its easy to forget all the algorithms you were taught, but that doesn’t mean you can’t crack open a book and skim through a few chapters on the basics such as sorting, big-O notation, and graph theory.

2. Write some code: there are countless websites out there that have practice interview coding questions such as implementing fibonacci iteratively vs recursively, or traversing a tree.  Please visit them!  And more specifically nail down the syntax for the language you are interviewing for.  Its not a deal-breaker, but it is a good idea to be as polished as possible.

3. When presented with a problem you don’t understand ask questions: while you might think you want to be an ace, and impress the interviewer by solving the problem as fast as you can and without any help, you do more damage by correctly answering the wrong problem.  Instead, pause to think about the problem, ask the interviewer questions on anything that seems unclear, and then proceed to solve the problem.  Remember we’re grading on process not just correctness, so its pivotal to communicate the solution, approach, and when you run into any roadblocks, because after all that is what’s going to happen on a day-to-day basis.

4. Read what your resume says and make sure you can explain it: anything you put on your resume is fair game, and employers will pick and choose projects to ask you questions. You should be able to communicate at a high-level the goal of the project and your role in it.  And if you put down that you know SQL, be prepared to write some SQL!

5. Use the product: I cannot emphasize this point enough. I know there is this pie-in-the-sky principle that as engineers our primary motivation is to work on tough problems regardless of what the business is, but if you haven’t even tried the product out how can we judge your enthusiasm for the company.  Being an engineer, especially at a startup is more than just cranking out code, its understanding the direction of the business, and being able to evolve with it and meet its needs.  If you’re not into the product or buy into the business model, how can we expect that you will put in the long hours.  Remember we want to hire you because we’re into you, and you should be just as into us, otherwise its going to be the case of unmet expectations on both ends.

I will conclude with the following: I realize its a recessionary year, and that people are scrambling to find jobs, and  I will admit to having looked for jobs during recessionary years myself.  The key to being a viable candidate is about understanding your strengths, selling yourself on those strengths, polishing up on your weak areas, and also communicating how you would make a unique impact on the product.

Teaching non-techies how to make trade-offs

The one mantra I left undergrad chanting was, “it depends.”  Translation: for any given problem the solution involves making trade-offs; space vs. time, time vs. money, quality vs. quick and dirty.  Most programmers think in terms of trade-offs, because they are constantly faced with limited resources whether its memory, disk space, or the scarcest resource of all: time.  The same cannot be said for the non-techies you work with.  This isn’t a character flaw, its just a manner of thinking, most non-techies think in terms of problem, solution, and the solution’s eta.  The discrepancy in the ways of thinking mostly manifests itself when it comes to scoping projects.  As a developer it is in your best interest to break down a problem and estimate how long it will take you to design, code, and unit test each portion.  Hence, it might not be feasible to implement the entire feature for the next release, and it may need to be built incrementally.  Non-techies don’t appreciate or understand incremental development, they want a fully functioning feature set with all the bells and requested in the spec.  For them delays translate to lesser revenue or an unhappy customer.  The burden-of-proof lies on you, as the developer responsible for coding the feature, you need to learn to speak their language: cost.  Not in terms of money, but employee time.  Its important to help non-techies understand that while it may only take you 2 days to one week to implement a feature, there are hidden costs such as designing the feature so that it is scalable, secure, and extensible, unit testing your implementation, and then of course throwing the feature over to the QA team to black box test it.  And if heaven forbid a bug is found, you need sometime to fix it.  Setting expectations and communicating the costs associated with implementing each feature also helps non-techies learn to make trade-offs, only in their lingo its called “priorities”.

At the end of the day everyone wants to deliver a quality product to their customers.  The challenge is to do so given limited resources, but it can be less arduous if developers understand the problems they are trying to solve, and set realistic expectations for the amount of time it will take to implement and test, and communicate the hidden costs of the development process to non-techies.

Hibernate Remote Lazy Loading to the Rescue

I’ve written a couple of posts recently on Lazy Loading, and some of the issues relating to how Hibernate creates and manages proxies.  While lazy loading itself is meant to improve performance, it can still lead to exceptions caused by objects being detached from their session.  As a web service becomes more distributed, and the number of requests increases the need for lazy loading remotely becomes more important, but implementing it without unintended consequences can be a little tricky.  Yesterday I was scanning through TheServerSide.COM and came across he following article on RemoteLazyLoadinginHibernate.  Its contains a good primer on lazy loading in Hibernate.  The more advanced concepts in the article deal with resolving exceptions caused by detached objects, helping to bridge the gap between performance and correctness.  This article has some good examples and methods of how to implement remote lazy loading, and Rajendran leaves us with the exercise of using it in conjunction with additional Hibernate features to improve site performance.

Class Cast Exception is a Proxy Problem – Revisited using the Visitor Pattern

In my previous post: ClassCastException is a Proxy Problem I talked about how Hibernate tries to optimize the loading of objects by lazily fetching the parent class object, and returning a proxy for the subclass instead of the actual subclass, thus causing a ClassCastException when the proxy is cast to the actual subclass.  The proxied object doesn’t contain member variables or a representation of the subclass’ methods, only the parent’s.

My proposed solution to the ClassCastException was to add an enum for each subclass that would be stored in the parent class, and used to figure out the subclass of the object and retrieve the actual instance from the database.  I created a method that returned a generic in either the parent class or DAO to keep the code clean.  However, after implementing this solution I discovered a bug that had been introduced a long time ago; the wrong enum value had been stored for the subclass.  The enum value was for SpanishCourse, so when I retrieved the object from the database, I cast it to SpanishCourse, when it was actually a MathCourse, causing a ClassCastException.   While I could just fix the data in the database I wasn’t satisfied with this pattern, because it broke the OO principle of encapsulation; the parent class had to have knowledge of its subclasses’ enum value.

I searched for awhile and found this article: Hibernate Proxies and Polymorphism.  I do think this is a good solution to the proxy problem, but, it pertains to lazily initializing the member variables of a subclass, and is a bit overkill for what I needed.  So then I went back to thinking about a solution for my specific problem.  How was I going to load the subclass instance without it being proxied?  

Here are a few things to note about Hibernate:

  1. Hibernate proxies an object inside a database transaction, the object is lazily loaded and it contains no data.  The data can be lazily fetched once a superclass method is called, as long as the database transaction is still open, otherwise you will get a LazyLoadingException.
  2. When calling a superclass’ abstract method, Hibernate will lookup the implementation of the method corresponding to the appropriate subclass.
  3. Hibernate cannot resolve subclass methods that are not part of the abstract parent class.

Here is my proposed solution:

public abstract class Course {

      public abstract class void load();

      ….

}

Each subclass’ implementation of the load method will handle lazily fetching the member variables of the class that are needed.  This avoids the need for a cast altogether.  If you need to return the object you can continue to use generics.  If you need the actual instance of the subclass then you will need to implement the visitor pattern described in the Hibernate articles.  Here is a simple example:

public interface CourseVisitor {

     public MathCourse getMathCourse();

     public SpanishCourse getSpanishCourse();

     …

}

public abstract class Course {

      public abstract void load(CourseVisitor visitor);

      ….

}

public class MathCourse {

     public void load(CourseVisitor visitor) {

         return visitor.setMathCourse(this);

     }

     …

}

public class CourseVisitorImpl implements CourseVisitor {

     private MathCourse mc;

     private SpanishCourse s;

     public MathCourse getMathCourse() { return mc; }

     public SpanishCourse getSpanishCourse(){ return s; }

     public void setMathCourse(MathCourse mc) { this.mc = mc; }

     public void setSpanishCourse(SpanishCourse s) { this.s = s; } 

     …

}

The Course object will be a proxy, and when the load method is called on it, passing in a new instance of CourseVisitor the subclass will be instantiated, and can be retrieved using the CourseVisitor’s getter method.  

This solution introduces more code, and requires that the CourseVisitor be updated with new subclasses of Course.  However, the visitor pattern is the correct solution to use, because it makes use of language concepts instead of relying on data such as an enum value, which can be error prone.

Her World – Installment 5

Jenna sat looking out of her bay window in her old brownstone.  As the sun’s rays beamed on her face she drifted deep into thought;  this was the place she had hoped to call home again.  She hadn’t had any expectations for her return.  She had always thought of this place as home, because of all the fond memories and experiences that took place here.  During her travels she would think about them, she would imagine herself laying in bed alone and gazing out at the street, or cooking in her kitchen assembling her mis-en-place, and then enjoying the fragrances and aromas of her creations.  She often wondered what it would be like to return, whether she could just pick up from where she had left.  But, now she was there, still sitting, with nothing left to imagine.  Things had changed, her friends had evolved, but so had she.  In the past five years she had gained new perspectives on the world and how she wanted to live.  But in a lot of ways she had stayed the same, and retained her old hopes and dreams.  The dream to come back to her brownstone, to buzz him up, to cook for him, and to lay in bed in his arms, and tell him about all her experiences.  But she knew none of this was possible anymore.  Her dreams would not come true.  She had to fight to get over it.  Her travels had made her stronger, but she still had not gotten over him.  The one love she had had in her life had been over for quite sometime.  

Over the years she stopped blaming herself, but she still felt an emptiness that she hadn’t felt when they were together.  While she tried hard to let others in, it wasn’t the same.  The memories of their life together always interfered with her new found life.  The only place she could connect with others was through art.  She could evoke an emotional response in others and feel a connection as she inspired the uninspired.  She helped design many Kouroi, and while the artists weren’t aware, to her, each one had an element of him in it.  His shoulders, his hands, or his strong legs.  When she was commissioned to help work on the sculpture of a head, she disappeared after designing the eyes and lips, because for the first time in five years she saw him again, and could no longer bare the thought of never seeing this stone sculpture, she wanted to see the live representation of it.  This is what had led her to ending the five years of wandering, and come back home.  But her love was betrothed to another, and she once again felt empty.  She wanted desperately to go to him, she wanted to tell him how she still felt.  But, she knew it would be unfair to him.  But, the night of the rehearsal dinner she she had felt a connection.  She saw how he looked at her.  ”No its only because he hasn’t seen me in so long.  It doesn’t mean anything,” she told herself.  

“Why is this so hard?  Why did Charlie have to leave?”  The only other man next to Aidan that she had come close to falling for had been Charlie, but he wasn’t ready for her.  And his only escape was to runaway.  Perhaps his actions had influenced her to do the same.  The thought of unrequited love was too much for her, and quickly after Charlie’s departure she too ran away.  

***

Drew walked up the staircase and rang the buzzer several times.  There was no answer.  He looked at his watch, he was an hour late, he should have called.  Still where could she be?  He peered into the glass.  It didn’t look like anyone was around.  Drew sat down on the steps and figured he would wait for her.  He wasn’t leaving until he got an explanation, she owed it to him, they were supposed to be best friends!

Then off in the distance a small cheery girl was walking up.  She stopped at the stairs, and looked up at him.  ”Are you Drew?” she asked.  He nodded back at her, “And who might you be?”  

“I’m Priscilla, I’m supposed to deliver this to you.”  She was holding a vanilla colored envelope.  ”My aunt Jenna said its very important!”

He took the envelope from her, and on the front in Jenna’s handwriting it said:  ”To my love, Aidan.”  ”Where did she go?” demanded Drew.  

“I don’t know.   I overheard my dad talk to mom, something about sailing.”  

Drew sighed, he had lost her again.  He would have to wait for her to show up again.

The following day, the wedding ceremonies started.  Drew was hesitant to deliver the envelope to Aidan, he wanted to open it, and find out what had happened, but he was a good friend and respected Jenna, so he kept it sealed.

Aidan was putting on his tux when Drew walked him.  ”Good luck today.” remarked Drew.  ”Thanks!  What have you got there?” asked Aidan noticing the envelope.  

“I’m not sure if this is good or bad, but its for you,” replied Drew handing over the envelope.  

“Oh its from Jenna.”  Aidan’s heart started to race.  He had thought about her constantly, since the night of the rehearsal dinner, and had told Sara that Jenna was in town, but nothing more on the subject, because he knew Sara would get nervous.  He had secretly hoped that she would be at the wedding with Josh, he missed having her around, but he also knew it would make things difficult for everyone, especially her.  He hadn’t anticipated how he would feel if she ever returned.  He had just hoped that she was happy wherever she was in the world.  But the night he saw her again, he knew what she wanted.  And while he loved her immensely and thought the world of her, he knew he couldn’t give her what she wanted, and so desperately needed.  As he started to read her letter, a tear ran down his cheek, he closed it, and thought to himself, “if only…”

Warrior Women

In one of my favorite TV shows of all time Firefly Wash is being intensely interrogated, and the interrogator asks Wash about his relationship with his wife Zoe, Wash responds rhetorically with a look of pride, “Have you ever been with a warrior woman?”   I personally have never been with a warrior woman, but this evening I attended the Anita Borg Awards in San Jose, and was in the presence of a warrior woman, Padmasree Warrior, the CTO of Cisco.  After her keynote speech I knew how Wash felt.  

Lately, I’ve been taking stock of women in engineering that have inspired and challenged me.  My favorite being my Professor at Duke Lisa Huettel.  But, I’ve felt a strange void.  I’ve been looking for someone who symbols almost exactly who I want to be in 10 or 20 years.  Some who is articulate, stylish, and graceful, in essence a femgineer.  And until now no one embodied these traits for me, until I listened and watched Padmasree deliver her keynote.

I’ve attended many keynotes by the likes of Madeleine Albright, Tom Wolfe, and read transcripts of keynotes of Steve Jobs and Carly Fiorina, but I must say this was hands down the best I’ve every experienced in my life!  I left feeling inspired but also light-hearted.   There were two points she made that really spoke to me.  First, Padmasree said that she never understood why people talk about balance as if work and life are constantly at odds with each other.  She insteads focuses on integrating work and life.  Second, she said you shape your opportunities.  I don’t think of myself as a naturally talented coder or having an astronomically high IQ, but I think I make up for those two areas with my drive and ambition, and use those as leverage to land opportunities.

So thank you Ms. Warrior for sharing your drive and courage with me tonight, and being a fabulous femgineer :)

Class Cast Exception is a Proxy Problem

I often face the following exception in Hibernate not on my local developer machine, but in production across several servers:

java.lang.ClassCastException: mint.hibernate.MathCourse$$EnhancerByCGLIB$$ed898f0d

This happens when I try to do something like this:

Set<Courses> courses = getCoursesDao().getCourses(userId);

for (Course c : courses) {
MathCourse mc = (MathCourse) course;
     // do something with mc
}

Assume MathCourse is a subclass of the abstract parent class Course. The gist of the problem is that Hibernate is trying to optimize and avoid going to the database by returning a proxy object. However, a proxy object cannot be downcast to the subclass object, the exception occurs because of downcasting. The solution to the exception is to return the real instance of the object.

One solution is to return the real instance of the object. To do this you could add a method to the DAO to return a generic. Create the function in the DAO class. Then during runtime the generic will be resolved to the appropriate subclass.

public class CourseDao {
public <T extends Course> getGenericCourse() {
     Session session = getCurrentSession();
     Course course = (Course) session.get(Course.class, courseId);
     if (course != null) {
         // type is an enum
        switch (course.type()) {
             case MATH:
                 course = (MathCourse) session.get(MathCourse.class, courseId);
                break;
             …
     }
     …
     return (T) course;
}

15 Ways to Speed Up Your Front-End

Last week I attend the Percona conference in Santa Clara.  The purpose of this conference was to talk about performance related to databases specifically mySQL.  Most of the talks went over my head.  However, there was one talk I attended “Website on Speed” by Philip Tellis from Yahoo! that I thought was outstanding.  In his 20 minute presentation he covered some key optimization techniques to speed up website and improve latency for users, that don’t require time-consuming back-end database restructuring.  Here are some of the ideas I found useful:

 

1. Reduce the number of domains your site has.  Having numerous domains requires a lot of DNS lookups, which makes the site seem slow to users.

2. Avoid redirects or point to a load balancer.  Redirects cause the site loading to slow down user experience.  Load balancers handle request processing by distributing them based on the current capacity of each server.

3. Combine CSS and JavaScript into a single file.  Having a file for each increases the time it takes to download the site content.

4. Combine decorative images into sprites.

5. Cache aggressively.  This of course depends on the content of your site, and how much data is being manipulated by users.  But I would recommend caching static data for as long as possible, which will speed up download time and improve the user’s experience.

6. gZip content over the wire.

7. Minify CSS and JavaScript using a YUI compressor.

8. Reduce cookie size.

9. Post-load components after on-load.

10. Put CSS on top so the browser will download it first, and page has rendered.  This improves user experience, because they can at least start to view the page, even if they can’t interact with it yet.

11. The corollary to #11 is to put JavaScript at the bottom so that it doesn’t block rendering.

12. Avoid using tables for layout in HTML, because you have to wait for the entire table to download before the page can be loaded.

13. Attach events on a container rather than on each element.

14. Use specific HTML elements e.g. unordered list (ul) vs. many divs, this reduces the number of elements that need to be loaded.

15. Profile your JavaScript using YUI profiler, there is also another new profiler called YSlow.