News for hackers. Stuff that matters.
Re:How I Became a Better Programmer by BurningFrog on Tuesday March 21, 2017 @01:17AM (#13920035)
The time to clean up the code is when it already does what it should.

That is: Make it pretty and readable and DRY once the code works. Until then my code can have several ugly and improvised things I've left for later.

Re:How I Became a Better Programmer by fauigerzigerk on Tuesday March 21, 2017 @06:27AM (#13920990)
>The time to clean up the code is when it already does what it should.

I'm a bit skeptical of that as a general principle.

I want code to be a consistent representation of my mental model of the solution at all times. I use code to help me think, remind me of my thinking and communicate with others. It's not just a series of commands that make a machine do something.

As long as any ugliness is not in conflict with this purpose it's fine. I can totally live with functions that are a bit messy and probably need cleaning up later.

Re:How I Became a Better Programmer by tshannon on Tuesday March 21, 2017 @09:34AM (#13922008)
Yep, I agree. I see it more as a list of priorities, not necessarily sequential steps.

1) Make it work 2) Make it maintainable 3) Make it fast

All three should be on your mind when developing something, but if you have to choose between 2 and 1, go with 1.

Re:How I Became a Better Programmer by AstralStorm on Tuesday March 21, 2017 @10:52AM (#13922673)
And you end up with the 60+ year old TODO this way. Or lack proper reason comments (the why) and end up in a gaggle of legacy code.

My rule is simpler: never write instant legacy code. If it feels like something you won't understand a month later, it likely is legacy code.

If it reads badly (and I'm not talking about this or that brace or whitespace choice), then it also provably is in that category.

Re:How I Became a Better Programmer by ant6n on Tuesday March 21, 2017 @01:43PM (#13924449)
If there is actually a trade-off like tshannon notes, then by not making it work first, you may end up with un-finished projects.
Re:How I Became a Better Programmer by AstralStorm on Tuesday March 21, 2017 @04:02PM (#13925675)
The solution to making it work first is to make a prototype with the correct design. You do not have to implement it at once.

(On C2 wiki, a proper SpikeSolution)

If you hit a case your design cannot cleanly handle, it is time for redesign, but often a tiny amount of design constrained by use cases will expose a good design quickly.

Re:How I Became a Better Programmer by mythrwy on Tuesday March 21, 2017 @04:14PM (#13925793)
They never give me the time for items #2 and #3. As soon as it works most clients and bosses figure "done".
Re:How I Became a Better Programmer by BurningFrog on Tuesday March 21, 2017 @07:15PM (#13927145)
How does that work exactly?

Why can't you just keep working until you consider your task done?

Re:How I Became a Better Programmer by kwhitefoot on Wednesday March 22, 2017 @03:17AM (#13929023)
Are you working as a developer? If so, how do I join your team? In my life as a developer I have deadlines that are set by customers and no amount of explanation that I need another week to make the code bomb-proof will shift them.
Re:How I Became a Better Programmer by BurningFrog on Wednesday March 22, 2017 @12:51PM (#13932530)
I've heard about jobs like that, but I would never take one. There are far less insane developer jobs out there, and you could try to find one!

Development time is inherently very hard to predict, so strict deadlines - even if set by people who understand the technical issues don't make a lot of sense. There many books on this, and I won't try to summarize them here.

Still, if you have a deadline, you can use your time however you want before the deadline, right? So if it's better/faster to clean up the code after you made it work than to try to type everything perfectly the first time, what's stopping you?

Or is it that the deadlines are so tight that you only have time to write terrible code?

Re:How I Became a Better Programmer by smp_ on Tuesday March 21, 2017 @03:31AM (#13920433)
That's ok assuming that time ever comes; pressure to deliver new features or just the possibility that you move on and it stops being your code and becomes someone elses means you may never get a chance to look at those ugly things. I think there's a middle ground that takes that kind of uncertainty into account and is pragmatically wary of 'ugly' and 'improvised'
Re:How I Became a Better Programmer by cname on Tuesday March 21, 2017 @10:55AM (#13922697)
I think a good metric for "advanced/senior programmer" is "writes reasonably clean code from the start". Not perfectly clean, but reasonably well-architected--at least easy to read and change. At a certain point, there's really no good excuse for starting out with a big ball of mud.
Re:How I Became a Better Programmer by ianbicking on Tuesday March 21, 2017 @12:18PM (#13923631)
This is a reasonable expectation when writing something the developer understands and has experience with, with an architecture that seems self-evident early on. Lots of problems are like this.

But when I see developers with the self-expectation of clean code take on a task where the architecture is not self-evident, where the architecture probably won't be right the first time, then they often freeze up. Or they move their efforts into the abstractions they do understand, instead of the task they are trying to accomplish.

Re:How I Became a Better Programmer by cname on Tuesday March 21, 2017 @07:37PM (#13927295)
I've definitely been there fiddling around with abstractions or whatever. I guess I think you're really starting to get good when you see yourself doing that kind of thing and make yourself stop and figure out what the real goal is and how to proceed. E.g., maybe stop banging on the keyboard and draw a picture, work through an example, talk to the client, etc.
Re:How I Became a Better Programmer by BurningFrog on Tuesday March 21, 2017 @12:21PM (#13923667)
Several people made the same argument, so I'll try to answer it here:

I'm talking about one single commit.

If I spend 4 hours on a story, the last half hour is probably spent cleaning up things. That's when it's easiest to do, because now that the problem is solved, I understand things the best, and the code is not in flux.

I do not have to ask a manager for permission to do this. If you do, you should really try to find a job where you're trusted to make these simple technical decisions.

Re:How I Became a Better Programmer by AstralStorm on Tuesday March 21, 2017 @04:04PM (#13925688)
Can you really clean up a bad design in a bunch of minutes?
Re:How I Became a Better Programmer by BurningFrog on Tuesday March 21, 2017 @06:16PM (#13926789)
I'm mostly talking about minor cleanup like finding the best names, removing duplication, deleting unused code. That can be done quickly, and is often easiest once the dust has cleared and the design is finished and working.

If the code is working but is badly designed, that can take longer.

Occasionally, the new feature requires larger refactorings to redesign preexisting code. That can take days, but is of course essential to do.

Re:How I Became a Better Programmer by kwhitefoot on Tuesday March 21, 2017 @07:33AM (#13921287)
The problem is that once the code works there will be external pressure to move on to fix the next bug and add the next feature.
Re:How I Became a Better Programmer by q-base on Tuesday March 21, 2017 @07:49AM (#13921359)
Then don't flag it as ready until you have been through your working code with just some sort of readability/architectural rework focus.

Adhering just somewhat to principles from the beginning shouldn't make this too time consuming.

Re:How I Became a Better Programmer by dplgk on Tuesday March 21, 2017 @10:44AM (#13922579)
> The time to clean up the code is when it already does what it should.

1. That's a good way to break it.

2. Typically there is not extra time given to cleanup code, write docs and unit tests.

Re:How I Became a Better Programmer by wedesoft on Thursday March 23, 2017 @05:11AM (#13938280)
In TDD you do small cycles: 1. write failing test, 2. write code to pass test, 3. refactor I.e. refactoring is part of the workflow