Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
smackfu
Jun 7, 2004

Sistergodiva posted:

public static String URL_SEPARATOR = "/";

This kind of thing is when people think too much about magic numbers and anonymous string parts.

Some people never met a string literal that shouldn’t be a constant.

Adbot
ADBOT LOVES YOU

prom candy
Dec 16, 2005

Only I may dance

a dingus posted:

Following Clean Code is better than nothing if you're a beginner just at the point where you can create spaghetti code and have no strong opinions of your own. Once you get some experience you'll start to find examples of the book falling apart, but by then you know the rules well enough to know when to break them. If you're already a working dev then I'd read the book and let the ideas float around in your head but don't be dogmatic about anything.

Granted I don't have a recommendation but is there nothing more up to date for today's beginners?

StumblyWumbly
Sep 12, 2007

Batmanticore!

prom candy posted:

Granted I don't have a recommendation but is there nothing more up to date for today's beginners?

ChatGPT

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

prom candy posted:

Granted I don't have a recommendation but is there nothing more up to date for today's beginners?

maybe The Pragmatic Programmer, I'm not sure I'd call it more up to date but it has better advice

Bongo Bill
Jan 17, 2012

As long as we're comparing straw men, I'd rather work with someone who takes Clean Code too far and out of context than with someone who thinks that readability is a naïve fantasy. Beginners are going to be wrong, but it matters what motivates the errors.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I think you completely misunderstand the criticism of the book. When someone says "Clean Code is bad", they mean that the book is bad and does not teach you to write clean code, not the concept of readable code does not exist.

prom candy
Dec 16, 2005

Only I may dance
Yeah I haven't read the book but the example the goon posted above the "clean" refactor is worse than the original code. I went through a phase of writing code like that and it's not easy to work with. The rigid adherence to DRY and short methods means you end up with a lot of weird/bad abstractions and splitting one perfectly good 8 line function into two 4 line functions that have no real reason to be separate.

Mega Comrade
Apr 22, 2004

Listen buddy, we all got problems!

thotsky posted:

Clean code as a phenomenon is more destructive than the book itself. A lot of teams will treat it as a Bible, even though a bunch of stuff in it is obviously bad or outdated advice.

Developers who worry a bunch about "magic numbers" and breaking every logical block of code out into its own function rather than think critically about readability are the bane of my existence.

I never meet these developers. Instead I get the ones who see a 100 line function and go "well making it 120 lines won't hurt"

thotsky
Jun 7, 2005

hot to trot

Mega Comrade posted:

I never meet these developers. Instead I get the ones who see a 100 line function and go "well making it 120 lines won't hurt"

It might not. I don't mind a deep function. I do mind putting those extra 20 lines in another few lines of function boilerplate somewhere else, when it is only going to be called from that original function anyway.

Doom Mathematic
Sep 2, 2008

Doom Mathematic posted:

Clean Code is like a recipe book where about half of the recipes will give you food poisoning. And fans of the book all say that it's actually not the recipe book writer's job to make sure that all the recipes are safe, it's the reader's job to read the recipe book carefully, and then make their own decision about which recipes will or won't give them food poisoning. Which is especially funny as a defense when the reader is a complete beginner who doesn't know how to cook at all and they're reading the book in order to learn.

Also the good recipes are completely mundane and simple. Like, scrambled eggs.

E: Not that it's not worth knowing how to make scrambled eggs but if the book has no value to a beginner and also has no value to someone with experience, then the book isn't worth recommending.

Sistergodiva
Jan 3, 2006

I'm like you,
I have no shame.

That's why vscode has a minimap. Maybe you could add some cool large ASCII title for different parts to spot them on the map?

Maybe it's because of old-school web dev origins, but it seems like a lot of people I know really don't like breaking up things in different files etc.

React components is helping because it's more obvious what should be split.

Does vscode have an easy way to navigate to the definition of a function? In intellij I can just ctrl-click and navigate to it. Wouldn't survive without that, especially when you can navigate to a third party library to see the implementation.

From what I see from colleagues searching and moving around in vscode seems a bit bad, but it could also be them not knowing how to do it properly.

SurgicalOntologist
Jun 17, 2004

One of our first developers (no longer with us) was a Clean Code fanatic. I just refactored one of his services and reduced the number of lines literally 75%. Probably the most satisfying PR I've ever submitted.

The "domain logic" module was full of one-line functions that just passed the arguments to another function. And that was only one layer out of four with most of the layers having just one or two lines. In the end I flatted it to one layer and most of the functions are still only about 4 lines. I'm sure that kind of strict architecture helps in a complex app but in this simple service it made it super tedious to trace what was supposed to happen.

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell

Sistergodiva posted:

Does vscode have an easy way to navigate to the definition of a function? In intellij I can just ctrl-click and navigate to it. Wouldn't survive without that, especially when you can navigate to a third party library to see the implementation.

From what I see from colleagues searching and moving around in vscode seems a bit bad, but it could also be them not knowing how to do it properly.

F12 is the default for jump to definition IIRC

Also ctrl-p is nice for fast navigation between files

StumblyWumbly
Sep 12, 2007

Batmanticore!
I'm always suspicious when folks talk about writing "easy to read" code because I've met folks for whom that just means they don't understand stuff unless they wrote it.
Easy to read requires metrics, and short is not necessarily the best metric.

a dingus
Mar 22, 2008

Rhetorical questions only
Fun Shoe

taqueso posted:

maybe The Pragmatic Programmer, I'm not sure I'd call it more up to date but it has better advice

This is the book I was thinking of too. Better than clean code.

lifg
Dec 4, 2000
<this tag left blank>
Muldoon
Code Complete is good too, but it’s also a doorstop of a book.

StumblyWumbly
Sep 12, 2007

Batmanticore!

lifg posted:

Code Complete is good too, but it’s also a doorstop of a book.

It has a whole chapter on how to structure your if statements. (It's actually a useful chapter)
It's a good book, definitely worth skimming through, but I don't think anyone has read it completely, including the author.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

prom candy posted:

Granted I don't have a recommendation but is there nothing more up to date for today's beginners?
honestly I've pointed more than one junior person to tef's blog

12 rats tied together
Sep 7, 2006

the best thing you can do for today's beginners is to have read these things yourself and to provide practical demonstration of their good parts with code review.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
Uncle Bob is an alt-right creep, about what you would expect from someone whose entire identity is about playbooks for clinging to your dogma

Pollyanna
Mar 5, 2005

Milk's on them.


:sigh: Based on this discussion it looks like a lot of my assumptions about programming best practices are either outdated or misinformed. I think I’ll load these recs up and review what I think I know.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Take a look at The Programmer's Brain. I'll copy their blurb rather than try to summarize it myself:

quote:

Your brain responds in a predictable way when it encounters new or difficult tasks. This unique book teaches you concrete techniques rooted in cognitive science that will improve the way you learn and think about code.

In The Programmer’s Brain: What every programmer needs to know about cognition you will learn:
  • Fast and effective ways to master new programming languages
  • Speed reading skills to quickly comprehend new code
  • Techniques to unravel the meaning of complex code
  • Ways to learn new syntax and keep it memorized
  • Writing code that is easy for others to read
  • Picking the right names for your variables
  • Making your codebase more understandable to newcomers
  • Onboarding new developers to your team

Hughlander
May 11, 2005

My take away is that good code is like pornography. I can’t explain it but I know it when I see it.

Fellatio del Toro
Mar 21, 2009

Hughlander posted:

My take away is that good code is like pornography. its on the screen on my work computer from 9am to 5pm

BusError
Jan 4, 2005

stupid babies need the most attention
I read Clean Code at a really unfortunate time in my career and became an insufferable zealot for its advice for a year or two after that. If you worked with me during that time, sorry! That said, it did get me to think about things I hadn't considered before, and now that I'm a lot older and can apply critical thinking and nuance to it, I'm glad I have those ideas to consider.

Nowadays I think that it'd be a lot more valuable to just take its table of contents as a starting point for a team discussion about standards and maybe some experimentation than to actually read the whole text. Also yeah Bob Martin is a shithead which may or may not be of concern to you re: giving him money.

Mega Comrade
Apr 22, 2004

Listen buddy, we all got problems!
Yeah you shouldn't be buying clean code in 2023. There are various github repos with snippets of all the actual good bits in it for free.

smackfu
Jun 7, 2004

It would be great if college programming courses just had people submit PRs and then the professors commented on them and the students had to respond and fix their stuff.

I assume this is nothing like what is actually done even now.

(When I went to school, we had to email programs to the professor and I guess they just ran them? It was ancient times.)

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


A lot of it's done with autograders now. That's not ideal but the demand for CS education pretty far outpaces the supply of people who can take a more hands-on approach and are willing to do so for an academic paycheck.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
My alma mater created the CS department as an outgrowth of the math department, and IMHO it really, really shows even today.

Source control? Pull requests? Practical applications? Wake up, you're having a bad dream, I don't know what you're talking about but you have some Formal Proofs of Algorithm performance to hand in!

thotsky
Jun 7, 2005

hot to trot

smackfu posted:

It would be great if college programming courses just had people submit PRs and then the professors commented on them and the students had to respond and fix their stuff.

I assume this is nothing like what is actually done even now.

(When I went to school, we had to email programs to the professor and I guess they just ran them? It was ancient times.)

The dude whose book is often recommended as an alternative to Clean Code (although the book is not really a close equivalent) does exactly that, and talks about it in this talk:

https://youtu.be/bmSAYlu0NcY

Bongo Bill
Jan 17, 2012

I just realized I was thinking of Code Complete this whole conversation, not Clean Code.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

smackfu posted:

It would be great if college programming courses just had people submit PRs and then the professors commented on them and the students had to respond and fix their stuff.

I assume this is nothing like what is actually done even now.
Forward-thinking professors do exactly this - GitHub has support for educational settings around managing students and TAs, grading within PRs, etc, and it seems to more or less work.

(of course good luck getting any phd-haver over the age of 40 to do this)

This worked in the grad-level classes that I took but I could imagine it's trickier in undergrad classes: in my experience nobody learns how version control works until upper-level classes, which means that for the first half of one's degree you haven't been taught the background to use git (and/or the faculty member doesn't know how it works either)

Dijkstracula fucked around with this message at 16:39 on Feb 12, 2023

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I had a class where your grade was based entirely on presenting the code you wrote and basically doing an in-person code review of your homework. This was an absolute shitload of work for everyone involved and required a big pile of TAs so it was pretty obvious why it wasn't a normal way to do things, but it was incredibly valuable. This was before pull reviews and async code reviews had become standard industry practice, so adopting that would maybe make it scale better.

wilderthanmild
Jun 21, 2010

Posting shit




Grimey Drawer
If you wanted to do the code review process in school it might be best to have the students do a fair chunk of the reviewing themselves. Learning to code review is just as important of a skill and helps learning.

Since all things in school have to get tied to grade you could probably make the grading equal parts between how good your initial code is, how well you do on you on reviewing others, and how well you do at responding to reviews.

Ruggan
Feb 20, 2007
WHAT THAT SMELL LIKE?!



Helper functions can be incredibly helpful in making code more organized, readable, and maintainable. They can also make it easier to reuse code and reduce the amount of duplicated code in a project.

However, there are also times when helper functions can be harmful and make code less readable and maintainable. Here are some guidelines for when to use helper functions:

1. When a block of code is used repeatedly in different parts of a program, it's often a good idea to encapsulate that code in a helper function.
2. When a block of code performs a specific, well-defined task that is separate from the main logic of the program, it's also a good candidate for a helper function.
3. When a block of code is complex and would make the main logic of the program more difficult to understand if it were included inline, it's also a good idea to extract that code into a helper function.

On the other hand, it's harmful to use helper functions when:

1. When a helper function is so small and simple that it doesn't add much value in terms of readability and maintainability.
2. When a helper function is used in only one place, it might be better to simply include the code inline.
3. When the purpose of a helper function is not clearly defined or its behavior is not immediately obvious from its name, it can make the code harder to understand.

In general, the goal of using helper functions should be to make code more readable, maintainable, and reusable. If a helper function doesn't achieve these goals, it may not be worth the added complexity that it introduces into the codebase.

Ruggan
Feb 20, 2007
WHAT THAT SMELL LIKE?!


Anyone want to buy my software development book written completely by ChatGPT?

thotsky
Jun 7, 2005

hot to trot
I have definitely read worse.

Xarn
Jun 26, 2015
Function-local helpers are great even when called in one place only, because you can give them a semantic name.

Mega Comrade
Apr 22, 2004

Listen buddy, we all got problems!
So my company is switching to "Shapeup" . Anyone got any experience with this, I've read the shapeup doc on it. And mostly seems sensible although I have concerns about this company actually sticking to some of the principles, mainly not pulling Devs of work cos some minor bug has been reported by a customer with a lot of clout.

Adbot
ADBOT LOVES YOU

Nybble
Jun 28, 2008

praise chuck, raise heck
I figured most people would have bailed from that idea after the writer’s conservative views caused a huge blowup at Basecamp, and then DHH went even farther than Ryan did in public. caused plenty of consternation in the Rails community and placed plenty of doubt whether any of their management books are actually good or were followed internally

https://www.theverge.com/2021/5/3/22418208/basecamp-all-hands-meeting-employee-resignations-buyouts-implosion

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply