Live data from Hacker News

Ask HN: I think My code isn't Good enough

news.ycombinator.com

71–80 of 97 posts

Re: Ask HN: I think My code isn't Good enough

#71

Reusable code/efficient code is usually more complex and less readable. I find this is usually not a big issue, as I can always refactor change to the design I need later. Just in time, not just in case.

I agree that efficient code is usually more complex and for some god forsaken reason it tends to be the least commented.

If you think to yourself, "wow! I'm really proud of that, very clever" please for the love of God leave a comment.

I find myself writing chicken scratch on a piece of paper or in a scrap file when writing a function, many of those chicken scratch comments are exactly the sort of things future developers would love to see in comments.

So...big takeaway from me (15+ years developing) is learning when to comment your code!

Re: Ask HN: I think My code isn't Good enough

#72
post #21

If you're using it for a start-up - it's much more important to deliver usable software than quality code - you can always go back and clean up the code - but if you don't get traction it's all over. Also - consider buying code reviews from developers you respect - even a couple of hours a week can make significant difference to your quality.

+1 on the mentorship note. _Incredibly_ useful. Not only for yourself but can also be a great exercise for the teacher.

http://pith.org/notes/2011/08/29/programmers-feeling-uninspi...

Re: Ask HN: I think My code isn't Good enough

#73
post #22

I know my code isn't good enough, and I've been programming for about 30 years! Not only that, my code isn't good enough, but I'm a great programmer. I might be making some wrong assumptions, but I think the people whose code is really bad are the ones who think their code is good enough, or the ones who just code quickly without thinking. (I tend to think quite a bit and then code. In fact for the particular project…

"The unskilled therefore suffer from illusory superiority, rating their ability as above average, much higher than it actually is, while the highly skilled underrate their own abilities, suffering from illusory inferiority." Dunning-Kruger effect, and it is the same in most professions where 'performance' can be a subjective judgement. Teaching, definitely! http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect

[deleted]

Re: Ask HN: I think My code isn't Good enough

#75

First and foremost, write your code so that it can be understood easily by someone that knows nothing about it. As you get older, you'll realize that this person is you! Anything written over 2 weeks ago is often like looking at new code, so make sure you have good comments and non-obscure variable names so that you can understand it easily. This also makes it easier on your coworkers. Second, write for readability a…

Sorry, but actually it sounds like quoted from a (programming) fantasy novel. Look at the other comments, who argue that the nice and clean code is not always the best, not always the goal and sometimes not even a goal that can be achieved. This(!) is what you learn from experience.

Re: Ask HN: I think My code isn't Good enough

#76
Is a good programmer one who creates good code or one who is always looking to improve his code, experiment and get his programs to work?

Look with pride at the mistakes of your past and be ready to do more mistakes to improve in every line you write. That's my philosophy for now.

Re: Ask HN: I think My code isn't Good enough

#78
post #22

I know my code isn't good enough, and I've been programming for about 30 years! Not only that, my code isn't good enough, but I'm a great programmer. I might be making some wrong assumptions, but I think the people whose code is really bad are the ones who think their code is good enough, or the ones who just code quickly without thinking. (I tend to think quite a bit and then code. In fact for the particular project…

> When I go back and look at code I did in the past, without having looked at it awhile, I see that it is really quite brilliant.

We have the opposite experience. Whenever I see code I wrote in a past life, I see ugly code. I certainly would have written it differently if my future self wrote it. I see it as a reflection of how much I've learned since writing that old code.

I tell a lot of people: Code I wrote yesterday is great; code I wrote a year ago sucks.

Unless, of course, I do as the OP does and look at other people's code. Then even the code I'm writing now would not be good enough.

Re: Ask HN: I think My code isn't Good enough

#79
> good code written by some one else

Exactly -- someone else. I don't have a formal Computer Science education. I'm juggling reading the K+R C book, Knuth's Literate Programming, Odersky's Programming Scala and the Ruby "pickaxe" book. All of them have been great. But their impact on my code and career all pale in comparison to the strides I've made by paying attention to the social side of programming.

You should now:

* Talk to other programmers. I found a couple groups on Meetup.com that I like attending. Sometimes they're not specifically about programming (like my UX meetup). That's good. I am cross-training. I have asked some programmers whose work I admire for beer/coffee, on me, and I've had some great experiences. You will hear new ideas, and will have to defend your opinions.

* Find an open source project you like on Github.com and start contributing. Start with easy #bugs in "Issues". If you don't know which ones are easy, ask. You will get invaluable peer review, sometimes from the best minds in our field. You will read great code, and you will modify it, and so you will understand it deeply. You will have the satisfaction of knowing your code is used by hundreds or thousands of people.

* Find beauty in other things.

Re: Ask HN: I think My code isn't Good enough

#80
I am passionate about writing good code, and I'll try to offer some practical advice. As others said, the first step is understanding the importance of writing clean code and taking pride in your craft. By doing this, you are already ahead of most other programmers who don't really care. Now, how do you improve?

1) Read books.

With 4-5 years of experience, you already have a good intuition for "good" and "bad" code. Still, it doesn't hurt to learn more about it. There are a lot of good books on this subject.

The first is "Clean Code", by Robert C. Martin. It's the first book I read on this subject, and I learned a lot. Note that the book uses Java in the examples, but I think the ideas would apply to most other languages.

Its author, Uncle Bob ( http://en.wikipedia.org/wiki/Robert_Cecil_Martin ) has long been a proponent of writing clean, beautiful code. He recently did an interview for Xebia: http://blog.xebia.fr/2011/05/25/interview-avec-robert-martin... (French blog, but the interview is in English). In it, he advises:

"Well there are a number of books that talk about writing code well. Kent Beck wrote a book called “Implementation Patterns” very recently. It’s an excellent book all about software craftsmanship. The pragmatic programmers wrote a wonderful book in 2000 called “The pragmatic programmer”, again a wonderful book. Chad Fowler wrote a book call the “Passionate Programmer”. Again the book is about doing everything well. I wrote a book recently called “Clean Code” which is very specific about particular things you can do with your code to do it well. So there is a tremendous number of resources that are available for people who are interested in doing software craftsmanship well."

Out of those, disregard "The passionate Programmer". It's an okay book, but its focus is on building a good programmer career, not on code.

"Implementation Patterns" by Kent Beck is a great book with a lot of best practices when writing * Java * code. Less useful if you use another language.

"The pragmatic programmer" is a good book on software craftsmanship. I'm personally half-way through. There is a lot of good advice in it, but I often find myself thinking it's "common-sense". Maybe because I've already been exposed to most of the ideas by reading blogs? Still, it's a great book, with a lot of best practices. It's main focus is not code, though, so you might want to start with other books if your focus is on writing good code.

To these books, I'd add "Code Complete (2nd Edition)" (language-agnostic) and "Effective Java 2nd Edition" if you use Java.

Summary:

If you use Java, read:

  - Clean Code - http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882
  - Effective Java 2nd Edition - http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683
  - Implementation Patterns - http://www.amazon.com/Implementation-Patterns-Kent-Beck/dp/0321413091
  - Code Complete / Pragmatic Programmer
If you use another language, read:

  - Clean Code - http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882
  - Code Complete - http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670
  - Pragmatic Programmer - http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X
Other people might chime in with suggestions for other languages?

2) Practice.

Implement what you learned in the books. Keep improving.

3) Read other people's code.

Read good open source code. Not all code is good code. Ask around for OSS projects with good code in your language.

If you use Java, start with:

  - Google Guava - http://code.google.com/p/guava-libraries/
  - Google Guice - http://code.google.com/p/google-guice/
  - Spring Framework - http://www.springsource.org/
4) Practice.

5) Practice.

Post reply on HN