r/badcode • • Sep 01 '20

other language the most efficient "cast"

Post image
753 Upvotes

26 comments sorted by

218

u/notger Sep 01 '20

Hope this guy got banned.

I will not even criticise this code, I will instead assume the guy wanted to troll someone or make a joke.

102

u/[deleted] Sep 01 '20 edited Sep 01 '20

Horrifyingly enough this seems to be the first result for "float to int pascal" on google :o

And the other answers aren't that great, so I get the feeling a lot of amateurs will end up seeing this as the simplest solution. Seriously, the other answers to the question, the first result on google, are all long-winded and complicated ways to complete a simple cast - which according to some digging from me (who doesn't know pascal) can be completed with Int(the float value) in pascal...

23

u/new2bay Sep 01 '20

Wow. On top of being spectacularly inefficient, this also manages to be wrong, unless you can guarantee nReg and nTPages are of opposite parity.

19

u/JuliusCCHD Sep 01 '20

What now?

58

u/gir2195 Sep 01 '20

I wouldn't trust them. They can't use "then/than" properly

30

u/-Dueck- Sep 01 '20

"e convert to int number"

That resembles English in some ways I guess.

4

u/memeticmachine Sep 01 '20

what decimal precision do they set for e?

2

u/joaoprp Sep 02 '20

This “e” is 100% Portuguese. It’s basically how we say “and”, and I don’t even realized until I read this comment.

60

u/Kilgaloon Sep 01 '20

Why not turn it into hex then binary, then use polymorpism to summon exodia?

17

u/NebbyOutOfTheBag Sep 01 '20

You meme. But I have the technology to cast keys into hex and binary and probably back, and pull from a Yu-Gi-Oh database. Don't tempt me

3

u/[deleted] Sep 02 '20

Seto Kaiba appeared out of nowhere! Throws Exodia cards into the ocean! Sanity harshly fell!

29

u/brjukva Sep 02 '20

I once inherited some code where every argument to every function was string typed. Every function call involved converting arguments to string. The first thing every function would do is parse its string arguments back to their appropriate types.

I reached peak wtf per minute rate that day.

6

u/[deleted] Sep 02 '20

...what language?

10

u/brjukva Sep 02 '20

C#

6

u/[deleted] Sep 02 '20

This was to uh, serialize, right?

Do you happen to know why?

7

u/brjukva Sep 02 '20

It looks like the person who wrote this was a big fan of serialisation.

Dunno, I don't see any other explanation.

2

u/Raknarg Sep 02 '20

Its the void* of C#, now you can take in anything

6

u/tangerinelion Sep 01 '20

They're not wrong. You *can* do that.

The question of *should* you is separate.

8

u/shriekingpanda Sep 01 '20

I work with a legacy code base that does all kinds of horrible things converting numbers back and forth to strings, so this is especially painful to me.

20

u/pete_moss Sep 01 '20

Ah, classic stringly typed programming.

1

u/ikatono Sep 02 '20

I have a snippet I've been meaning to post that uses 2.0n instead of 1<<n. I'd honestly prefer strings.

3

u/[deleted] Sep 01 '20

is this V?

5

u/witti534 Sep 02 '20

Looks like Pascal

2

u/Mrinin Sep 01 '20

is he trying to round a float to an integer or something? what's the goal here can someone explain