this post was submitted on 09 Aug 2024
618 points (98.3% liked)

Programmer Humor

32558 readers
683 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 

Those who know, know.

top 50 comments
sorted by: hot top controversial new old
[–] armchair_progamer@programming.dev 130 points 3 months ago (2 children)

But is it rewritten in Rust?

[–] xlash123@sh.itjust.works 39 points 3 months ago

It'll be rewritten in mdBook

load more comments (1 replies)
[–] CodexArcanum@lemmy.world 125 points 3 months ago (6 children)

I should get to work on my opus, "Dirty Code"

Inside I'll reveal all my secrets like: not writing tests, not documenting anything, putting the whole app into a single python file, object-disoriented relational mapping, obscure SQL tricks, unobscure no-sql tricks, and more!

[–] eager_eagle@lemmy.world 56 points 3 months ago (1 children)

object-disoriented

I'll steal this to shit talk about code; until git blame points to my past self

load more comments (1 replies)
[–] tetris11@lemmy.ml 32 points 3 months ago

Just make sure the first chapter is dedicated to spaghetti, and contains various GOTO statements telling where the reader where to go shove it and other obscenities.

[–] pfm@scribe.disroot.org 7 points 3 months ago

I hope your book won't have a table of context and those stupid indexes. If they read it, they should know where you mention topics, right? Tables of contents considered harmful! /s

load more comments (3 replies)
[–] shy_mia@lemmy.blahaj.zone 83 points 3 months ago (3 children)

I'm of the opinion that Uncle Bob did some massive damage to software development as a whole with that book.
With that said, this is genuinely funny.

[–] Phegan@lemmy.world 20 points 3 months ago (1 children)

Agreed. I found that many developers, in the pursuit of clean code, lost slight of some of the fundamentals principles of good code. I found that people were eschewing readability and modularity and calling it clean code.

Clean code became the target, not the underlying principles and the reason why we needed clean code in the first place. It became an entirely new thing that aided in producing some of the worst code I've read.

Oftentimes, when devs talk about "clean code" it's a red flag for me in hiring. Some of the worst devs I've worked with have been clean code evangelists.

[–] pfm@scribe.disroot.org 18 points 3 months ago (1 children)

I'm beginning to feel we're no longer talking about Clean Code being bad, but about people following ideas they don't understand, which is not related or caused to any particular book.

load more comments (1 replies)
[–] pfm@scribe.disroot.org 12 points 3 months ago (1 children)

I'd love to learn what that damage was. I often see complaints (sometimes also involving tech choices) but usually they're not specific, so I'm always left wondering.

[–] shy_mia@lemmy.blahaj.zone 38 points 3 months ago* (last edited 3 months ago) (8 children)

I've found it's mostly two things: readability (ironically) and performance. I'll describe a few crude examples, but I won't get too much into specifics, otherwise I might as well write another book myself.

The performance part is simple: its excessive reliance on polymorphism and the presence of several levels of abstraction just doesn't allow for good code generation. I've seen 10x+ performance improvements by dropping all of the above, with often minimal loss in readability; on the contrary, oftentimes the code became more readable as well.

The readability part is harder to explain; not only because it depends on the codebase and the problem at hand, but also on the coding style each programmer has (though in my opinion, in that particular case it's the programmer's problem, not the codebase's).
I like to think of codebases as puzzles. To understand a codebase, you need to piece together said puzzle. What I've found with Clean Code codebases is that each piece of the puzzle is itself a smaller puzzle to piece together, which isn't ideal.

Functions

They should be small and do one thing

I generally disagree, not because those ideas are wrong, but because they're often too limiting.
What often happens by following those principles is you end up with a slew of tiny functions scattered around your codebase (or a single file), and you are forced to piece together the behaviour they exhibit when called together. Your code loses locality and, much like with CPU cache locality, your brain has to do extra work to retrieve the information it needs every time it needs to jump somewhere else.
It may work for describing what the code does at a high level, but understanding how it works to make meaningful changes will require a lot more work as a result.

Don't repeat yourself

Once again, it makes sense in principle, but in practice it often creates more problems. I agree that having massive chunks of repeated code is bad, no questions about it, but for smaller chunks it may actually be desirable in some circumstances.
By never repeating code, you end up with functions that are over-parameterized to account for all possible uses and combinations that particular code snippet needs to work with. As a result, that code becomes more complex, and the code that calls it does too, because it requires you to know all the right parameters to pass for it to do the right thing.

Exceptions

Exceptions are just bad. They are a separate, hidden control flow that you constantly need to be wary of.
The name itself is a misnomer in my opinion, because they're rarely exceptional: errors are not just common, but an integral part of software development, and they should be treated as such.
Errors as values are much clearer, because they explicitly show that a function may return an error and that it should be handled.

Classes, interfaces and polymorphism

I have lots of gripes with object orientation. Not everything needs to be an object, not everything needs to be polymorphic. There's no need to have a Base64Decoder, much less an IBase64Decoder or an AbstractBase64Decoder. Base64 only works one way, there are no alternative implementations, a function is enough.

I'm a lot more on the data oriented side of the isle than the OO one, but I digress.
Object orientation can be good in certain contexts, but it's not a silver bullet.

Encapsulation for the sake of it

Let's say you have something like this:

class Point {
	public float X, Y;
}

With the Clean Code approach, it magically becomes:

class Point {
	private float x, y;
	
	public float get_x() {
		return this.x;
	}
	public float get_y() {
		return this.y;
	}
	public void set_x(float x) {
		this.x = x;
	}
	public void set_y(float y) {
		this.y = y;
	}
}

Why? Who the hell knows. It makes absolutely no tangible difference, it only makes your code longer and more verbose. Now, if a value needs validation, sure, but oftentimes this is just done regardless and it drives me insane.

Abstract classes for everything!

  • "You'll never know when you'll need to add another implementation, right?"
  • "You don't need to know the underlying implementation"

The problem with wanting to create the most generalized code in advance is that you end up stuck in abstraction hell.
You may as well not need the ability to have arbitrary implementations, but now you need to plan for that.

Not only that, but it also makes reasoning about your code harder: how many times have you had to step through your code just to figure out what was being executed | just to figure out what particular concrete class was hiding behind an abstract class reference?
I myself, way too many, and there was often no reason for that.

Also, the idea that you shouldn't know about the implementation is crazy to me. Completely encapsulating data and behaviour not only makes you miss out on important optimizations, but often leads to code bloat.

There's more but I'm tired of typing :)

Take a look at these if you want more info or someone else's view on the matter, I wholeheartedly recommend both:

[–] bleistift2@sopuli.xyz 16 points 3 months ago* (last edited 3 months ago) (4 children)

Functions should be small and do one thing […] you end up with a slew of tiny functions scattered around your codebase (or a single file), and you are forced to piece together the behaviour they exhibit when called together

I believe you have a wrong idea of what “one thing” is. This comes together with “functions should not mix levels of abstraction” (cited from the first blog entry you referenced). In a very low-level library, “one thing” may be sending an IP packet over a network interface. Higher up, “one thing” may be establishing a database connection. Even higher up, “one thing” may be querying a list of users from the database, and higher up yet again is responding to the GET /users http request. All of these functions do ‘one thing’, but they rely on calls to a few methods that are further down on the abstraction scheme.

By allowing each function to do ‘one thing’, you decompose the huge problem that responding to an HTTP request actually is into more manageable chunks. When you figure out what a function does, it’s way easier to see that the function connectToDb will not be responsible for why all users are suddenly called "Bob". You’ll look into the http handler first, and if that’s not responsible, into getUsersFromDb, and then check what sendQuery does. If all methods truly do one thing, you’ll be certain that checkAuthorization will not be related to the problem.

Tell me if I just didn’t get the point you were trying to make.

Edit: I just read

Martin says that functions should not be large enough to hold nested control structures (conditionals and loops); equivalently, they should not be indented to more than two levels. He says blocks should be one line long, consisting probably of a single function call. […] Most bizarrely, Martin asserts that an ideal function is two to four lines of code long.

If that’s the standard of “doing one thing”, then I agree with you. This is stupid.

load more comments (4 replies)
[–] bleistift2@sopuli.xyz 7 points 3 months ago

Thank you for linking the blog posts. They are a really good deterrent from Clean Code. I once thought I’d read it, but Fowler’s advice really is stupid.

In case you’re wondering why I replied three times: “Do one thing” :)

load more comments (6 replies)
load more comments (1 replies)
[–] NigelFrobisher@aussie.zone 61 points 3 months ago (2 children)

New edition is just an incoherent rant about the “woke mind virus” trying to destroy him for “just saying what everyone is thinking”.

[–] normalexit@lemmy.world 24 points 3 months ago (3 children)

This! Uncle Bob is a garbage person. Used to really respect him, but F that guy.

load more comments (3 replies)
load more comments (1 replies)
[–] Magister@lemmy.world 27 points 3 months ago (5 children)

I'm a programmer since the 80s, who is this guy?

[–] olafurp@lemmy.world 29 points 3 months ago* (last edited 3 months ago) (2 children)

He wrote for example the books Clean Code and Clean Architecture which are IMO opinion really good books although I don't agree with every point he makes.

Some really good points he makes are for example:

  • Functions that only do one job
  • Testing makes refactoring easier
  • The standard SOLID OOP stuff.
  • Tech debt is bad
  • Abstraction and encapsulation is good and allows developers to interact with the code on a higher level in terms of actions instead of writing verbose stuff. Essentially saying less code leads to less bugs
  • Insulate yourself from change
  • Duplication is bad
  • Two use cases that are very similar is not duplication and common code shouldn't be factored out.
  • Don't mix high level code with low level.
  • Build solid Entity classes to model the data and their interactions.
  • Don't write multithreaded code if you don't have to.
  • If you have to do your best to write it so they don't share memory.

Those comes with examples. He's a tad bit overly idealistic in my opinion. These books fail to mention a couple of things:

  • Refactoring is expensive and the cost is often not justified.
  • Premature abstraction is the absolute devil
  • You don't need to insulate from things that are very unlikely to change (like going from SQL to Document DB)
  • Less changes also lead to less bugs.
  • Too much emphasis on functions being few lines of code instead of just being simple.

All in all though, very solid books. I read Clean Code in university and Clean Architecture in my first job and it really helped me wrap my head around different ways to solve the same problem. Excellent ideas but it's not the holy truth. The only reason I remember all of these points is that I encountered all of them on the job and saw the benefit.

In my opinion new programmers should read it and take inspiration. Craftsman level developers should criticise and maybe pick up a few brain concepts to sort some concepts out in their brain. Experts will get little benefit though.

[–] Waldowal@lemmy.world 27 points 3 months ago (7 children)

The consultancy I used to work for in the late 90s would have crucified any developer that didn't write "a data abstraction layer that allows you to pop off the original db and substitute a different one later".

How many times in my 25 year career have I swapped out the database (and been thankful for such an abstraction layer)? 0 times.

[–] Tja@programming.dev 10 points 3 months ago

In my 15 year career? Dozens. Maybe low hundreds. Depends what you work on. Oracle is not making any friends lately and a ton of companies a whole-sale migrating to Postgres, MongoDB, DynamoDB or some of the NewSQL contenders. It's like 50% of the projects I'm involved in. Results are generally positive, with some spectacular wins (x3000 acceleration or x1000 lower costs) and a few losses.

load more comments (6 replies)
[–] marlowe221@lemmy.world 10 points 3 months ago* (last edited 3 months ago) (1 children)

I generally agree with the idea that code should be as simple as it can be to accomplish the goal of the code… I just haven’t been convinced that Clean Code is the way to get there, necessarily. The book does contain some good advice , to be sure, but I wouldn’t call it universal by any means.

I also think TDD is a very optimistic strategy that just doesn’t match up with reality terribly often.

Actually, I think that’s what confuses me the most about all of Uncle Bob’s books. I’ve read a couple of them and thought, “All this sounds great but real world development just doesn’t seem to work that way.” Like, all of his advice is for best case scenarios that I certainly haven’t encountered in my career.

I say confusing, because surely he’s been in the profession long enough to have seen the disconnect between what he’s preaching and real life, right???

load more comments (1 replies)
[–] WanderingVentra@lemm.ee 27 points 3 months ago

Wrote a couple famous books about Clean Code, Architecture, Test Driven Development, OOP, and Agile.

[–] eager_eagle@lemmy.world 17 points 3 months ago

he's a programmer since the 70s

Robert C. Martin

load more comments (2 replies)
[–] quicken@aussie.zone 22 points 3 months ago (2 children)

I was a big Uncle Bob fan and still really like the Clean Code book. But he trashed his public reputation so I doubt this 2nd edition will do very well.

[–] BleatingZombie@lemmy.world 17 points 3 months ago (1 children)

Is there a TL;DR if I don't know who this is?

[–] milkisklim@lemm.ee 9 points 3 months ago (1 children)

Here's the Wikipedia page

Basically he is an old man/ software engineer who's famous for his philosophy of coding.

[–] Anders429@programming.dev 16 points 3 months ago (1 children)

Any context on him "trashing his reputation"?

load more comments (1 replies)
load more comments (1 replies)
[–] EnderMB@lemmy.world 17 points 3 months ago (1 children)

Working in Ruby did 10x more to help me write clean code than reading Clean Code ever did.

Many of the lessons drilled into me with Ruby (keep a consistent style, tests are cheap, keep your methods relatively small where possible, reduce nesting where possible) carry over nicely into other languages without needing to go through any OO bullshit.

IMO, the best lesson around Clean Code is this: you're not clever, write obvious code that works with as few tricks as possible.

load more comments (1 replies)
[–] arisunz@lemmy.blahaj.zone 16 points 3 months ago (1 children)

oh no somebody stop please him

load more comments (1 replies)
[–] prwnr@programming.dev 16 points 3 months ago (2 children)

i am genuinely waiting for it. read the first one almost 10 years ago and it gave me a good start into my programming journey.

even if this second version won't bring in anything new for me, I will be glad to consume it

load more comments (2 replies)
[–] livingcoder@programming.dev 16 points 3 months ago

The bit of Clean Code that I read was unimpressive, but Clean Architecture was amazing. I view that book as required reading for anyone who wants to write code professionally. If Uncle Bob hasn't realized that his coding style is worse than alternatives, I do not see how a second version of the same bad ideas is going to do well.

[–] 1984@lemmy.today 14 points 3 months ago (1 children)
[–] lukstru@lemmy.world 14 points 3 months ago (2 children)

Waiting for him to finish the trilogy with Cleanest Code

[–] rickyrigatoni@lemm.ee 8 points 3 months ago

cleanerer code. gotta leave room for a fourth book: clean code and the crystal skull

load more comments (1 replies)
[–] veganpizza69@lemmy.world 12 points 3 months ago

Glad I didn't read it.

[–] arxdat@lemmy.ml 9 points 3 months ago (3 children)

There are no inherent "rules" in software development. These books are useless and a waste of time. They offer nothing but CS Dogma and are actually against freedom of expression.

[–] sus@programming.dev 40 points 3 months ago* (last edited 3 months ago) (1 children)

Rules of thumb can be very useful for a relatively inexperienced programmer, and once you understand why they exist you can choose to ignore them when they would get in the way. Clean Code is totally unhinged though

[–] doktormerlin@feddit.org 13 points 3 months ago

The problem is that a lot of people don't understand when to ignore the rules and just stick with them forever.

We had a developer once that always said KISS KISS KISS whenever we pointed out that her functions are working but not reusable, so she wrote 20 functions that all did the same thing, but with slightly different parameters. And that's just one of the examples

[–] orcrist@lemm.ee 9 points 3 months ago

CS often requires working in teams, and working it teams is often more efficient if you have some shared approaches.

[–] bleistift2@sopuli.xyz 7 points 3 months ago

There are no inherent “rules” to language, either, but when you don’t followthemthingsgetmessyandyou’reannoyingforeveryoneelese.

[–] matzler@lemmy.ml 7 points 3 months ago

Those of you who red and liked clean code (I did too), what's your next best recommendation as a book? The pragmatic programmer?

load more comments
view more: next ›