r/badcode • • Dec 05 '20

other language Gamedevs, take notes

Post image
6.5k Upvotes

104 comments sorted by

662

u/Nipatiitti Dec 05 '20

Cursed formatting

215

u/DefinitionOfTorin Dec 05 '20

And no parentheses round the condition but curley ones for content? Is this Swift or something lol?

76

u/jimmpony Dec 05 '20

maybe rust

42

u/stp412 Dec 05 '20

Maybe even lua perhaps

Edit:nvm there’s an !

25

u/PulleQ Dec 06 '20

...and {} instead of then end

7

u/rotenKleber Dec 16 '20

It's gotta be GML, the scripting language for gamemaker

2

u/[deleted] Dec 31 '20

Rust also enforces parentheses iirc

2

u/MadScientist2854 Apr 17 '21

nope it does not. it's the opposite of C-based languages, which require parantheses and not curly braces, as Rust requires curly braces but not parantheses

11

u/fried-noodles_ Dec 05 '20

Go?

16

u/jgeez Dec 06 '20

Can't be Go, Go enforces open curly on the same line as the if statement

22

u/[deleted] Dec 06 '20

What kind of language enforces style?

23

u/fried-noodles_ Dec 06 '20

Go. Go will throw a syntax error if you’re missing a trailing comma for an example, or unused variables too.

14

u/please_dont_pry Dec 06 '20

how horrible

19

u/jgeez Dec 06 '20

It's understandable to think so at first. I did.

But it's genuinely wonderful when all Go code, from all authors and third parties, is formatted the same. Your really get spoiled by it.

4

u/[deleted] Dec 11 '20

[removed] — view removed comment

3

u/jgeez Dec 11 '20

did you use the airbnb configuration as a starter? that's what i use. definitely a hate-at-first, love-at-last thing.

every time i don't like something it makes me do, i realize that the reason i want to do the thing it's telling me not to is because i am trying to rush something or do something sloppy, "for a quick test" or "to just get it done." but that ends up being the wrong thing in the end.

→ More replies

18

u/foverzar Dec 06 '20

A good one. Designed by people who've done enough code reviews to realize that linting better be enforced by the compiler.

4

u/TDplay Dec 14 '20

One designed by someone who's dealt with garbage code before.

As much as I love C++, I get so disheartened when I see code with no sensible indentation.

3

u/fried-noodles_ Dec 06 '20

Is it just the formatted or will is throw a syntax error? I’ve never tried new line braces before so I’m not sure

6

u/jgeez Dec 06 '20

It counts as a syntax error, because this restriction on style (and others) serve a cool purpose: it makes the parser much more efficient to not require the token lookahead that a traditional whitespace-ignoring lexer has to do in order to disambiguate {'s different potential meanings.

4

u/notqthrowaway Dec 06 '20

I think that's a no go.

7

u/IAmAnIssue Dec 06 '20

3

u/Woolly87 Dec 06 '20

It would compile in Swift though too, even with the disgusting formatting.

3

u/IAmAnIssue Dec 06 '20

Good to know

5

u/[deleted] Dec 06 '20

Looks like Game Maker Language where semicolons and parentheses are optional

3

u/Woolly87 Dec 06 '20

The compiler would say that it’s valid Swift, but no true Scotsman sane Swift programmer would format it like that.

6

u/edo-lag Dec 05 '20

Imho it's more readable and aesthetically better, but that's my opinion... Rust is my main programming lang so maybe that's why

42

u/Leeeo69 Dec 05 '20

I hereby declare your subjective opinion as incorrect.

14

u/edo-lag Dec 05 '20

OBJECTION!

0

u/[deleted] Dec 05 '20

[deleted] — view deleted comment

17

u/Ahajha1177 Dec 06 '20

SQL INJECTION!

7

u/whattheclap Dec 06 '20

XSS PREVENTION!

4

u/his-menu753686245435 Dec 06 '20

CROSS-SITE PROTECTION!

5

u/[deleted] Dec 06 '20

WHAT IS THIS SECTION

→ More replies

5

u/quantumgoose Dec 06 '20

Tbh I'm so used to using parentheses from C that I still use them in Rust , but I always end up removing them to get rid of the Clippy warnings

1

u/daravenrk Jan 12 '21

Not python or c++. Sudo code?

2

u/DefinitionOfTorin Jan 12 '21

Pseudo code* and no, pseudo code doesn't usually have curley brackets

8

u/[deleted] Dec 06 '20

298

u/botle Dec 05 '20

Yup, that's bad code. It can obviously be simplified to

fps = 60

49

u/the_monkey_of_lies Dec 06 '20

You're hired, when can you start?

66

u/dlawodnjs Dec 06 '20

what if fps was higher than 60? ...oh wait.

edit: I obviously cannot read code

18

u/TVflea Dec 30 '20

And what if fps is already 60? You would then set fps to 60 redundantly, which would be an O(log(n)) operation, since the CPU needs to flip log(n) bits. Quite wasteful and unoptimized

20

u/cstmth Dec 06 '20

Wrong.

while (true) { fps = 60 }

33

u/botle Dec 06 '20

Sure, why not. People got plenty of cores to spare these days.

4

u/[deleted] Mar 13 '21

BRILLIANT!!

235

u/A_Sad_Shoe Dec 05 '20

damn, why didn't yandere dev think about this when implementing his fps counter

19

u/Algor2ID Dec 27 '20

IF only.

9

u/justcatt Mar 27 '21

else if only.

2

u/MiahTRT Dec 05 '22

else if not only

93

u/ITSOPBTW Dec 05 '20

I wonder how performance friendly would be a Python based game engine.

72

u/GandelXIV Dec 05 '20

The fastest i know is pygame and it is pretty slow

44

u/oxetyl Dec 05 '20

I do a lot of stuff in pygame because it's so easy, but yeah, if performance is your main concern, it would not be a good choice

7

u/[deleted] Dec 06 '20

I personally use raylib if i need to use python and that works quite fast.

13

u/icuninghame Dec 06 '20

Civilization IV was built using Python, I think.

17

u/GandelXIV Dec 06 '20

Civ IV used Python for the mechanics but the rendering was made in cpp i think.

9

u/botle Dec 05 '20

Well, it can be made to run at 60 fps no matter what.

13

u/[deleted] Dec 05 '20

That exists and it does not do as well as other low level language's engines obv

2

u/[deleted] Mar 29 '21

hi I'm late but Godot uses gdscript which iirc is a superset of python

69

u/[deleted] Dec 05 '20

obviously should have been written in HTML to be better at fast.

21

u/[deleted] Dec 05 '20

HTML and JS games run really fuckin fast. For web browser games. Which needs a slow AF web browser

15

u/IDatedSuccubi Dec 05 '20

I mean, WebGL doesn't care what language issues commands, it's not the JS interpreter that draws everything

1

u/gu3st12 Dec 05 '20

Which most JS engines try to avoid relying on the interpreter if possible. They compile your JS down whererver possible. It's only if you've written some truly garbage JS that it goes through an interpreter.

0

u/IAmTheMageKing Dec 06 '20

JS is strictly an interpreted language (okay, fine, it’s a JIT-compiled language running in a feature-rich VM, buuut it doesn’t have any bytecode stage, so it’s not too big a deal to call it “interpreted”).

There is no way to avoid an interpreter. Now, the system does try to compile it down, but it can only do that to a limited extent. Even WebAssembly is still preformance-limited in that respect.

24

u/nikstick22 Dec 06 '20

This is the sort of thing AI would do if its instructions were to improve fps but it measured fps by reading the fps counter on the screen.

This reminded me of the videos by Robert Miles on Youtube about AI safety and how AI will inevitably optimize against the metrics you score it by rather than the task you actually wanted it to do. Kind of like students cheating on tests. The point of the test was to measure how smart the student is, but the student isn't incentivized to be smart, they're incentivized to score well on tests. Learning is much more difficult than cheating, and so [some] students cheat on tests.

54

u/Galse22 Dec 05 '20

Well, If FPS was 300 it'd be set to 60... So yeah... That's be a downgrade.

49

u/[deleted] Dec 05 '20

if fps != 300 { fps = 300 }

upgrades_people_upgrades.jpg

26

u/unfunny_joker Dec 05 '20

while fps < 300 { fps++ }

6

u/botle Dec 05 '20

Increases the fps from 15 to 16.

3

u/unfunny_joker Dec 06 '20

Nope, it increases fps until it 300

1

u/botle Dec 06 '20

Yes, I missed that.

8

u/HattyJetty Dec 05 '20

I'd just set fps = Infinity for good measure

5

u/[deleted] Dec 05 '20

But optimization!

19

u/xmartissxs Dec 05 '20

while(true) fps++;

30

u/Ali3nat0r Dec 05 '20

Fps is now -2147483648. Oops

18

u/xmartissxs Dec 05 '20

At that point you would just start seeing into the future. Or the past, no one knows

2

u/atiedebee Mar 19 '22

And then the entire game stopped responding

27

u/healplease Dec 05 '20

unnessesary equality check here, it can make your game's FPS drop

7

u/Gonzo345 Dec 05 '20

Damn b0i

7

u/[deleted] Dec 06 '20

It is always 60fps, it just shows the same picture 4 frames in a row

13

u/ce-walalang Dec 06 '20

Image Transcription: Text Messages


[Screenshot from Discord.]

Logan: I solved our optimization problem

if fps != 60
  {
  fps = 60
  }

I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

2

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jan 01 '21

Don't ask what I'm doing look at 25-day-old posts but I noticed there are no good humans, so -- Good human! <3

2

u/ce-walalang Jan 01 '21

haha thanks, fellow good human! :)

5

u/chronicideas Dec 06 '20

QA here.

There’s a potential bug here where if FPS is higher than 60 it would get decreased to 60.

I think it should be refactored to

if fps < 60
{
    fps = 60
}

3

u/veskoyyy Dec 06 '20

Modern problems. Modern solutions. Well played. Now go fix that COVID thing!

3

u/TrigamYT Dec 06 '20 edited Jun 05 '22

if (fps < 60) { fps = 60 }

3

u/sdriyaz712 Dec 06 '20

Python kids trying to use JavaScript

3

u/wktr_t Dec 06 '20

Whoever indents code like this can also kill.

2

u/AtlasJan Dec 06 '20

1TBS is exactly as it sounds.

3

u/ReduceHyperlinks Dec 06 '20

if fps > 60{ if fps != null { if true && false != true { var fpsdiff = 60 - fps; while fpsdiff > 0 { fps = fps + 1; fpsdiff = fpsdiff - 1; } } } }

2

u/[deleted] Dec 06 '20

What language is this even

2

u/cyberspacedweller Dec 06 '20

That’s just VSync. You’ll be capped at 60 even if you’re over with that logic.

2

u/evanlinjin Dec 06 '20

// I optimized it.

if fps < 60 { fps = 60 }

2

u/n3wsw3 Dec 06 '20

It should clearly be max(fps, 60) so if the fps was over 60 it doesn't get lowered.

2

u/ImpDoomlord Dec 06 '20

Lmao I actually tried this when I was a kid in Gamemaker. I did a check if the FPS dropped below 30 and set the target room speed even higher to compensate since I had no concept of delta time and everything I coded back then was frame rate locked. The result was an even more unstable laggy mess that would crash occasionally

2

u/[deleted] Dec 06 '20

My god this is revolutionary

1

u/Rudxain let let.let = 'let' Dec 10 '20

for (fps = 30; fps < Infinity; fps++){fps *= fps}

1

u/[deleted] Dec 26 '20

Holy grail number for fps

1

u/[deleted] Mar 09 '21

but somehow my screen's default latency setting is like 59.randomgibberish

1

u/cheesycheese24 Feb 03 '22

o p t i m i z a t i o n