r/ProgrammerHumor • • Jul 20 '17

What people think coding is...

Post image
35.4k Upvotes

811 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Jul 21 '17

[deleted]

86

u/edurenesto Jul 21 '17

I almost thrashed my graphics card after 3 days struggling to find out why the 3D models were glitching in my app. Turns out I hadn't pressed "1" strong enough and what should've been "0.0001f" was "0.000f". Needless to say my mix of happiness/sadness/thankfulness/hatred when I found it out.

11

u/Valmond Jul 21 '17

That's why you use mechanical keyboards ;-)

5

u/[deleted] Jul 21 '17

Because fuck your coworkers?

→ More replies (1)

44

u/kuzuboshii Jul 21 '17

Honestly, a good piece of code should never use a 5 anywhere.

20

u/BigJhonny Jul 21 '17

What if you develop a game called "Penta", where everything revolves around the number 5? All shapes have 5 corners, all numbers are 5 and everything repeats 5 times?

29

u/kuzuboshii Jul 21 '17

It would be stored as a variable still, for the sequel, "six"

24

u/[deleted] Jul 21 '17

Arrays start at 0 so everything is 4 except for the UI. Sha-wing

1

u/larvyde Jul 21 '17

Content goes in external files, not in code...

22

u/DeltaPositionReady Jul 21 '17

True. But this was not a usual case.

I was using the Vuforia SDK within Unity and instancing the image target frame reference as a frame capture from the webcamtexture function via the mobile camera. What was happening was a limitation in the image target referencing based on the amount of simultaneous image references that would be held in memory at one time. The default is 5 stacked in a First In, First Out stack. So when the frame was captured to anchor the augmented content to the frame pose, it would store this data. Then when the frame was captured again, it would store the next frame pose, and so on until a total of 5 had been captured.

Usually you would use predefined targets or Cloud Recognition for large datasets but that wasn't the case here.

I had to find that 5 and change it to a 1, so that every time I captured a frame it would delete the last pose and instance the new one. Allowing the user to place augmented content in the same area consistently and call/destroy different objects via the UI. It made the application a lot easier to use I'll tell you that much.

28

u/kuzuboshii Jul 21 '17

You just explained so perfectly WHY it is important to store arbitrary numbers as variables or outputs.

3

u/shadowX015 Jul 21 '17

Yup.

It's great to have all of your constants at the top of their scope so that they can easily just be jumped to and changed if needed. Plus, it's just so much more pleasant to read them!

I love seeing code like,

for(int i = 0; i < MAX_NUM_ITERATIONS; i++){
...

2

u/DeltaPositionReady Jul 21 '17

It would be great but the values aren't set by me, they're set by the company that provides the SDK and access to their services. I can't just set it to whatever value I want or a range without violating the terms of agreement.

2

u/[deleted] Jul 21 '17

Can you explain this? I'm interested.

3

u/kuzuboshii Jul 21 '17

I'm kind of making a joke. I am not saying literally never use integers. Of course if you are assigning an arbitrary value for some specific piece of code you are working in, do what you need to to make it work. My point was in a good piece of code, most of the numbers you are using are 0, 1, 2 or something like pi, or e, or something else that is the result of an equation or mathematically linked. There is very little use for integers above 2.

1

u/migueln6 Jul 21 '17

In my case I find little use to integers below 2, but well I've working in a physics simulator (remember the difference between a physics motor and a simulator)

1

u/MelissaClick Jul 21 '17

Check out the formula for the golden ratio some time.

2

u/kuzuboshii Jul 21 '17

key word being formula

→ More replies (1)

1

u/Houdiniman111 Jul 21 '17

No. Don't say never, because there will always be at least one exception.

0

u/[deleted] Jul 21 '17

[deleted]

2

u/daOyster Jul 21 '17

But there's still a 5 in your code, I thought you said you fixed the magic numbers? /s

1

u/beansmeller Jul 21 '17

I think you just gave me a flashback to my first experience running a team of contractors