Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"Solve a problem, not a class of problems."

I, for one, think this is good advice for code in general. At least "at first, solve a problem, not a class of problems".

I have noticed that if I write my code too general at first, it ends up solving one class of problems kinda poorly, and ends up being re-written. If I write it for the specific problem I need to solve, and then generalize it to include another similar problem when I need to (and continue this process), I end up with very solid generalized code that solves a specific class of problems very (IMO) elegantly. It still gets re-written, but in a small-chunk iterative fashion.

This, of course, may be because of the way I think - or it may be due to me being relatively "young" as a developer. I am slowly generating more general purpose code that is getting reused for similar problems in different applications, however I write much more code for specific problems than I re-use.

Perhaps someone who's been doing serious coding work for more than a few years would like to weigh in on this?



I've always liked the rule of three; the first time, solve just your immediate the problem. The second time, notice that you solved the same problem twice. If the same situation occurs a third time, write a general solution.


I couldn't agree more. I call this ORYO: Only Repeat Yourself Once. Actually, I often put comments in my code marking places I've already repeated myself (saying 'ORYO' plus a reference, if needed).


This will only become more true as you gain experience.

Take a look at any piece of software you consider great, and you'll see that at version 1, it did very little, but did it well.

Conversely, take a look at something like Lotus notes, and you'll see that the opposite is true.

Consider yourself lucky to have discovered this idiom so early in your career!


This is often referred to as YAGNI (http://c2.com/cgi/wiki?YouArentGonnaNeedIt).


Joel calls this "Architecture Astronomy." http://www.joelonsoftware.com/articles/fog0000000018.html




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: