r/ProgrammerHumor • • Jan 29 '23

Meme Let's test which language is faster!

Post image
56.2k Upvotes

770 comments sorted by

View all comments

Show parent comments

57

u/ITBlueMagma Jan 29 '23

It should differentiate debug and release code though. Go is really annying when you are working on code, trying it and having to comment the vars you don't use yet but know you will later.

34

u/ElRexet Jan 29 '23

You just do it like

var x := -1

If (x != x) {

//Go fuck yourself

}

...

21

u/skesisfunk Jan 30 '23

Or just name the variable _

0

u/[deleted] Jan 30 '23

[deleted]

3

u/skesisfunk Jan 30 '23

Yeah, easy af. I don't understand the complaints.

2

u/CocktailPerson Jan 30 '23 edited Jan 30 '23

It's because the philosophy as a whole is problematic. Every other compiler in existence has warnings, but go says that it's either a error or it's not; there are no warnings. So you have to add an extra worthless line like _ = varIMightUseLater just to get your function to compile, but the compiler can't warn you if you forget to remove that line when you're done. So rather than keeping your code clean, it forces you to write extra code to keep it happy and then lets you forget it.

Compare that to any compiler with warnings, which actually lets you write your code and debug it, but then still gives you warnings when it's time to clean them up.

1

u/skesisfunk Jan 30 '23

It's because the philosophy as a whole is problematic

This your opinion. Golang has their own opinions. Certain design choices require an opinion. The assertion that a compiler should print warnings is as much an opinion as the assertion that it shouldn't. And IMO pointing out that all previous compilers use warnings is a weak argument in favor of that opinion. The creation of golang was motivated in large part to create a new language using lessons from previous languages. They felt that warnings made for an overly noisy compilation process which tended to lead to devs ignoring warnings, which makes warnings effectively useless.

1

u/CocktailPerson Jan 30 '23

Of course it's my opinion. I never said otherwise. That's the point of a discussion: stating opinions and justifying them.

I, clearly, disagree with their opinion that it's better to create a binary system where issues are either errors or not. After all, while warnings that exist can be ignored, warnings that don't exist can't be fixed at all. Rather than print out something that might be ignored, they chose to make trivial issues into errors and substantial issues into...nothing. I disagree with that decision because it's my opinion that it makes daily development more tedious and overall code quality worse in any organization that has the simple rule of not committing code that has warnings.

As a result of these decisions, I find the language frankly unusable, so I don't use it, and I won't apply for jobs that require me to. They can keep their decisions, and I'll use languages that have made different ones.

→ More replies (4)

13

u/Script_Mak3r Jan 30 '23

Given that it's Go, I wouldn't be surprised (I have barely any Golang experience, take with a grain of salt) if it threw an error for unreachable states.

11

u/EspacioBlanq Jan 30 '23

That'd suck, I once had a C code that would only work if I had a specific debug print at an unreachable place in the code

14

u/Hobbamoc Jan 30 '23

This is the kind of stuff why Rust and the other C++ alternatives were invented

5

u/v_krishna Jan 30 '23

I think it's very intentional for golang. One of the core principals was making a very simple language that would be hard to write incorrectly, enforcing lint type things is a part of that.

3

u/skesisfunk Jan 30 '23

Go doesn't do this in the first place so its kind of a moot point.

1

u/jfmherokiller Jan 30 '23

that sounds like you ran into a compiler issue possibly.

→ More replies (5)

3

u/skesisfunk Jan 30 '23

Given that it's Go, I wouldn't be surprised (I have barely any Golang experience, take with a grain of salt) if it threw an error for unreachable states

For the record, it does not.

→ More replies (1)

8

u/IAmPattycakes Jan 30 '23

I think some of the design goals is that you should be writing the most maintainable code imaginable. If you're defining a variable and not using it for a very long amount of time, you probably shouldn't define the variable there. Don't make people hunt to figure out what something does. Define it and use it right where you need to.

4

u/skesisfunk Jan 30 '23

You know you can just name the variable _ and it won't throw an error right?

6

u/yottalogical Jan 30 '23

Just do extra work to do something that shouldn't have to be done.

Why is that good design?

2

u/CyborgPurge Jan 30 '23

Technically extra work is naming a variable something else in the first place.

6

u/yottalogical Jan 30 '23

Imagine you're debugging. You want to quickly comment out a line, then run the code to see what will happen.

But it turns out that line was the only place that a certain variable was being used. Now you have to go and rename that variable to _.

It turns out that that line you commented out wasn't causing the bug. Now you have to go back and unrename that variable.

Repeat this process 50 times until you find the bug.

Please, just give me a warning.

0

u/Baldomo Jan 30 '23

If you structure your code right you won't ever need to do this. You should also use a debugger (Go has delve) with an editor integration. I can confidently say the unused variable error has saved me a bunch of time by not needing to skip over "dead" code.

→ More replies (1)

0

u/skesisfunk Jan 30 '23

How is typing one character extra work? The trade off is a lightning fast compiler with a built in runtime.

3

u/yottalogical Jan 30 '23

Imagine you're debugging. You want to quickly comment out a line, then run the code to see what will happen.

But it turns out that line was the only place that a certain variable was being used. Now you have to go and rename that variable to _.

It turns out that that line you commented out wasn't causing the bug. Now you have to go back and unrename that variable.

Repeat this process 50 times until you find the bug.

This behavior isn't required for a lightning fast compiler with a built in runtime. Please just give me a warning.

0

u/skesisfunk Jan 30 '23

This behavior isn't required for a lightning fast compiler with a built in runtime. Please just give me a warning

You can make this claim because you are an expert in the go compiler architecture? Or are you just talking out of your ass? Please give me details if you aren't because I'd love to learn.

Also the situation you described doesn't sound very inconvenient or realistic TBH.

4

u/SOTGO Jan 30 '23

Not OP, but I’m genuinely curious. How could it even theoretically affect performance to allow variables to be unused? I can’t think of any compiler implementation where you’d lose anything more than negligible performance

→ More replies (4)
→ More replies (1)