this post was submitted on 10 Aug 2024
138 points (95.4% liked)

Programming

17432 readers
240 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS
 

Seeing that Uncle Bob is making a new version of Clean Code I decided to try and find this article about the original.

you are viewing a single comment's thread
view the rest of the comments
[–] kogasa@programming.dev 3 points 3 months ago (8 children)

You realize this is just an argument against methods?

[–] Kache@lemm.ee 10 points 3 months ago (7 children)

All methods? Of course not. Just methods like these.

[–] kogasa@programming.dev 2 points 3 months ago (6 children)

No, your argument is equally applicable to all methods. The idea that a method hides implementation details is not a real criticism, it's just a basic fact.

[–] magic_lobster_party@kbin.run 9 points 3 months ago (1 children)

These kind methods hide too much.

Where can I find the commissions these methods calculated? Does extra commissions depend on the calculations of default commissions? Do I need to calculate default commissions before calling hasExtraCommisions? What happens if I calculate extra commissions if hasExtraCommisions return false?

There are so many questions about this code that should be immediately obvious, but isn’t.

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

What you're saying is "descriptive method names aren't a substitute for knowing how the code works." That's once again just a basic fact. It's not "hiding," it's "organization." Organization makes it easier to take a high level view of the code, it doesn't preclude you from digging in at a lower level.

[–] magic_lobster_party@kbin.run 5 points 3 months ago (2 children)

What I’m saying is that it’s hiding too much of the control flow.

Compare it with this code:

public double calculateCommision(Sale sale, Contract contract) {
    double defaultCommision = calculateDefaultCommision(sale);
    double extraCommision = calculateExtraCommision(sale, contract);
    return defaultCommision + extraCommision;
}

This is about the same number of lines, but it communicates so much more about the control flow. It gives us an idea which data is involved in the calculations, and where we can find the result of all the calculations. We can make assumptions that the functions inside are independent from each other, and that they’re probably not relying on side effects.

This is also against clean code examples, because Uncle Bob seems to be allergic against function arguments and return values.

[–] djnattyp@lemmy.world 1 points 3 months ago

This is also against clean code examples, because Uncle Bob seems to be allergic against function arguments and return values.

I think this is your strawman version of "Clean Code"... not anything that's actually in it...

I "like" some parts of your example more than the previous one, but a lot of this depends on where exactly in the whole program this method is - if this method is on a "Salesman" class - does it make sense to pass the "Contract" in? If there's a Contract class available, why doesn't the "calculateCommission" method exist on it?

[–] kogasa@programming.dev 0 points 3 months ago (1 children)

You're making assumptions about the control flow in a hypothetical piece of code...

[–] azulavoir@sh.itjust.works 1 points 3 months ago

Yes, because that's exactly what the thread is about. Making assumptions about control flow.

load more comments (4 replies)
load more comments (4 replies)
load more comments (4 replies)