this post was submitted on 28 Jul 2024
1306 points (99.0% liked)

Programmer Humor

23848 readers
2613 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] Alexstarfire@lemmy.world 1 points 10 months ago
[–] JimVanDeventer@lemmy.world 10 points 10 months ago (1 children)

Don't threaten me with a good time.

[–] zbyte64@awful.systems 2 points 10 months ago

Python Black for Java. Just a thought....

[–] kamen@lemmy.world 10 points 10 months ago

What amazes me is that someone either did that manually or wrote a formatter to do that - I doubt that any standard style config would do this.

[–] OhStopYellingAtMe@lemmy.world 20 points 10 months ago

Damn. That’s tidy to the point of inconvenience.

[–] MystikIncarnate@lemmy.ca 17 points 10 months ago (1 children)

I'm not a coder, and.... Well... Thanks, I hate it.

Even I know this is horrific. Where the fuck does this statement end? Which of these brackets refer to this section of other brackets. Idfk.

I could give a shit less if it was just for a single block per or something but ";}}}" hurts me.

[–] velvetThunder@lemmy.zip 15 points 10 months ago (1 children)

Well the code indentation explains that, like python. The issue is not reading it. You would rather quit your job than edit this.

[–] hglman@lemmy.ml 4 points 10 months ago

tooling would have to do it all after the fact or something

[–] demizerone@lemmy.world 15 points 10 months ago (2 children)

Auto formatter as part of the expected language tooling is Go's greatest move, even if their formatter doesn't go far enough.

[–] JackbyDev@programming.dev 2 points 10 months ago

But I want my bike shed blue...

[–] PlexSheep@infosec.pub 4 points 10 months ago

Rust does this too I think (or just everyone uses rustfmt).

[–] Reddfugee42@lemmy.world -2 points 10 months ago
[–] Hack3900@lemy.lol 34 points 10 months ago (3 children)
[–] bss03@infosec.pub 4 points 10 months ago (1 children)

Might check out the Haskell layout rules.

Basically, when you leave out the '{' then Haskell uses your intendation to insert ';}' on later lines between the leading whitespace and the first token.

There some really old Haskell code out there that lines up the '{;}' characters on the left under block-introduction keywords.

[–] barsoap@lemm.ee 4 points 10 months ago

It's not just old Haskell code that's how you write Haskell if you want explicit braces. Well, mostly generate, but it's still the idiomatic formatting (and when you generate you always generate braces because it's easy to get layout subtly wrong when generating).

Haskell also does the whole

data Foo = Bar
         | Baz
         | Quux

foo = [ Bar
      , Baz
      , Quux
      ]

thing, makes sense to apply it to braces especially as they're seen only very rarely. Single-line, yes, but not multi-line.

[–] VonReposti@feddit.dk 12 points 10 months ago* (last edited 10 months ago) (2 children)

I think you'll like Ruby. It has mostly done away with braces and code blocks end with end, e.g.

def create
  unless admin redirect_to new_session_path and return
  
  @product = Product.new product_params

  if @product.save
    flash[:success] = "New product has been created!"
    redirect_to edit_product_path(@product) and return
  else
    flash[:error] = "Something went wrong!
    render :new
  end
end

This is working code that I simplified a bit from an old project of mine.

[–] barsoap@lemm.ee 2 points 10 months ago* (last edited 10 months ago)

That's just Algol instead of B. Most languages use the one or the other, then there's sexpr-based languages (lisp, scheme), lua (technically Algol but not needing semicolons while also not needing newlines so it's definitely special), and layout syntax (Haskell, or, if you want a bad implementation, python).

[–] olafurp@lemmy.world 12 points 10 months ago (2 children)

Ruby syntax is nice although I prefer python way of enforcing indentation instead of adding "end"s. Personally I just want a statically typed language with enforced indent as syntax.

[–] JackbyDev@programming.dev 1 points 10 months ago

Just add a linter to your build lol. Now if it's indented wrong it breaks!

[–] VonReposti@feddit.dk 7 points 10 months ago (2 children)

Funny, the forced indentation is what I hate about Python. If you think a missing semicolon can be hard to catch, don't ever think about a missing whitespace :p

The end keyword really isn't a big deal for me. I find it to be a good way to easily spot the end of a method. But if you wouldn't like it I'd still find it a good compromise to avoid syntax issues due to whitespace.

[–] JackbyDev@programming.dev 4 points 10 months ago

} helps me easily spot the end of stuff. end just blends into the statements.

[–] hglman@lemmy.ml 5 points 10 months ago (1 children)

i can count on one hand how many times ive had white space issues in 15 years of using python. its just not an issue

[–] 0ops@lemm.ee 3 points 10 months ago

Same and agreed, especially if you keep your functions small and focused as you should. 3-5 indents is nbd to keep track of, and if you need more than that... No you don't, refactor.

I've had way more hangups with brackets then indentation, personally, not that either is a super frequent issue, but I'm indenting anyway, so brackets are redundant and just another thing I have to keep track of

[–] olafurp@lemmy.world 11 points 10 months ago

Who's going to write the extension so that they are all hidden and automatically inserted?

load more comments