Live data from Hacker News

A Million Lines of Bad Code

varianceexplained.org

51–60 of 123 posts

Re: A Million Lines of Bad Code

#51
post #20

1000000 lines of bad code is a bit of an exaggeration. Many (most?) programmers never write that much code in their entire careers. I've heard 10000 LOC as a milestone for REALLY learning a language (once you're familiar with programming in general), I'd say it's on that order of magnitude for writing non-terrible code in general.

The problem is that a lot depends on what kind of problem your solving, and whether it varies a lot. I've written ~10k lines of python (single small project). But, I'm still at the point where it seems every other line requires me to google something, and i'm sure normal python people would snicker at the result. OTOH, I've probably written close to 750 (maybe a million, aren't small companies cool!) lines of C/C++ over the last 20 years and that is probably not enough either. Although I rarely even have to think about the code, rather i'm totally working at the algorithm/interaction level and the text pops out of my fingers.

I would say 10k is enough that you can put it on your resume... But, even that is probably way less than the average comp-sci graduate writes. So, I would still consider it a starting point. Especially, since reading other peoples code is just as important a skill, and that isn't something generally picked up in school, or on little weekend projects using a new language.

But again, it depends on the breadth of the problems being solved. We hired a web developer a couple years ago, who in the space of about a year wrote ~150k lines of PHP and javascript, and got a _LOT_ better at it, but he solved most of the problems the same way and there was a metric ton of duplicate code, and imprecise problem solving (AKA problems solved in the most roundabout way). Over the last 2 years I've probably only written about 50k lines of PHP/Javascript but I've added about 20x the functionality he added. So, I would say that i'm better now than he was when he left, but i'm still not really that good.

Re: A Million Lines of Bad Code

#52
post #6

I recently read the book "How to Win Friends & Influence People", bad title great book. My main take away from this is I've been talking to people really badly for the last 27 years. I wish I had read this book in middle school. But this blog reminded me of some of the concepts from the book, its far more productive to give positive encouragement than to give negative feedback, and just adding a complement isn't enou…

I like teaching. I don't think I'm amazing at it, but I like sharing knowledge and experience with my friends and co-workers and see them improve, or just sometimes for the abstract sense of helping. Of course, sometimes I fall flat and come across as arrogant or condescending, but I hope that's rare. I read "How to make friends" a long time ago, and I apply those rules diligently to my interactions with people. Rece…

> Anyhow, this is just my two cents relating an experience to show how a seemingly normal and friendly human being can revert to angry "RTFM"s.

Sure. We're all human, and I know I've been there many times. Just also remember how the seemingly normal and ready to learn human will react to a lesson put that way.

Re: A Million Lines of Bad Code

#53

Earlier quoted context omitted.

"Hey pretty cool program! Its a great start. I bet we can make it run faster if we changed the way files are imported to something like this... nice work" I usually hear this referred to as a "criticism sandwich": Criticism surrounded on either side with compliments.

We Brits are the masters of allusive and indirect speech, and I would automatically automatically strip of both pieces of bread translate that to "you're reading in files wrong".

Not everyone auto-parses. Unless you really know who you're talking to, it makes sense to add the "bread/condiments" to the sandwich.

Re: A Million Lines of Bad Code

#54

Earlier quoted context omitted.

"Hey pretty cool program! Its a great start. I bet we can make it run faster if we changed the way files are imported to something like this... nice work" I usually hear this referred to as a "criticism sandwich": Criticism surrounded on either side with compliments.

We Brits are the masters of allusive and indirect speech, and I would automatically automatically strip of both pieces of bread translate that to "you're reading in files wrong".

I think you have to take each individual differently. Most folks react well to the criticism sandwich. Someone like you might prefer a more direct approach, as long as it is not phrased in a mean way.

At some point in my career, I stopped taking criticism personally. I just realized I was wrong so often that upholding the pretense that I knew it all was too hard. For that reason, I prefer direct suggestions.

If I was teaching a child or a new beginner, I would start with a lot of praise that they're even trying. I want to get them some early wins to help boost their confidence.

Re: A Million Lines of Bad Code

#55
post #6

I recently read the book "How to Win Friends & Influence People", bad title great book. My main take away from this is I've been talking to people really badly for the last 27 years. I wish I had read this book in middle school. But this blog reminded me of some of the concepts from the book, its far more productive to give positive encouragement than to give negative feedback, and just adding a complement isn't enou…

Don't you feel patronized when people do that though? Be as rude as you want to me, as long as you're correct. As for myself, I tend to not call out the positive parts of something, because that's sort of implicit. I would not bother to point out that the file reading code is wrong if the whole thing was broken. I admit I'm probably incorrect here, but I notice people try this "say something positive" and it really c…

I think it just comes down to different personalities. I'm just like you. I tend to get agitated when people try to sandwich their criticisms or compliment me for irrelevant things when I just want them to get to the point. I'd very much prefer someone just telling me "your code is shitty and here is how you'd fix it and why." Unfortunately, people that take criticisms like us seem to be in the minority.

Re: A Million Lines of Bad Code

#56
post #48

Earlier quoted context omitted.

Factually incorrect. Creating new strings by concatenation requires reallocation because Strings are immutable in java. Using a Builder is over 700x faster: Concat code: http://pastebin.com/CcezmJbf Builder code: http://pastebin.com/Dd6kzcKa Results, using JRE 7: > time java concat data.blk Finished. java foo data.blk 170.08s user 1.52s system 102% cpu 2:48.12 total > time java builder data.blk Finished. java builder…

What about the time to write the program?

About the same.

Re: A Million Lines of Bad Code

#57

> Building a string with a series of concatenations like this is extremely inefficient No. Not in Java since 1999 or so.

Factually incorrect. Creating new strings by concatenation requires reallocation because Strings are immutable in java. Using a Builder is over 700x faster: Concat code: http://pastebin.com/CcezmJbf Builder code: http://pastebin.com/Dd6kzcKa Results, using JRE 7: > time java concat data.blk Finished. java foo data.blk 170.08s user 1.52s system 102% cpu 2:48.12 total > time java builder data.blk Finished. java builder…

This is true, javac only replaces individual concatentations with use of a StringBuilder, so foo + bar + baz + "!" is fast, but performing a concatenation in a loop does multiple copies for each iteration. It (or the JIT) could conceivably do escape analysis to optimize simple cases like this, but it doesn't.

builder: http://hastebin.com/qadusoriqa.cs

concat: http://hastebin.com/nasukuxemi.cs

Re: A Million Lines of Bad Code

#58

> Building a string with a series of concatenations like this is extremely inefficient No. Not in Java since 1999 or so.

In special cases multiple string concatenations can be optimized into using a StringBuilder calls. Not in the general case.

Re: A Million Lines of Bad Code

#59
I'm not a real fan of assigning a context-independent global value label like "good" or "bad" to code. While there probably are examples of truly "bad in all respects, in any context" code, the vast majority of code that I've seen tends to fit more into " of the code could/should probably be improved when using it in ".

I find that viewing (and discussing) code this way has a lot of benefits:

    * It is really hard for a single global negative value judgement made about code to not be taken personally by the person who wrote it (e.g., "your code sucks" == "you suck").  This is much easier to avoid when talking about attributes of a thing, since (a) it comes across as more objective than subjective, (b) gives plenty of opportunities for acknowledging aspects of the code that _don't_ suck, and (c) lends itself to much more of a "give and take" discussion.

    * It gives you the opportunity to talk about "figures of merit" and trade-offs that are the reality of engineering, but rarely taught in schools (e.g., readability/development cost/flexibility vs.  performance, etc.)

    * It gives you a framework for explaining why things like idiomatic style, "principle of least astonishment", and general elegance actually contribute to code quality (and aren't just excuses for subjective attacks).

Re: A Million Lines of Bad Code

#60

Earlier quoted context omitted.

I like teaching. I don't think I'm amazing at it, but I like sharing knowledge and experience with my friends and co-workers and see them improve, or just sometimes for the abstract sense of helping. Of course, sometimes I fall flat and come across as arrogant or condescending, but I hope that's rare. I read "How to make friends" a long time ago, and I apply those rules diligently to my interactions with people. Rece…

> Anyhow, this is just my two cents relating an experience to show how a seemingly normal and friendly human being can revert to angry "RTFM"s. Sure. We're all human, and I know I've been there many times. Just also remember how the seemingly normal and ready to learn human will react to a lesson put that way.

I know, and that's the part I feel worse about.
Post reply on HN