5 ms·
Ask HN: Have you ever written (extensive) code that works the first time?
As I continue down a little project of mine, I realized that I've never written an app that works completely the first time I run it.<p>I wondered if it was my incompetence/lack of experience/ignorance/etc., or if it was a common phenomenon.
- JCThoughtscream 17y agoI suspect the problem is much like with literary writing: The first draft is NEVER perfect.
- jmonegro 17y agoWell said.
- pg 17y agoI think the longest thing I've written that worked the first time was a Pascal program about a page or two long, in college. I'm never likely to surpass that record, because I'd never write so much code now before testing it.
- statictype 17y agoI always wondered, what does it mean for a program to be a page long? I guess you're referring to a printout of the code on A4 size paper in some fixed 10-point font?
- vena 17y ago25 lines of 80 characters, i'd say.
- thwarted 17y agoWhen I absolutely had to print out code, 17+ years ago, I remember it being 66 lines on a US letter sized sheet (don't care to calculate what pitch that would be, or the font size -- whatever HP LaserJets would print by default if you sent plain text ASCII data to port 9100 directly. My university also had those terrible green banded fan-fold paper line-printers that was like 200 columns wide and maybe 80-100 lines. We referred to both of these as "pages". Now, I don't know anyone who measures code in "pages". This isn't a good metric when most projects are made up of multiple files. It's as good as measuring productivity in LOC.
- pg 17y agoYes, I was thinking of 66 lines.
- soundsop 17y agoThis is how to do it, apparently: http://www.multicians.org/andre.html http://www.multicians.org/andre.html
- cperciva 17y agoI've written modules of 500-1000 lines which worked perfectly the first time I successfully compiled it. In any large block of code, I'm prone to make occasional typos (usually missing semicolons, unmatched parentheses, not declaring a temporary variable, not #including a required header, etc.) but the compiler always finds those for me, so it's not really a problem. I've also written code which didn't work at all, and then spent days debugging it. But I've learned that I'm really bad at debugging code, so instead I take the time to plan out what my code is doing so that I can get it right the first time.
- jrp 17y agoNever the first time I think about a problem. But sometimes when doing a from-scratch rewrite of a medium-size program, I will understand how everything should be, and it works the first time.
- jerome_etienne 17y agono, simply because writting extensive code without running it is silly from a developement time point of view. It would uselessly increase the distance between writing the bug and finding it.
- ratsbane 17y agoI have done that. Very rarely, but when it happens it's like the rain stops, the clouds part and the sun illuminates the countryside with a fresh spring warmth. And then there are days I've hacked through some muddy recursive reference problem in a few lines of code, just knowing the solution should be obvious but not seeing it. The good moments make me happy to program; the bad ones make me think about becoming a lumberjack instead.
- deleted 17y ago[deleted]