News for hackers. Stuff that matters.
Re:How I Became a Better Programmer by couchand on Monday March 20, 2017 @10:27PM (#13919371)
There's a lot of value here, but I have to raise concerns about a few things.

First, the title: written in the past tense makes it seem like he believes the journey is complete. The article itself doesn't convey that message, fortunately. But I think it's worth noting that a critical skill for a professional is constant education - don't be satisfied that you're already "better", get better every day.

I also strongly disagree with the suggestion that you should ignore the form of your code. Code is read many, many times more than it is written, so improvements to your own and your teammates' understanding can pay huge dividends.

In particular, the advice to "not worry about" DRY and duplicate freely reveals a common misunderstanding. DRY shouldn't be taken literally, it is a recognition that repetition is evidence of some greater underlying truth. By duplicating freely rather than thoughtfully avoiding duplication, you're just creating opportunities for bugs.

Re:How I Became a Better Programmer by bobwaycott on Tuesday March 21, 2017 @03:48AM (#13920479)
I met James around 9 years ago when I was first starting out in professional development, before he eventually joined Mozilla. I inherited more than one massive project from him, and I'd like to assure you he did not actually ignore the form of his code, nor did he avoid improvements that paid huge dividends. I've always been rather OCD about DRYness, and I never had cause to complain about the quality of his work, nor was there ever much of any duplication.

I believe the spirit of what he's trying to get at is not letting concern for DRYness stand in the way of working things out. I saw this in practice many times, and even approach complex projects in much the same way--I'll typically not worry about DRYness until I've implemented something a couple of times, sometimes in different ways, to get a feel for how I can approach it best. Once I've figured that out, I clean things up.

I've seen many junior devs get so worried about the quality of their code, and how they should do things, and omgosh, DRY that they can often become paralyzed and don't just start writing code. I've been mentoring someone for nearly 18 months, and I'm always trying to push him to just start coding and get something working, then come back and discuss and evaluate his work together.

I think you've misunderstood what James has said, and feel compelled to push back on any suggestion that his advice regarding DRY and duplication is borne of any misunderstanding or lack of recognition of the value of DRY. Nor is he someone who I've ever seen stop learning. I keep up with his work, and I'm always impressed by the different things he picks up just because something about it interests him.

Re:How I Became a Better Programmer by Chris2048 on Wednesday March 22, 2017 @11:15AM (#13931572)
> I've seen many junior devs get so worried about the quality of their code, and how they should do things

TBH, junior devs are often hammered constantly throughout training about this stuff. They are drilled on design patterns before having even coded anything significant.

It's not surprising they can only breathlessly parrot software principles when they begin..

Re:How I Became a Better Programmer by jlongster on Thursday March 23, 2017 @03:44PM (#13943472)
Holy crap Bob, hi! Thank you for the kind words :) (and be honest, I'm sure there were things to complain about from my projects haha)
Re:How I Became a Better Programmer by bobwaycott on Friday March 24, 2017 @10:02PM (#13953687)
We all find things to complain about. But quality of your work or unnecessary duplication wasn't one of them. ;)
Re:How I Became a Better Programmer by richdougherty on Monday March 20, 2017 @11:05PM (#13919536)
Responding to your last two paragraphs...

James's suggestions about ignoring code form, DRY, etc resonate with me because I'm someone who is usually inclined to spend too much time on those things. I consciously try to reduce the effort I put into those things and instead focus on trying to get the code to actually do something!

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
Re:How I Became a Better Programmer by couchand on Tuesday March 21, 2017 @12:56AM (#13919969)
Thanks for providing your perspective here, I'd guess that he has a similar mentality, which is why he wrote that.

In my (admittedly anecdotal) experience, devs who tend to overemphasize formatting and DRY are already self-aware about it, whereas those who give it far too little care and attention regularly shoot themselves in the foot by overlooking simple mistakes that get camouflaged in poor formatting and excessive repetition. My concern is mostly that the latter group would see this article as evidence that they can safely ignore code review comments and such.

Re:How I Became a Better Programmer by _petronius on Tuesday March 21, 2017 @09:19AM (#13921893)
I think this is a really good point. I am probably far too guilty of overemphasizing formatting etc., but by the same token, have seem the chaos that a lack of care in that department can cause, especially on big projects. Coming back to a big pile of code that someone else wrote, which is difficult to read or make sense of, six months after the fact to do maitenance is, like, top three things that make my professional life difficult.

Formatting, DRY, and good code organization don't solve business problems, but they do make solving those problems (and keeping them solved) a lot easier.

Re:How I Became a Better Programmer by damon_c on Monday March 20, 2017 @11:17PM (#13919595)
There is a good place, somewhere in the middle.
Re:How I Became a Better Programmer by pacaro on Tuesday March 21, 2017 @12:07AM (#13919802)
Always, but with regards to writing clean code, it pays to just learn how to do this upfront. An analogy is of cooking. I used to be a very messy cook, the food is just as good, but when I was done the kitchen looked like a bomb had hit it. Cleaning becomes intimidating at that point. Learning to be cleaner in my processes didn't change the end result for the food, but made the rest of the evening much more pleasant. Professional cooks and chefs learn to optimize this, they are neat and clean where this is most efficient, and offload cleanup to a plongeur where necessary.

Secondly I believe that with practice, DRY can become second nature. Back in the mid 90s I wrote a lot of COM code in straight C (for reasons). This ends up being extremely verbose, so repetition carried a sufficient penalty that I learned to avoid it, to carry a sufficient mental model of the code base to know when I could avoid repetition.

[edit] plonjeur -> plongeur

Re:How I Became a Better Programmer by couchand on Tuesday March 21, 2017 @12:46AM (#13919928)
I love your use of the cooking metaphor here. Are you expanding on Uncle Bob's discussion of it in The Clean Coder or was that just a coincidence? If I remember correctly, he uses it there to describe the difference between delivering quickly once (and making a mess in the kitchen) and reliably producing over the long term (by taking a little extra time to clean as you go). Adding the spin about the learning process really (forgive me) sweetens it.
Re:How I Became a Better Programmer by pacaro on Tuesday March 21, 2017 @02:18AM (#13920240)
I'm thinking more of the "You cannot be Mommy!" scene from the movie Ratatouille
Re:How I Became a Better Programmer by Permagate on Monday March 20, 2017 @11:02PM (#13919523)
> I also strongly disagree with the suggestion that you should ignore the form of your code. Code is read many, many times more than it is written, so improvements to your own and your teammates' understanding can pay huge dividends.

While he explicitly said to ignore fluffs, he followed it up with `Another way to say this is "use your time wisely"`. So I interpreted it as to just not spend too much time on fluffs, rather than completely ignoring it (like code styles as you mentioned). He created Prettier, so I'm sure he knows the value of code styling.

Re:How I Became a Better Programmer by couchand on Tuesday March 21, 2017 @01:09AM (#13920009)
Simply using the term "fluff" to describe the form of code shows a lack of respect that I find deeply troubling. Those that pay little attention to code style, form, names of things, etc. (including those who rely on the tooling to fix it for them) tend to miss other, arguably more critical, things. Sometimes, but not always, this happens because those errors are lost in a soup of poor formatting and copy-paste repetition.
Re:How I Became a Better Programmer by hinkley on Tuesday March 21, 2017 @11:02AM (#13922775)
I had a coworker come to my desk one day, years ago. "Why did you add all that duplicated code to that file??" Huh? Oh, I didn't 'add' that duplication. I took two long files by two different authors, changed them to use the same white space, variable names, comment style and organization strategy. That's all I did. I didn't have the time at that moment to take the next step.

He came back four hours later and said that he couldn't stand it and he had refactored the code and fixed/written some tests.

Perfect. I learned long ago that there are ways you can start cleaning that will induce (some) others to participate.

He spent hours writing tests while I was working on an adjacent part of the code that had worse bugs in it. The work got done and a big piece of the code (this was a project I supported but didn't maintain) didn't, in the end, have my edit history all over it.

Re:How I Became a Better Programmer by collyw on Tuesday March 21, 2017 @05:06AM (#13920715)
I see a lot of article that tell you how to improve code, and they often seem focused in the wrong area. Python's PEP for example, I see the value in it, but you can follow that to the letter and still have a badly designed application and confusing code.
Re:How I Became a Better Programmer by Chris2048 on Tuesday March 21, 2017 @10:07AM (#13922280)
Aren't style guides supposed to help write code that is more standard in style, and hence easier to read - because your brain will become accustomed to that style.

And PEPs cover many things.

Re:How I Became a Better Programmer by Vinnl on Tuesday March 21, 2017 @03:51AM (#13920488)
But then again, actually writing a code formatter does show quite some respect ;)
Re:How I Became a Better Programmer by jredwards on Tuesday March 21, 2017 @12:12AM (#13919825)
Other people's time is also valuable. Try not to write code that's impossible to read.
Re:How I Became a Better Programmer by cloverich on Tuesday March 21, 2017 @11:09AM (#13922846)
I think pure style (e.g. that a linter would catch) and DRY could be treated separately. The former should always be followed. To the latter: I find weak or incorrect abstractions much harder to follow than repetitive code. And I find those much more commonly when implemented early rather than later.

There's definitely a balance, and if you know the type of problem you are solving ahead of time you can probably abstract early. But if you're just kind of feeling around in the dark, which seems to be relatively common in complex business applications (for instance), I much appreciate an implement-test-reflect-refator cycle.

Re:How I Became a Better Programmer by AstralStorm on Tuesday March 21, 2017 @04:08PM (#13925726)
For actual redesign, you end up with a long true refactoring iteration when no new features can be added. There is no guarantee you will not repeat the same mistakes or make it worse.

It is a very tough sell to most customers.

The quick cycle does not scale with project size.

Re:How I Became a Better Programmer by nallerooth on Tuesday March 21, 2017 @03:55AM (#13920497)
My interpretation was more like "do not focus too much on the form of your code, while you are figuring things out". Which I think is decent advice.

The classic line "Make It Work, Make It Right, Make It Fast"[1] may have communicated this concept in a better way (with each step explained).

[1] http://wiki.c2.com/?MakeItWorkMakeItRightMakeItFast

Re:How I Became a Better Programmer by rimliu on Tuesday March 21, 2017 @08:27AM (#13921536)
Yes. There is also "wrong abstraction is worse than code duplication".
Re:How I Became a Better Programmer by amelius on Tuesday March 21, 2017 @06:25AM (#13920980)
> First, the title: written in the past tense makes it seem like he believes the journey is complete.

How should he have formulated the title then? I think it is logically correct.

Re:How I Became a Better Programmer by couchand on Tuesday March 21, 2017 @12:05PM (#13923484)
Anything in the present tense would be preferable. Just a one letter change would be an improvement: "How I Become A Better Programmer". If it's in the past tense, possibly some indication that he's partway along the journey, such as "How I Got to the Level of Programmer I Am Today" (not as punchy, needs editing).
Re:How I Became a Better Programmer by sriku on Tuesday March 21, 2017 @12:28AM (#13919884)
The note about DRY didn't sound like a mandate to ignore it entirely and "duplicate freely". As you said, duplication is a way to ratify that a common pattern exists first before putting something in place that captures the pattern. Many young programmers try to anticipate these concepts and end up with some form of over-design. The goal of DRY is not so much to avoid duplication, but to figure out useful concepts in ground-up work.

"Beta abstraction" is a useful mechanism for this. Wrote a post capturing some discussions in my org. [1]

[1]: http://sriku.org/blog/2016/02/06/beta-abstraction-for-bottom...

edit: I wrote "as you said", but I expanded on what you said instead.

Re:How I Became a Better Programmer by AstralStorm on Tuesday March 21, 2017 @11:01AM (#13922758)
If you do not anticipate concerns and rely solely on bottom up design, you are guaranteed to require expensive rewrites. Plural. It is also as trivially easy to end up with bad abstraction bottom up add top down, usually by not taking measures to uncouple components (also known as leaking implementation in abstraction)

Properly anticipating issues takes experience.

Re:How I Became a Better Programmer by sriku on Wednesday March 22, 2017 @12:37AM (#13928488)
Thus far, "properly" has been elusive - I.e. we know it when we see it, but not beforehand​. It has been easier to instruct people to look at past concerns in similar projects and tick off which ones are relevant based on current constraints and requirements. So it is not a one-time task to set the "properly" needle right, but a continuous one to keep adjusting it as the cases evolve.

The way abstractions are usually laid out is by trying to generalize a concept, usually along simplistic lines without attempting to substantiate it. Beta abstraction provides a substantiatable route which could involve a bit of repeating before the abstraction surfaces. For example, the Pixar cars don't form a class hierarchy with a "car" base class - there is only one class "car" and the variety is generated by configuration (need to pull up ref for this, as I read this long ago). This may not be an obvious step for someone not in the domain.

Re:How I Became a Better Programmer by pacomerh on Tuesday March 21, 2017 @02:15AM (#13920227)
Same thought here. He makes it sound like he got to the finish line. This is an infinite journey. Good read though.
Re:How I Became a Better Programmer by zoul on Tuesday March 21, 2017 @02:40AM (#13920299)
He explicitly writes:

Even now, though, I continually doubt myself. The point is that this feeling doesn't go away, so just try to ignore it, keep hacking, and keep building experience.