Live data from Hacker News

Portrait of a Noob

steve-yegge.blogspot.com

21–30 of 43 posts

Re: Portrait of a Noob

#21
I'm suprised no one mentions this, good code does not need comments, because it clearly speaks with variable names and function names.

The Lisp function Yegge gives, is horrible in that aspect. for example this piece of code:

  (if (or (= tt js2-LB) (= tt js2-LC))
should really be more like

  (if (matches-js2-line-ending current_token))
No matter "how good you are" code reading is faster if what you read matches with what you're doing in English.

Re: Portrait of a Noob

#22
post #2

I read this a while back and i still remember the takeaway point from it : "It's denser: there's less whitespace and far less commenting. Most of the commenting is in the form of doc-comments for automated API-doc extraction" This is right on the button. I prefer writing/reading an overall README.txt which says concisely what that module/package etc. is supposed to do and doc-comments where appropriate when something…

I've reduced the amount of whitespace I use as I've learned to read dense code more patiently. You have to read at the right speed and not let your eyes fly down the screen, leaving comprehension behind. Strangely enough, I majored in math, so I've always had this skill, but it's hard for me to apply it to code for some reason.

Re: Portrait of a Noob

#23
post #21

I'm suprised no one mentions this, good code does not need comments, because it clearly speaks with variable names and function names. The Lisp function Yegge gives, is horrible in that aspect. for example this piece of code: (if (or (= tt js2-LB) (= tt js2-LC)) should really be more like (if (matches-js2-line-ending current_token)) No matter "how good you are" code reading is faster if what you read matches with wha…

A nice reminder that skill and raw brainpower are two different things, and the latter can retard development of the former. I worked with many pieces of code written by one particular coworker of mine who was way too smart for his own good. His code was littered with little formulae like that, repeated again and again throughout a file, and to him it was obvious at a glance what they meant. It was also easy for him to scan through his code and find errors in these expressions, as easy as it is for you or me to see that "(matthes-js2-line-ending ..." contains a typo. I have no idea how he coped with finding and changing every instance of a formula that needed to be changed. For me it was a slog every time I had to read, change, or debug his code.

P.S. The most frequent and flagrant was calculating array indices into multi-dimensional arrays in C++. It's so easy to write a simple class that lets you do this:

  arr(n1 + i, n2 + j, n3 + k) = calc_foo(i, j, k);
instead of this:

  arr[n3 + k + (n2 + j) * (nz + (n1 + i) * ny)] = calc_foo(i, j, k);

Re: Portrait of a Noob

#24

From the article: If you're a n00b, you'll look at experienced code and say it's impenetrable, undisciplined crap written by someone who never learned the essentials of modern software engineering. If you're a veteran, you'll look at n00b code and say it's over-commented, ornamental fluff that an intern could have written in a single night of heavy drinking. I have never seen this so succinctly expressed before.

A guy who works for us just read that and laughed and said:

"To be honest I'd sit there and say both were equally shoddy and unlearned in their own way. There is a sweet spot middle ground that the really really good programmers learn"

I suspect he is right.

Re: Portrait of a Noob

#25
He's spot-on about Java being a safe-haven for "data modeling" geeks who are afraid of doing real work. Writing a whole bunch of getters and setters in a freshly minted Java class certainly feels like work. However, I think he gets it wrong when he puts OCaml on the extreme "for you to model everything" end of the spectrum:

And Haskell, OCaml and their ilk are part of a 45-year-old static-typing movement within academia to try to force people to model everything. Programmers hate that. These languages will never, ever enjoy any substantial commercial success

Hold on a minute...last time I checked OCaml was a dialect of ML. ML does not ask you to "statically" type everything, in fact it does the opposite. It infers all the types. Sure, it allows you to hint types to the compiler, but this is not necessary. You get all the benefits of "static" type checking through ML's concept of type inference. It's designed specifically to make it less work for the programmer to enjoy the benefits of a sound, correct type system.

If you want to learn more about type inference in ML, check out this short introduction: http://bit.ly/8WEhD8

Re: Portrait of a Noob

#26
post #21

I'm suprised no one mentions this, good code does not need comments, because it clearly speaks with variable names and function names. The Lisp function Yegge gives, is horrible in that aspect. for example this piece of code: (if (or (= tt js2-LB) (= tt js2-LC)) should really be more like (if (matches-js2-line-ending current_token)) No matter "how good you are" code reading is faster if what you read matches with wha…

By leaving out the definition of that long function name you mask the increased cognitive load of your change. If you include the definition of your new function it doesn't look like an improvement anymore.

Re: Portrait of a Noob

#27

I refute Yegge thusly: Which code would you rather maintain?

Surely Yegge would tell you that he would rather maintain the concise code with sparse comments. That's the whole point of the post.

But he would be lying. Yegge would rather maintain the concise code with sparse comments if and only if it were Yegge's concise code with sparse comments. If it were someone else's, he'd rather it were in fact rather heavily commented.

Re: Portrait of a Noob

#28
This is one of the most inspired pieces of writing on programming I've read in quite some time. Acknowledging the difference in preference for code density among noobs vs. seasoned programmers will be really useful during any annoying meetings on programming style I have to attend in the future.

Edit: It got less inspired as I continued to read but the initial idea was good.

Re: Portrait of a Noob

#29
I've shared Yegge's disdain for static typing for quite some time. One of the best examples of how awful it can be is type hinting (optional type constraints on parameters) in PHP. Many times I've explained to people why type hints are awful thing deserving banishment to hell — along with Facebook suggestions and Microsoft product recommendations — but so many PHP programmers seem to love them! Now that I read this I can see why that sort of thinking is bound to exist for a language like PHP (read: noobs).

Recently, however, I've been getting into Haskell and in doing so I found my opinion on static typing left a little beaten in the legs and suffering some obvious facial wounds. Static typing works in Haskell, I'm pretty sure of that. The question I'm left with is, why?

I think it might have something to do with the fact that type checks in class-based OO languages don't even begin to insure the program correctness that novices are often foolish enough to think they do. Everyone else recognizes the need for all manner of testing, and that's how correctness is proved (albeit, approximately) in imperative languages. In Haskell, I've found that type checks go quite some way to proving correctness, no really! (They don't actually prove correctness but proofs of correctness would be impossible without them). Without even bothering to do any proofs or testing you get a much more rigorous check for correctness in Haskell than you do when a Java program successfully compiles.

I can't emphasize this difference enough. To me static typing in Java is an annoyance and a lie. And so when I program in a language that teeters between static and dynamic typing, such as PHP, I go out of my way to write libraries that make things more dynamic (I've got one GitHub) and I call men who advocate aforementioned type hinting, girls names. In Haskell, it's totally different; it actually works; it's actually useful. Not to mention the clever stuff that you can do with types which I couldn't begin to do justice here given my inexperience.

Re: Portrait of a Noob

#30
The first part seems to be motivating something like a macro system for comments. What if one abbreviated compound situations using a single word or a phrase along with a separate file with expansions of the abbreviations into more detail. So, one can comment at a more abstract level and still be understandable (using say, a tool which displays the expansion when hovering over the abbreviation, or a separate window with expansions of all the abbrevs used nearby). Ideally, of course, the abstraction would be captured in the code itself, and the expansion would be the comment before the function or the macro defining the abstraction. So this system will be useful only when there are abstractions in comments which are not reflected in the code.
Post reply on HN