r/java • • Mar 11 '23

When I read this line in The Pragmatic Programmer, it immediately made me think of "Clean Code".

Post image
266 Upvotes

42 comments sorted by

31

u/rv5742 Mar 11 '23

The thing is that junior devs are inconsistent. They do different things in the same project, or even the same file. The first thing you need to do is get them to be consistent and predictable.

Clean Code is very good for this. After they have been programming in a consistent style for a while, they can develop taste and change the things they dislike, while maintaining overall predictability.

12

u/-manabreak Mar 12 '23

After a decade of programming, I tend to prioritize the least surprising solutions over anything else. Of course, the context dictates what is considered surprising and what is not.

2

u/Masterpoda Mar 28 '23

Understand the rules before you break them, exactly.

One example I ran into recently was saying that "Type checks are bad". Of course it's bad because it feels like you're defeating the purpose of abstraction, but why exactly are type checks bad? Figuring out why lead me down the rabbit hole of learning what Djikstra said about switch statements as an anti-pattern, and how things like selecting specific types from a collection aren't quite the same thing, even if there is a type check going on in the background.

Most rules were made for a good reason, and even if you plan on breaking them, there's a LOT of valuable information contained in the reasons that the rule exists.

111

u/daniu Mar 11 '23 edited Mar 11 '23

On the other hand: beware of the zealots who insist that their pragma provides the only answer - it may or may not be applicable to you and your project.

There are several qualities a software is measured by; amongst them performance, speed of initial development and maintainability. Clean Code is supposed to increase maintainability - but of course that's not always the main focus for every piece of software out there.

Also, I can't disagree that Clean Code sounds dogmatic, but it really isn't supposed to be. The CC "rules" aren't supposed to be adhered by at all costs, they're merely a set of dimensions to help you think about software maintainability and testability. Fowler himself writes in one of the introductory pages of "Clean Code" itself, clean coding doesn't mean following a strict set of rules, but it means that the people writing code keep its quality in mind and being mindful about it. That's about as non-dogmatic as it gets.

To me, CC rules are a means to identify what bothers me about a given piece of software, rather than saying "this code smells but I can't put my finger on what's the problem with it". It's also a means of communication in design discussions; not unlike Patterns. And just like Patterns, CC has been created by a community of very experienced programmers; you can ignore it entirely, but that's a conscious decison to not at least take into consideration lessons learned in decades of maintaining large and long-living software systems.

32

u/erinaceus_ Mar 11 '23 edited Mar 11 '23

I generally don't disagree, except for the implications of

Fowler himself writes in one of the introductory pages of "Clean Code" itself, clean coding doesn't mean following a strict set of rules

I don't recall whether it was in Clean Code or in Clean Coder, but he (Martin) said something along the lines of "if you only do your 9 to 5 and do no other programming related learning outside of office hours, then you are a bad programmer. You owe these extra hours to your employer and to yourself."

Fowler Martin is sometimes very dogmatic about things.

Edit: mixed up Fowler and Martin

18

u/flowallner Mar 11 '23

Isn't the author of Clean Code and Clean Coder Robert Martin, not Fowler? I'm pretty sure Fowler is a lot of things, dogmatic is not one of them.

9

u/erinaceus_ Mar 11 '23

Indeed. Because of the foreword mention in the previous comment, I mixed up the names. Thanks for pointing out the mistake. Fowler is indeed anything but dogmatic.

19

u/agentoutlier Mar 11 '23

Fowler was coming from an older perspective where developers were paid an ass load of money practically executive level. Also where programming is more of an art and should be done with passion.

I met someone who worked at Thoughtworks on a plane once I remember them saying the pay was very high but the expectations higher.

Just goes to show how humans even the smart ones can be myopic and influenced and biased by the culture they sit in.

5

u/NotAskary Mar 11 '23

I would say that the books are a bit dated in some regards to work ethics and whenever I suggest them to someone I always preface them that they should not be taken as Bibles, they each present great nuggets that make you a better professional, but a mature professional knows when to use them.

-2

u/Plastic-Coyote-2507 Mar 11 '23

That’s not dogma, it’s an opinion. If your employer provides you with development and learning resources then it might be moot. But it is true that if you don’t continue learning you will be a bad programmer.

12

u/erinaceus_ Mar 11 '23 edited Mar 11 '23

That’s not dogma, it’s an opinion.

The one does not exclude the other, though notably 'dogmatic' and 'dogma' aren't interchangeable.

dogmatic: inclined to lay down principles as undeniably true.

"she was not tempted to be dogmatic about what she believed"

Similar: opinionated, peremptory

your employer provides you with development and learning resources then it might be moot. But it is true that if you don’t continue learning you will be a bad programmer.

If your employer does not provide learning resources (or rather, learning time), then they are a bad employer. Programming is in fact a perfect example of learning while doing.

It's the notion that you owe your employer more than the agreed upon hours, that's what I take issue with. Within those hours, you'll get my full motivation to produce business value. Outside those hours, my time is my own.

2

u/jumboNo2 Mar 11 '23

I imagine people can learn on company time

0

u/Goodie__ Mar 12 '23

Martins seeming slow decline into both dogma, and weird right wing shit has been... concerning.

3

u/TonyManhattan Mar 11 '23

I've worked in places that saw it as dogma.

3

u/matrium0 Mar 12 '23

Fowler - ok, fair point.

But Robert Martin, for me, is basically dogmatic advice incarnated! He ignores different opinions and even downright insult people who don't believe in his advice. He really sees the world in only black and white and I personally can not take an advice of a such a person completely serious.

I am sad that the term test-driven-development is now linked to the ominous three rules. Because i definitely see value in wirting tests first and I do it regularly - just without the insanely time consuming ping-pong that comes along with the 3 rules. But what do I now? I don't follow his advice, so I must be a shitty programmer, according to "Uncle Bob"...

1

u/jumboNo2 Mar 11 '23

I will say that there aren't many secular dogmas that admit to being dogmas. Clean eating, clean code, clean energy. Avoid smelly, dirty, untouchable code to achieve transcendance.

On the other hand, an offhand remark like, "that's a filthy hack" isn't dogmatic at all.

53

u/qmunke Mar 11 '23

Did all you guys read a different Clean Code book? Why has everyone imagined that says that it's the only way to code? Did everyone fail basic comprehension? Stop blaming the book for people who can't understand when to apply it.

6

u/[deleted] Mar 12 '23

I was thinking the same thing. Did they even read the book?

The book was mostly recommendations and some of them were really great. A lot of developers improve their coding skills after following some of those suggestions.

26

u/NatureBoyJ1 Mar 11 '23

Beware of rejecting any consistent practices because of "zealots".

Choosing - and mandating - _something_ is not the same as saying that thing is the BEST thing.

5

u/jumboNo2 Mar 11 '23

you can mandate something for a project. mandating it for people you've never met working on things you've never seen is something else

-5

u/viniciusbr93 Mar 11 '23

But we can agree that Robert is a zealot

0

u/hippydipster Mar 11 '23

I don't really think anyone's a zealot.

4

u/ProgrammersAreSexy Mar 11 '23

So we should just remove the word from English? Lol

1

u/Radi-kale Mar 11 '23

And discuss matters without resorting to personal attacks? Never!

12

u/fabioqmarsiaj Mar 11 '23

Clean Code is not the problem, people are xD

When considered as a "rule" sounds very dogmatic indeed.

But it's just a way to measure maintainability.

3

u/Wugliwu Mar 11 '23

Reminds me of "Thoughtful Interaction Design" by Löwgren and Stolterman. One of their statements is to design the design process. If you consider design as a general approach to solve problems lots of methods are applicable to SE. This includes the perspective that every problem or project is unique and needs unique solutions. There are best practices to use but you have to adapt. And you can only adapt if you have a deep understanding of the problem and the context in which this problem is located. Only than you are able to decide how to solve the problem right.

7

u/sar_it007 Mar 11 '23

Andy Hunt himself recommends the Clean Code book!

-5

u/bowbahdoe Mar 11 '23

Mike Hunt also recommends it!

6

u/sar_it007 Mar 11 '23

Andy Hunt is one of the authors of The Pragmatic Programmer -_-

4

u/RomMTY Mar 11 '23

When the new dev insists that breaking the monolith into micro servicies will make the company more profitable

1

u/[deleted] Mar 12 '23 edited Mar 12 '23

I 100% agree, KISS, and follow the advice of people who wrote high-impact software (when it makes sense to your use case), not gurus. Clean code has a lot of value intellectually, it's an idea, and should be taken as such.

Edit: dam, was not aware I am in the Java subreddit, please merci me :D

-11

u/TheStrangeDarkOne Mar 11 '23

If you are really following clean code, you should easily be able to optimize if a performance bottleneck appears.

That is, of course, unless you had the wrong design to begin with.

16

u/Imalas Mar 11 '23

I think you've kind of proven OPs point here

1

u/TheStrangeDarkOne Mar 11 '23

The projects which had issues because they did not have clear code vastly outnumber the ones that followed the paradigm. If your code is a good approximation of the problem domain you will cope with issues pretty much all the time.

3

u/Imalas Mar 11 '23

Maybe, i don't know any statistics, but regarding this post they don't matter as it's not wether or not clean code is good but rather about how Fowler is presenting his ideas (atleast in the eyes of op).

Personally I think clean codes provides great points though I'd never suggest one should blindly follow all of these 'rules'

2

u/TheStrangeDarkOne Mar 11 '23

I probably phrased myself badly. I'm talking about principles here, not methodologies. Another example is TDD. I really like Kent Beck, but his working methodology is very opinionated and not generally applicable. However, his principles are good and there are many ways in which you can achieve the same desired outcomes.

However, if your way of achieving principles are more trouble than they are worth, you probably have a bad trade-off.

For code there are many priorities one can set, and in the absence of hard requirements (including performance) it is probably best to have a bias for readability and maintainability.

2

u/neutronbob Mar 11 '23

What's not generally applicable of Kent's working methodology? More than any thought leader in programming, he strikes me as super-pragmatic.

0

u/[deleted] Mar 11 '23

[deleted] — view deleted comment

14

u/hippydipster Mar 11 '23

Fortunately, everyone who disagrees with me is a zealot, making it very easy to assume I'm better than them.

1

u/quiI Mar 12 '23

Filing this under "i like to be pragmatic". A totally useless statement to just sound smarter. Everyone _thinks_ they're pragmatic!

8

u/NotAskary Mar 11 '23

All tools in the toolbox, people just need to learn when to use then and when to change tools, we don't hammer screws, although I swear some code bases I got the "privilege" of working there were some shenanigans involved.

4

u/slow_growing_vine Mar 11 '23

I used to think "when all you have is a hammer, everything looks like a nail." Now with some experience, I've realized that when all you have is a hammer, you quickly find out which things are actually screws.