Live data from Hacker News

Do you worry about the quality of code?

news.ycombinator.com

1–10 of 18 posts

Do you worry about the quality of code?

#1
I have recently submitted our app to the app store after weeks of coding and hacking things to work. At this point I have realized that the quality of code has deteriorated considerably even though it works. The structure of the code is not lost, but in order to make it work, I have put a lot of hacks.

When I look back at the code, I can't believe I have written it and there are 1000 other ways to write it better. But I am hard pressed for time since my team has to ship it fast and validate a few points for our next round.

So I wanted to find out from HN members, how do you keep track of the quality of the code? Do you try to keep it well structured and re-factor your code often? What steps do you take to maintain the quality of the code. I mean, not just writing 'good' code, but what do you do to ensure that it is easily re-factorable?

Re: Do you worry about the quality of code?

#2
For me, this is something that has just gotten better with experience and practice.

Of course, we all start out with a clear and rigid vision about how the code should be - you use good design patterns, you let your data dictate the flow of your code and inevitably, some scenario comes up that doesn't play into your structure well and you concede a hack. Then a couple more. But with experience comes being able to identify areas that are more likely to attract smelly code and thus you are able to prepare in advance.

One of the paradigms that I am always reiterating to my team is that their code only needs to be 'good enough' and of course, this is relating to productivity. It doesn't need to be the shiniest example of a memento implementation I ever saw - first and foremost, it needs to work. And it needs to work when I need it to work, not 2 weeks after because you just had to refactor it just one more time. This is the reality of being a professional developer, working with customers.

Re: Do you worry about the quality of code?

#3
I am currently a graduate student and I can say that I, without a doubt, worry about the quality of my code. I worry about this because I have to rely on other student-written code that often does not perform as advertised. I refactor both my code, and code written by other students very frequently even though the code is really only "proof of concept" because I need to refactor other people's code to get mine to work. I cannot stress enough how important it is to refactor (and document) code.

Re: Do you worry about the quality of code?

#4
post #3

I am currently a graduate student and I can say that I, without a doubt, worry about the quality of my code. I worry about this because I have to rely on other student-written code that often does not perform as advertised. I refactor both my code, and code written by other students very frequently even though the code is really only "proof of concept" because I need to refactor other people's code to get mine to wor…

Working across teams and developers is one more reason to worry about the quality of the code. Sometimes the code written in not as per our vision and we end up refactoring it. But again, all these things are possible if there is some time at hand. For startup like ours, we are continually iterating and adding code proof points. This makes it difficult to maintain the quality of the code how much ever we want to. I like your idea of documenting, though again, it's time consuming. We do it with helpful comments, but I think it is not enough.

Re: Do you worry about the quality of code?

#5
The main thing I do is try to implement very thorough unit tests. I find that the act of writing the tests helps me think through the interface to the code, which in turn helps me isolate the caller from implementation details. It also helps make sure an individual module doesn't try to do too much or too little-- the unit test will start to feel "baggy" in the first case, and will look pretty thin in the other.

If you haven't read "Working Effectively with Legacy Code" by Michael Feathers, I would strongly recommend it. The book officially is about how you get existing code under test, but its techniques orient around moving the code to a better organization.

The book "Large Scale C++ Software Design" by Lakos lists some actual, computable, metrics for assessing how interconnected your code is (and hence how hard to change). Never having used those metrics, I can't recommend them one way or the other; I just know they exist.

Re: Do you worry about the quality of code?

#6

The main thing I do is try to implement very thorough unit tests. I find that the act of writing the tests helps me think through the interface to the code, which in turn helps me isolate the caller from implementation details. It also helps make sure an individual module doesn't try to do too much or too little-- the unit test will start to feel "baggy" in the first case, and will look pretty thin in the other. If y…

Thanks for the suggestions. I checked out the book by Michael Feathers and it definitely looks helpful. I have embarrassingly low number of unit tests which I need to take care of and introduce more rigorous testing into our code.

Re: Do you worry about the quality of code?

#7
I absolutely think about clean and quality code. The easiest way to do it, in my opinion, is to write the most customizable and modular code from the beginning. Because, inevitably, mid-project you'll want to use something you've already written with a slight twist or use a class somewhere else where you didn't know you'd need it - but now you can just drop that sucker in and spend no time making a totally new class for something so it doesn't break something you've made earlier. It really doesn't take too much extra time to do this either, especially if you're constantly thinking like that - future proofing your code for the unknowable and very changeable design requirements. Loosely sticking to MVC has greatly improved my app coding. Here's how I set it up:

* Controllers

* Data Objects

* Utility UI functions (making shadows, or anything that can happen anywhere)

* Data Managers (sometimes Singletons)

* Web Services

If I start with this model in my head, the code is self organizing because I'm not writing data parsing in a controller because I KNOW with 99% certainty that I'm going to parse something later in another controller or something even higher is going to handle that data at some point in the future.

This kind of abstraction is how I do it currently, and I've only gotten here through experience, and I'm sure that I'll find even better ways as I continue to code into the future (I'm already thinking of base iOS project templates that contain that structure already).

Re: Do you worry about the quality of code?

#10
post #2

For me, this is something that has just gotten better with experience and practice. Of course, we all start out with a clear and rigid vision about how the code should be - you use good design patterns, you let your data dictate the flow of your code and inevitably, some scenario comes up that doesn't play into your structure well and you concede a hack. Then a couple more. But with experience comes being able to ide…

Fair enough. I agree that the code has to be working but sometimes, even after laying down the guidelines on how to write code a better way to structure out, things go out of hands with multiple contributors. In my opinion, the solution to this problem is to refactor the code as soon as the code is checked in. Not necessarily refactoring the whole code, but to make it conform to the existing design and structure.
Post reply on HN