magic_lobster_party

joined 8 months ago
[–] magic_lobster_party@kbin.run 3 points 3 months ago

There’s no profits in this.

[–] magic_lobster_party@kbin.run 10 points 3 months ago

Your description is accurate. No need for that /s

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

I think try catch often leads to messy code. It breaks the control flow in weird ways. For some reason we’ve collectively agreed on that goto is a bad idea, but we’re still using exceptions for error handling.

Consider this example:

try {
    File file = openFile();
    String contents = file.read();
    file.close();
    return contents:
} catch (IoException) {
}

Say an exception is triggered. Which of these lines triggered the exception? It’s hard to tell.

We might want to handle each type of error differently. If we fail to open the file, we might want to use a backup file instead. If we fail to read the file, we might want to close it and retry with the same file again to see if it works better this time. If we fail to close the file, we might just want to raise a warning. We already got what we wanted.

One way to handle this is to wrap each line around a separate try catch. This is incredibly messy and leads to problematic scopes. Another way is to have 3 different exception types: FileOpenException, FileReadException and FileCloseException. This is also incredibly messy.

Or we can include the error in the return value. Then we can do whatever we want programmatically like any other code we write.

[–] magic_lobster_party@kbin.run 5 points 3 months ago (3 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.

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

Academia has a disconnect with the industry when it comes to coding practices. Most teachers haven’t much industry experience. They don’t know how it is to maintain a 10 year old project using SOLID and clean code principles.

They just teach whatever has already been in the curriculum for decades. They don’t know that whatever they’re teaching is actually harmful in the industry.

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

Problem is that barely anyone use crypto as currency. Almost everybody treat it as a stupid get rich quick scheme.

[–] magic_lobster_party@kbin.run 7 points 3 months ago

It’s abstract art!

[–] magic_lobster_party@kbin.run 9 points 3 months ago

I heavily disagree it’s easier to write good code if you follow clean code. Especially if you follow his examples throughout the book. Most of his examples are just over engineered messes held together by side effects (even if he says side effects is a bad thing).

If he can’t write good code by following clean code, why should you? He even picked the examples himself and failed!

[–] magic_lobster_party@kbin.run 9 points 3 months ago (5 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.

[–] magic_lobster_party@kbin.run 14 points 3 months ago

The article goes into that. Clean Code has some good advice. But it also got bad advice.

Problem is, the good advice is basic. Anyone working in the industry will pick most of these up. All the good advice could be summed up in 10 pages or so.

The bad advice is incredibly bad - and in the worst cases even be counter productive. A newbie won’t be able to tell these advice apart. Some professionals might not either. So they adopt these techniques to their code, and slowly their code turns into an unmaintainable mess of spaghetti.

So no, the book shouldn’t be recommended to anybody. It has already done enough harm to the industry.

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

Robert Martin's "Clean Code" is an incredibly useful book which helps write code that Fits In Your Head

It has the exact opposite effect. It leads to code that doesn’t fit in your head.

Because his style of coding leads to code where everything useful are 10 levels deep in nested method calls. If I want to understand how the code works and how my changes will affect the overall picture, I need to keep a dozen methods in my head and how all of these are connected to each other.

And he’s mostly working with global states, so knowing where variables are assigned is just a huge pain.

So many times I’ve looked into code like this where I finally find what I’m looking for, only to forget how I even reached this part of the code. So I need to backtrack to remember how I got there, but then I forget where that damn thing I was looking for is. And I go back and forth until I figure out a mental model of the code. It’s awful!

Compare that with just having one big method. Everything is in front of me. I don’t need to keep that many things in my head at the same time, because everything I need is right there in front of my eyes.

Sure, sometimes breaking out to separate methods can make it easier to communicate what the code does and the boundaries of each scope, but if it’s overdone it leads to code that’s impossible to work with.

 

Decipher a new quote every day! Test your skills with this new daily brainteaser.

 

Piped link: https://piped.video/watch?v=3so7xdZHKxw

Radiance Cascades are an innovative solution to global illumination from the devs of Path of Exile 2.

I think this video is informative and describes the new approach in a way that’s easy to follow. It’s simple with impressive results.

Link to paper:
https://drive.google.com/file/d/1L6v1_7HY2X-LV3Ofb6oyTIxgEaP4LOI6/view?usp=sharing

A more impressive demo:
https://youtu.be/6O9-BUDk_-c?si=j-cyMMPyjIBthDYw
https://piped.video/watch?v=6O9-BUDk_-c

view more: next ›