this post was submitted on 01 Mar 2024
371 points (93.4% liked)

Programmer Humor

31260 readers
533 users here now

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

Rules:

founded 4 years ago
MODERATORS
 
all 46 comments
sorted by: hot top controversial new old
[–] [email protected] 107 points 4 months ago* (last edited 4 months ago) (1 children)

for a second I thought I read

publ;c

[–] FooBarrington 26 points 4 months ago

Nah, it's actually publ;c

[–] [email protected] 62 points 4 months ago (2 children)

This is why I spend a good amount of time setting up linters on new repos before even starting to make the application. It saves a ton of time in peer reviews because no one has to think about formatting. Some people may not like the rules chosen but official direction from the boss is "get over it". There are 0 comments on PRs about formatting which only ever annoys people and is a waste of good dev time.

[–] waz 18 points 4 months ago

On my current team, when we were trying to choose a style, my only input was "any style that can be checked/applied with a git commit hook."

I get some people prefer reading code in a particular format. Let them configure their editor to apply it, but let's keep the version history in one unavoidably consistent style. Pretty please.

[–] [email protected] 26 points 4 months ago* (last edited 4 months ago) (3 children)

I felt that. I have a colleague whose coding style is different to mine and whenever they work on code that I originally wrote, I have to resist the temptation to modify things to camelCase.

[–] mesamunefire 45 points 4 months ago (1 children)

Linters make these kind of things easier. Then you get mad at the tool rather than your coworker.

[–] [email protected] 10 points 4 months ago (1 children)

Does Prettier count as a linter?

I always thought linters were more to find bad practice and possible errors than control the code style

[–] [email protected] 14 points 4 months ago (2 children)

Some linters can do both. Getting one set up as an automated job whenever code is pushed to the repo is on my TODO list...

[–] mesamunefire 4 points 4 months ago

Yep all my public repos have it on a ci job. When you have a library that is used on many different projects, I want to be able to read the prs.

[–] [email protected] 3 points 4 months ago (1 children)

That does sound nice to me too. I've found prettier with format on save works pretty well but that means you have to set it up in every editor

[–] RustyNova 8 points 4 months ago (1 children)

Format on save is a godsend. Copy paste something with whole indentation? Ctrl-s, it's back to normal. Did some wacky nested anonymous function calls? Ctrl-s, and they're laid out nicely.

[–] [email protected] 2 points 4 months ago (1 children)

I honestly almost golf my code nowadays and just let the tooling fix formatting for me. The space bar and enter key are in an ideal world vestigial for the purposes of programming.

[–] RustyNova 1 points 4 months ago

I'll always say that the best code editor is the one that makes you put your idea onto a file the fastest.

So yeah, you shouldn't worry about style and code lint. You should worry if your code is sound and works. Keep your mind on the logic, not the extras

[–] [email protected] 14 points 4 months ago (1 children)

It's interesting that something this minor gets people so upset. I mean, I get it, but objectively it's weird of us.

I had a debate years ago about test naming. When I was a junior, the lead dev used test methods with an underscore separating different cases. Like testServiceConnector_success(). I thought that's pretty neat and kept that style. In another project one of the devs almost had a meltdown because I dared introducing underscore scum into "his" project.

[–] [email protected] 1 points 4 months ago* (last edited 4 months ago)

I think it's just that we're possessive/protective of "our" code, even more so if one is passionate about programming. We've put a lot of effort into it, then somebody else comes along and "ruins" our "perfect" (to our eyes) formatting/styling!

[–] [email protected] 8 points 4 months ago (1 children)

Last year I had a module for ai stuff. We did things in Python and I am quite into doing things as coding standards say. My mate didn't really care so much and just went for his style of doing things, also not really worrying about descriptive names etc.

Well, let's say, we weren't having a good time.

I also realized that I was probably too harsh and tried to go a bit more easy on it later, but many things just felt wrong.

[–] [email protected] 9 points 4 months ago (1 children)

Add black, isort and flake 8 to your repo, you can set it up to be applied on commit.

So folks can modify their local config all they like, and when they push it's to the team standard and when they work locally it's to theirs. It's the best.

[–] [email protected] 3 points 4 months ago

What about Ruff? I've been having a great time with Ruff.

[–] RustyNova 19 points 4 months ago

I work on a proprietary language that translates everything to uppercase before compiling. So having a specific case is useless. The standard functions all have wacky cases. Some from the same module may use CamelCase, while it's brother use snake_case.

... I just use Rust's style. Simple, easy.

[–] Deckweiss 17 points 4 months ago (3 children)
[–] RustyNova 37 points 4 months ago (3 children)

Classes often have camelCase or PascalCase. Snake cases often are for variables or functions.

I don't remember the java standards, but it's enough to get it

[–] marcos 9 points 4 months ago (1 children)

The Java standard is ClassName, variableName, FINAL_VALUE_NAME.

It's derived from a popular C++ standard. (But C++ has many for you to pick.)

Python is the one that likes snake_case, but it's for variables, as you said. Classes are still PascalCase.

[–] RustyNova 2 points 4 months ago

Rust is like Python, but actually tell you the rules instead of you doing whatever you want

[–] bassomitron 5 points 4 months ago* (last edited 4 months ago) (1 children)

In college and workplace, all java projects I ever worked with used camelCase. Whether that's the official stance of Java or not, I don't recall.

[–] [email protected] 8 points 4 months ago* (last edited 4 months ago) (1 children)

But also classes? In Java, I normally see camelcase (objects, variables, functions, ...) except for class definitions, which are PascalCase.
The package itself often is snakecase though iirc?

[–] [email protected] 2 points 4 months ago (1 children)

That's exactly how I was taught Java styling in college. Idk if it was official styling or just professor preference though.

[–] [email protected] 1 points 4 months ago

Same I was taught. Think it's official. Professor was a stickler for following official rules so I doubt he would deviate.

[–] CosmicCleric 3 points 4 months ago (1 children)

When you're telling a joke to a bunch of computer programmer nerds, you got to tell them what programming language the joke is in, or else it just falls flat.

[–] RustyNova 1 points 4 months ago

Always type the name of the language after opening your joke block. If your language is known enough, you may have syntax highlighting as well!

[–] [email protected] -1 points 4 months ago (1 children)

So this looks like it's based in Java code.

A public class means that any bit of Java code, including that injected by an attacker, can see and mess with the contents of that class.

A private class, in contrast, means that other bits of Java code are restricted to running the class's predefined functions.

In theory it is supposed to help with the security of the data. In practice if an attacker gets to this point, you've got much bigger issues.

[–] [email protected] 5 points 4 months ago* (last edited 4 months ago)

Private Vs public has nothing to do with security

If people can execute arbitrary code in your app, they can already read your memory, and even if they couldn't they could use java reflection to just turn off the private modifier

Accessibility modifiers are to do with maintainability. If you have internal implementation logic that should be hidden from a consumer you don't want that consumer to have to know about things they shouldn't be changing anyway.

The comic is just about how classnames in java should be in pascal case

[–] jroid8 13 points 4 months ago (3 children)
[–] [email protected] 14 points 4 months ago

I think Rust actually is actually among the best in this regard for the simple reason that there is consistency given by the compiler. A simple cargo fmt and cargo build will fix or warn you about everything. I can read into Rust codebases so quickly. C++ was always really exhausting because most of the time you were just getting used to the code style.

[–] RustyNova 9 points 4 months ago (2 children)
[–] [email protected] 5 points 4 months ago (1 children)

I've found whenever people complain about rust code they can only point out how it's different but not why it's worse and I can usually point to a reason why it's better.

to be fair, I get sometimes it's difficult to pinpoint why something is bad and even "being different" can be a legitimate criticism on its own

[–] hansl 0 points 4 months ago

People who learnt structural OOP without actually understanding typing system and their benefits really struggle with learning Rist as they try to map classes onto structs and it just doesn’t work.

Traits are not inheritance. Box is not polymorphism. Rust is not C++ with more keywords.

[–] jroid8 1 points 4 months ago (1 children)

It IS fine, I though the comic was referring snake_case as disgusting. I was uncomfortable too at first but I got used to it

[–] [email protected] 2 points 2 months ago

I used to be a PascalCase guy myself, but that changed recently when I had to use React (coming from embbeded C)

I am working with a C embedded framework that uses snake_case, and switching between the two, I realized that it is a lot easier to find information with snake_case for me.

[–] [email protected] 8 points 4 months ago (1 children)

I don't get why every language seems to have its own coding style when you'd think they'd be completely interchangeable depending on user/org/project maintainer preference

[–] RustyNova 20 points 4 months ago

Having a standardized codding styles allows people to immediately recognise things, and not have a wacky case mix.

You don't need to remember the coding style of one specific project. You just need to remember the style of the language

Of course it would be better if it was standardized for every language, but that's probably never going to happen

[–] [email protected] 1 points 2 months ago

Wait, is this implying the software devs are hard coding all of the customer data? 🤮

[–] [email protected] 0 points 4 months ago

What is the freakout?!?!?!?!?!?!?!? Maybe i want to read other people's code in a wacky comic-looking silly goofy totally awesome monospaced font!?!?!?!