Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Look Around You
Jan 19, 2009

pigdog posted:

From Notch's perspective, counterintuitively, yes. It proves, with cold hard cash to back it up, that the faults in his game and coding style are relatively insignificant.

I am not Notch. I am not speaking for Notch. I am speaking for myself. I don't give a drat whether or not he's making money off of it, it doesn't affect me one bit. I'm a lot more interested in theory than in making money anyway.

quote:

Ultimately you don't code something like this for coding's own sake. Succeeding in writing software that people would buy is a higher level goal than writing perfect code. The latter is ultimately the means to attain the former.

Again this is extremely presumptuous. Writing "perfect code" is more than just about becoming profitable or "successful". It's also a way to improve your knowledge and skills. Sometimes I'll put in 5 hours on school project that I could cobble together in 1 hour. Sure I would probably get the same grade, but doing that won't make me any better of a programmer.

If he's just out to make money, then fine, that's what matters to him, but that's not what this thread is about. This is not "Software Success: Post the produce that make you laugh (or smile)". I'm not even being glib. You're missing the whole point of this thread.

Adbot
ADBOT LOVES YOU

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
The whiteknight squad comes out whenever anyone mentions minecraft in any thread in any subforum, frankly it ought to get 1) banned from this thread and 2) sequestered to its own subforum. Didn't furries get obnoxious a few years back to the point they were quarantined? Do that again.

The Gripper
Sep 14, 2004
i am winner

Jewel posted:

But this argument is like saying "Well I'm the owner of a candy company. We make the cheapest shittiest candy you can buy, but because it's so cheap, children buy it even though it tastes bad, because they can't tell the difference!"

Yes, you have money, but you don't have a good product in any sense of the word. Plus; once again, this is the coding horrors thread, not the "Unsuccessful products" thread. The code is bad, so we focus on that.
Plus it's not even subjectively "ugh I don't like this" bad; there's blocks of code that are poorly designed enough to restrict future complexity because of performance concerns (and have in the past prevented Notch from making changes), and these kinds of bottlenecks aren't present in games with significantly higher complexity (as people regularly cite, Skyrim performs better than Minecraft on equivalent hardware).

I'm willing to let it slide and not outright say he's an awful developer since he originally didn't have these grand plans for the game, but it doesn't make bad code any less bad (though at a smaller scale, maybe the problems wouldn't be an issue).

pigdog
Apr 23, 2004

by Smythe

Look Around You posted:

I am not Notch. I am not speaking for Notch. I am speaking for myself. I don't give a drat whether or not he's making money off of it, it doesn't affect me one bit. I'm a lot more interested in theory than in making money anyway.


Again this is extremely presumptuous. Writing "perfect code" is more than just about becoming profitable or "successful". It's also a way to improve your knowledge and skills. Sometimes I'll put in 5 hours on school project that I could cobble together in 1 hour. Sure I would probably get the same grade, but doing that won't make me any better of a programmer.

If he's just out to make money, then fine, that's what matters to him, but that's not what this thread is about. This is not "Software Success: Post the produce that make you laugh (or smile)". I'm not even being glib. You're missing the whole point of this thread.

On the contrary, I'm perfectly aware of what this thread is about. Minecraft's success story in my opinion augments it brilliantly. Developers may get too caught up in quality and gold-plating that they don't realize, or forget, what's actually important: for the code to provide some value for someone. Personally, I'm totally obsessed with writing clear, optimal and bulletproof code with test-driven methodologies, but there's no way to argue with Minecraft's success. Something like Skyrim has been and has to be lovingly, skillfully and painstakingly crafted, but from the other end, noone would gold-plate or test-drive a shell script they would only use once. Notch has found his own sweet spot between speed, skill and quality, and even if it's not quite as well made as Skyrim or not quite as hacked together as a single-use shell script, he has succeeded and thus done it right in his own way.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof
Hey guys, how's this for a coding horror:

code:
$.post('newreply.php', {
    threadid: '2803713',
    message: 'Anything about Minecraft'
});

Look Around You
Jan 19, 2009

pigdog posted:

On the contrary, I'm perfectly aware of what this thread is about. Minecraft's success story in my opinion augments it brilliantly. Developers may get too caught up in quality and gold-plating that they don't realize, or forget, what's actually important: for the code to provide some value for someone. Personally, I'm totally obsessed with writing clear, optimal and bulletproof code with test-driven methodologies, but there's no way to argue with Minecraft's success. Something like Skyrim has been and has to be lovingly, skillfully and painstakingly crafted, but from the other end, noone would gold-plate or test-drive a shell script they would only use once. Notch has found his own sweet spot between speed, skill and quality, and even if it's not quite as well made as Skyrim or not quite as hacked together as a single-use shell script, he has succeeded and thus done it right in his own way.

The thing is that nobody was detracting from his product's success. At all. Nobody here has argued that Minecraft wasn't a successful product. There's a difference between a product's success and it's technical correctness and I think that most people posting in this thread realize that.

I mean, I personally prefer spending my time perfecting my skills, learning new things and hopefully advancing the field eventually. Ideally I'll end up in academia, but that's a long way off. Honestly I don't care if I ever get rich, I'd rather advance the field and my own knowledge.

e: I recognize that I'm a bit uncommon and a bit of an idealist though.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





My kingdom for a new LOL PHP error.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Here's an oldie but goodie

Aristotle Palagaltzis posted:

This is a tale of an integer overflow vulnerability (paraphrased for the purposes of the tale, as are all following snippets):
code:
dest = calloc(EXPR, sizeof(char));
/* where EXPR is a calculation that is never checked for overflow */
Of course, the maintainers of the software in question are studious and busy types and they would not let this go unfixed for long – they instituted a check to make sure that such a thing would never happen again:
code:
int size;

size = EXPR;

if (size > INT_MAX || size <= 0) {
    return NULL;
}

dest = calloc(size, sizeof(char));
Marvelous! Now the code is safe…



Err, right. Undaunted and unphased by having made a mistake, they sagely nodded when they learned of it, and proceeded to implement a fix that would rid the world of this evil for good:
code:
float size;

size = PARTIAL_EXPR_1;
size *= PARTIAL_EXPR_2;
size += PARTIAL_EXPR_3;

if (size > INT_MAX || size <= 0) {
    return NULL;
}

dest = calloc((int)size, sizeof(char));
And the world was a safer pl… err… I mean: and when they also got rid of floating point round-offs, the world became a safer pla…



OK, people, enough of the fairy tales. How do these people even come up with this stuff?!? Testing an integer for whether it’s greater than INT_MAX ?! A float to calculate the length of a string!? I mean… I am… when I…

You can’t even parody this stuff.

This is bogosity as it belongs on DailyWTF, not into one of the most widely deployed codebases on the internet that is backed by several of the biggest corporations in IT. Please, please, someone tell me how PHP got to be as big as it is?

P.S.: oh yeah, and the current guard clause looks like this:
code:
int charsize = sizeof(char);

/* still the same float-based calculation here */

if ((size > INT_MAX || size <= 0) || ((size * charsize) > INT_MAX || (size * charsize) <= 0)) {
    return NULL;
}
Portability is important, after all.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Otto Skorzeny posted:

Here's an oldie but goodie

The best part is when you remember that sizeof(char) == 1. Everywhere. If it isn't, then you're not actually coding in C.

hobbesmaster
Jan 28, 2008

Jabor posted:

The best part is when you remember that sizeof(char) == 1. Everywhere. If it isn't, then you're not actually coding in C.

That's a style thing. Let's not start that again...

The Gripper
Sep 14, 2004
i am winner

Jabor posted:

The best part is when you remember that sizeof(char) == 1. Everywhere. If it isn't, then you're not actually coding in C.
I like the (size * charsize) <= 0 test, purely because I can't figure out what edge-case it solves.

hobbesmaster posted:

That's a style thing. Let's not start that again...
If it's a style thing then a) why bother using charsize at all? b) right hand side tests are equivalent to left hand side tests, so entirely pointless.

The Gripper fucked around with this message at 10:19 on Apr 9, 2012

hobbesmaster
Jan 28, 2008

The Gripper posted:

I like the (size * charsize) <= 0 test, purely because I can't figure out what edge-case it solves.

If it's a style thing then a) why bother using charsize at all? b) right hand side tests are equivalent to left hand side tests, so entirely pointless.

I wasn't looking at the bottom one, I blocked it out of my mind at first glance so was just looking at the calloc call. I can't even pretend to understand how that would make sense.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

hobbesmaster posted:

That's a style thing. Let's not start that again...

It's a style thing in a malloc (a poor style, incidentally, although for other reasons), but not here. If you look up the commit, they actually thought they were making the code portable to systems where sizeof(char) != 1. That is to say, systems guaranteed not to exist.

The Gripper
Sep 14, 2004
i am winner

hobbesmaster posted:

I wasn't looking at the bottom one, I blocked it out of my mind at first glance so was just looking at the calloc call. I can't even pretend to understand how that would make sense.
I didn't even notice the calloc, so I'll freely admit that doing it there is an ok style choice!

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

The Gripper posted:

I didn't even notice the calloc, so I'll freely admit that doing it there is an ok style choice!

Since it's come up twice now, I'll disagree

Doing

foo = malloc(n * sizeof(*foo))

or

foo = calloc(n, sizeof(*foo))

always makes more sense than

foo = malloc(n * sizeof(whatever_type_*foo_is))

Progressive JPEG
Feb 19, 2003

sizeof(var) can be better than sizeof(var_type), just in case var someday changes type and noone remembers to update that sizeof.

(PS that guide is pretty useful in general)

tef
May 30, 2004

-> some l-system crap ->

Strong Sauce posted:

My kingdom for a new LOL PHP error.

Why not learn about how to handle unicode in php ? http://www.phpwact.org/php/i18n/utf-8

tef
May 30, 2004

-> some l-system crap ->

Otto Skorzeny posted:

foo = malloc(n * sizeof(*foo))

assuming no integer overflow :confused:

hobbesmaster
Jan 28, 2008

tef posted:

assuming no integer overflow :confused:

Lets do it the PHP way!
code:
int size;
size = n * sizeof(*foo);
if(size > MAX_INT || size <= 0){
     return NULL;
}
dest = calloc(size, n * sizeof(*foo));
     

PrBacterio
Jul 19, 2000

Otto Skorzeny posted:

Here's an oldie but goodie

So why didn't even one of them just come up with (what seems to me to be the obvious and sane version of)
code:
#define SIZE_MAX	((size_t)(-1))

	/*...*/
	const size_t max_items = SIZE_MAX / sizeof(*buffer);
	if(n_items > max_items) {
		/*raise an error*/
	} else {
		buffer = malloc(n_items * sizeof(*buffer));
		/*...*/
	}
	/*...*/
?

EDIT: vvv but there's no division happening here at run-time anywhere? it's all compile-time which even a straightforward and simple compiler should be able to optimize away during compile-time constant folding vvv

PrBacterio fucked around with this message at 18:16 on Apr 9, 2012

nielsm
Jun 1, 2009



But division is slooooooowww!!

Vanadium
Jan 8, 2005

Thanks for reposting that php thing, the link to the writeup in the post I had bookmarked apparently went dead. :shobon:

1337JiveTurkey
Feb 17, 2005

PrBacterio posted:

EDIT: vvv but there's no division happening here at run-time anywhere? it's all compile-time which even a straightforward and simple compiler should be able to optimize away during compile-time constant folding vvv

There wouldn't be half as much crappy code floating around if people recognized when their 'optimizations' were absolutely pointless.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

I just came across this:
code:
typedef enum {
  AppTabIdentifierNone, //None has no use other than to have identifers start at an index of 1
  AppTabIdentifierFoo,
  AppTabIdentifierBar,
  AppTabIdentifierBuzz,
...
Wouldn't it make more sense to just say:
code:
typedef enum {
  AppTabIdentifierFoo = 1,
  AppTabIdentifierBar,
  AppTabIdentifierBuzz,
...

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
It's not necessarily unhelpful to define a value for zero even if you don't expect to use it. For example, assuming you're dealing with Objective-C, instance variables are initialized as zero, so you could easily see a value of 0 for something declared as that enum.

I'm with you in not wanting 0 to be a legal non-falsy value though, and making the first in the list = 1 does that.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice
The Dunning-Kruger effect. That is my only explanation for this stuff.

Anyone is entitled to write crappy code. We all do it when prototyping something or when the schedule demands we get a product out the door.

When a good programmer gets reports of his code running slowly or realizes he can't add a feature due to a bad design decision.... He fixes the code. He runs a profiler on it. He tries to research better algorithms. Especially when that person makes millions of dollars and now has his or her full time to devote to the product and the ability to hire additional developers.

Code's history is excusable. It's present condition is not.

Thats what gets me: People who don't just write crappy code - they are proud of it and continue to actively avoid learning a better way of doing things. The only explanation is that their incompetence is so pronounced they are unable to recognize just how incompetent they are.


edit: removed derail to focus on the real point

Simulated fucked around with this message at 20:30 on Apr 9, 2012

Star War Sex Parrot
Oct 2, 2003

Shut up about notch/Minecraft.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Ender.uNF posted:

People who don't just write crappy code - they are proud of it and continue to actively avoid learning a better way of doing things. The only explanation is that their incompetence is so large they are unable to recognize just how incompetent they are.

That's my last job in a nutshell. I had conversations along the following lines many times:

Other Developer: Why did you refactor my code to do <thing that's a best practice>?
Me: Because <thing> is a best practice for <reasons>.
OD: But we don't do <best practice> anywhere else! I'm going to change it back.
Me: *blank stare, begins mentally composing letter of resignation*

Meanwhile, if the roles were reversed, the conversation would go like this:
Me: Why did you refactor my code to do <thing that's a best practice>?
Other Developer: Because <thing> is a best practice for <reasons>.
Me: Ooh, that's really good to know, thanks! I'll keep that in mind in the future.

McGlockenshire
Dec 16, 2005

GOLLOCKS!

Ithaqua posted:

Other Developer: Why did you refactor my code to do <thing that's a best practice>?
Me: Because <thing> is a best practice for <reasons>.
OD: But we don't do <best practice> anywhere else! I'm going to change it back.

This may be a case of the developer caring about "his" code too much.

Devs getting possessive has been the #1 obstacle I've encountered when trying to do non-trivial scale refactoring, even trumping management deadline fuckery.

tef
May 30, 2004

-> some l-system crap ->
You are not your code

OddObserver
Apr 3, 2009

tef posted:

assuming no integer overflow :confused:

Well, the compiler probably can (repeat after me: signed integer overflow in C is undefined...)

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

McGlockenshire posted:

This may be a case of the developer caring about "his" code too much.

Devs getting possessive has been the #1 obstacle I've encountered when trying to do non-trivial scale refactoring, even trumping management deadline fuckery.

I don't think it was out of ownership. I was the youngest developer on the team by decades, and I incorrectly thought that being around older devs would mean that they had a lot to teach me. Instead, I was the only person with a current skill set and exposure to modern software development practices, and they were dismissive of my suggestions because I'm "young" (by which I mean "barely under 30", with 8 years of professional experience).

There definitely were some areas where there was "ownership," of course. I suggested phasing out the horrible database-and-reflection-driven abomination they were using for XML generation in favor of simple serialization and was dismissed by the guy that wrote the monstrosity because it wasn't "flexible". Of course, implementing even a simple XML schema took weeks of loving around creating database rows, and generating the XML was so slow that processing 100 records took 5 minutes (and we were working with 10,000+ record data sets), but it was flexible. :barf:

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I forget if I've pasted this one before: Click "Comments", and then scroll down a bit. Here's something else by him.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

code:
# NOTE: w = x
# NOTE: z = y
#    -- HE, HE, Bad habit of mine . . .

Chuu
Sep 11, 2004

Grimey Drawer
So a coding decision I made months ago is starting to drive me insane. I was writing a decoder for a certain messaging protocol and decided to interpret str(1)'s as chars. I can't count how many times a bug has been tracked down to a mistake that's essentially the following:

quote:

if (x == 1) {...}
vs.

quote:

if (x == '1') {...}

I'm not sure if the horror is that the implicit cast is legal, or that I decided to use a "weak type" for such a critical data structure. Either way, this has caused all sorts of fun bugs, especially since I'm no longer the only one working on this codebase.

I should probably refactor before it's too late . . .

Nippashish
Nov 2, 2005

Let me see you dance!
PHP's rand() function seems to have some pretty obvious patterns.

mentholmoose
Nov 5, 2009

YKNOW THERES ONLY ONE DIRECTION I KNOW AND THATS DRIVIN STRAIGHT TO THE NET

Nippashish posted:

PHP's rand() function seems to have some pretty obvious patterns.

FWIW, I'm pretty sure that's only PHP on Windows. On Mac OS X the sample code Bo Allen posted displays a bitmap without any real patterns.

I haven't tested it on Linux, but it looks like other people have and it appears to be Windows/PHP specific.

senrath
Nov 4, 2009

Look Professor, a destruct switch!


Yeah, the linked article discusses that. It's due to PHP's rand function just being a wrapper for the system's random function.

McGlockenshire
Dec 16, 2005

GOLLOCKS!
Perl, Ruby and Python all expose the same flawed rand by default, as does, say, C. This has been a known problem for decades.

Don't use rand for anything other than trivial matters.

Adbot
ADBOT LOVES YOU

ToxicFrog
Apr 26, 2008


Linux and OSX - at least - long ago either upgraded rand() itself or made it an alias for random(), which while not crypto-quality isn't laughably and obviously broken as rand() is.

Windows still uses the old, terrible implementation, though. :eng99:

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply