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
zeekner
Jul 14, 2007

Chairman Steve posted:

Can you elaborate? I'm not trying to call you out on anything - I'm genuinely interested to hear how String.equals() breaks the equals() contract.

I think he's referring to the problem with null strings in Java. If foostring is null, and you call foostring.equals("whatever"), then you get a null pointer exception. If you reverse that call, since "whatever" is guaranteed not to be null, you will never have that exception. It's due to java treating strings like objects, and building the equals() function into that object.

e: The horror is that java includes the equals function into the string object, where most other languages handle it in a separate function that can handle null cases better.

zeekner fucked around with this message at 16:35 on Jun 12, 2010

Adbot
ADBOT LOVES YOU

zeekner
Jul 14, 2007

SirViver posted:

Substring does allocate a new string. You can read the characters directly from the string, though, making substring completely unnecessary for reading single characters. That said, how would you implement substring without allocating a new string?

...

He may be referring to Java, where substring uses the parent's char array. http://www.javamex.com/tutorials/memory/string_memory_usage.shtml

zeekner
Jul 14, 2007

PhonyMcRingRing posted:

...
I was hoping I just had some ancient version being used in the project I had to work on, but nope, even when he recently converted it to C# it still has the same awfulness.

Horrible code is the only thing thats truly cross-platform.

zeekner
Jul 14, 2007

code:
Thread doSomething = new Thread(){
     public void run(){
          //stuff
          }

doSomething.run();
Huh, why is the UI thread blocking for so long? :downs:

zeekner
Jul 14, 2007

npe posted:

Dear Penthouse:
:drat:
It was every bit as wonderful as I expected it to be!

Do VB switch-cases fall-through? If so, there are no words to describe the horror.

zeekner
Jul 14, 2007

code:
hd_quality = int(self.__settings__.getSetting( "hd_videos_download" ))
if ( hd_quality == 0 ):
       hd_quality = int(self.__settings__.getSetting( "hd_videos" ))
else:
       hd_quality -= 1
'getSetting' returns a boolean in this case, int() throws a invalid value error.

This breaks a major feature in XMBC, and has gone unnoticed for months because of differences in how major versions of python handle int(boolean).

zeekner
Jul 14, 2007

quote:

Coding horrors: post the code that makes you laugh (or cry)

Eggnogium posted:

this ugly workaround that made me laugh:

Not everything in this thread has to be straight from the demented mind of an enterprise Java/PHP veteran.

I kinda like seeing the crazy ways new people solve problems, they are pretty creative (albeit in a terrible way).

zeekner
Jul 14, 2007

yaoi prophet posted:

code:
$node = "(?<node>\([A-Z]+[[:blank:]]+([^()]+|((?&node)[[:blank:]]*)+)[[:blank:]]*\)[[:blank:]]*)"
I love PCREs so much.

I thought I knew a fair bit about perl regex, but I can't read this drat thing.

What's it supposed to parse?

Edit: What are those named capture buffers even doing? Read it wrong.

zeekner fucked around with this message at 23:33 on Apr 7, 2011

zeekner
Jul 14, 2007

yaoi prophet posted:

poo poo that looks like "(PP (IN in) (NP (JJ full) (NN swing)))". The (?<node>) syntax means 'this pattern is called 'node'' and (?&node) means 'the pattern 'node'. So basically you can recurse back into the pattern from itself.

Amazing. No, wait, the other thing: Tedious.

Are there any practical limitations on how far that kind of regex can recurse?

zeekner fucked around with this message at 23:38 on Apr 7, 2011

zeekner
Jul 14, 2007

Munkeymon posted:

I'm not the best with Java, but I think this counts, right?

code:
public static String readUrl(String urlString) {
 BufferedReader in = null;
 String output = "";
 try {
  try {
   in = new BufferedReader(new InputStreamReader(
     new URL(urlString).openStream()));
   output = new String();
   String line;
   while ((line = in.readLine()) != null) {
    output += line + newline;
   }
  } finally {
   if (in != null)
    in.close();
  }
 } catch (IOException e) {
  e.printStackTrace();
 }
 return output;
}

It's not completely horrible, it just looks like a C programmer that's still stuck assuming everything needs a null-check or to be allocated manually.

Also, concatting strings like that should be done with StringBuilder or something.

zeekner
Jul 14, 2007

HFX posted:

The real horror here is that they overloaded mathematical operators for strings and thus broke consistency.

Java strings are a confusing mess. Features like that += operator are designed around ease of use, not speed. Anyone who understands this mess well will avoid them like the plague. When you stare into the enterprise, the enterprise stares into you.

That code snippet just shows that the programmer doesn't understand Java strings very well. Each += operation creates a new string, wasting memory and processing time. With StringBuilder, he could just append the string and generate the final string when he's done reading from input.

zeekner fucked around with this message at 19:13 on Apr 11, 2011

zeekner
Jul 14, 2007

ToxicFrog posted:

Am I missing something, or could that whole thing be replaced with:

code:
public static String readUrl(String urlString) {
  return urlString;
}

code:
new URL(urlString).openStream()
This is a shortcut to open an inputstream from that URL, for opening a webpage or something.

The code just opens/reads/concats a webpage or file into a string.

zeekner
Jul 14, 2007

Why does a localizer class do any form of pluralization? :psyduck:

zeekner
Jul 14, 2007

code:
defaultPlurifyRules.put(Pattern.compile("(.*)man$", Pattern.CASE_INSENSITIVE), "$1men");
defaultPlurifyRules.put(Pattern.compile("(.*)child$", Pattern.CASE_INSENSITIVE), "$1children");
Manchild -> Menchildren?

e: gently caress, didn't notice $

zeekner
Jul 14, 2007

TRex EaterofCars posted:

You're right. What is that (.*) doing in front of the line-start symbol though? That's what threw me off.
http://download.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html
. Any character (may or may not match line terminators)
X* X, zero or more times

So, anything zero or more times, basically a pure wildcard. I assume strings are tokenized before calling these functions.

zeekner
Jul 14, 2007

Is that better or worse than (Java):
code:
int whatever = Integer.parseInt("1");
The same program threw generic Exceptions from EVERY function, then ignored them in main(). Thank god it wasn't commercial, but it was still depressing to read.

zeekner
Jul 14, 2007

Monkeyseesaw posted:

Rule #1 of web development: Browsers don't scream about *anything*.

They cry themselves to sleep instead.

zeekner
Jul 14, 2007

Aleksei Vasiliev posted:

:stare:

So is your boss like insane, or something

Dooey posted:

(This shop primarily does electrical engineering so they aren't really familiar with common software development methodologies.)

This is pretty much the case, EE's tend to commit some pretty major coding horrors. Hell, sometimes horrors are even required by the device/IDE/platform. And I've never seen a good IDE for embedded devices. Ever.

zeekner
Jul 14, 2007

Janin posted:

from a while back, but:

This is a coding horror, because you're not verifying the contents of the exception. How do you know the correct BogusInputException was thrown, and that it was constructed with the correct values?

An exception type can be really specific or really general. Yea, you need to check the exception contents for an SQLException, but what can you really do with a NullPointerException? Even then, his code could easily have checked for the mis-constructed state inside the catch block and thrown a fail() there as well.

zeekner
Jul 14, 2007

decarboxylated posted:

code:
#DEFINE ZERO 0
#DEFINE ONE 1
#DEFINE TWO 2
#DEFINE THREE 3
#DEFINE FOUR 4
Scientific modeling code that's been under development by a multitude of developers for a decade. Reading it is like looking at the ark of the covenant.

It's handy to have that, remember back in '79 when "Two" was legally 3 for a week? Just plannin' ahead. :smug:

Also, off-by-one errors can be fixed en-mass.

zeekner
Jul 14, 2007

Sedro posted:

Java 7 has new operators to make this crap faster to write. :rolleyes:

code:
ohMyGod?[0]?.pleaseKill(me);

zeekner
Jul 14, 2007

Sedro posted:

What if that array is empty? Surely the indexer should return null instead of throwing an exception.

From what I understand, if the left side of the ? is null, it will return null instead of attempting to read the array. The second question mark does the same for the array value.

code:
if(ohMyGod != null && ohMyGod[0] != null){
  Object whatever = ohMyGod.pleaseKill(me);
}else{
  Object whatever = null;
}
Or for extra horror:
code:
Object whatever = (ohMyGod != null ? (ohMyGod[0] != null ? ohMyGod.pleaseKill(me) : null) : null);
Kill me.

e: Misread that, from that link: "(the array) is non-null and non-empty", it'll return null instead of throwing an error.

zeekner fucked around with this message at 07:01 on May 22, 2011

zeekner
Jul 14, 2007

It might be fine in other languages, but Java always encouraged avoiding null references as a design methodology. That way you don't have to check for null on every single operation. Now I'm gonna see code that'll have more question marks than a :foxnews: headline.

e: My complaints are really about the quality of the average Java programmer, the actual function isn't horrible. The coding horrors that will result will be.

zeekner fucked around with this message at 09:32 on May 22, 2011

zeekner
Jul 14, 2007

dwazegek posted:

How the gently caress do you even accomplish this?

I could only imagine some variables refer to previous variables, and rely on the specific initialization order.

int ONE = 1;
int TWO = ONE+ONE;
ect.

zeekner fucked around with this message at 09:48 on May 26, 2011

zeekner
Jul 14, 2007

Standish posted:

that's 5,400 commits every single day since subversion was released back in 2000, what are you doing?

All I can imagine is some app backed by a flat file database. Eventually they need to scale, enterprise style. Rather than spend 10 minutes rewriting the app to use SQL, they write to the file and check it into SVN. Every time the app goes to read the file it calls svn update first, and every time it writes it will commit those changes.

The Überhorror.

zeekner
Jul 14, 2007

JediGandalf posted:

I just found this gem
code:
if (CheckField(form.txtSalePrice.value,form,'0123456789$,') == true)
	if (CheckField(form.txtPerFin.value,form,'0123456789$') == true)
		if (CheckField(form.txtTermLoan.value,form,'0123456789') == true)
			if (CheckField(form.txtIntrate.value,form,'0123456789.') == true)
							OK=true
			else form.txtIntrate.focus()
		else form.txtTermLoan.focus()
	else form.txtPerFin.focus()
else form.txtSalePrice.focus()
return OK

Don't worry, I validated the input!

zeekner
Jul 14, 2007

xarph posted:

Torn between this thread and the poo poo that pisses you off thread...

code:
 # Stop command
  stop)
    echo "Stopping $APP"
    /bin/su -m $USER -c "$BASE/bin/shutdown.sh &> /dev/null"
    echo "$APP stopped successfully"
    ;;
I can forgive init scripts not being verbose, but at least you could check the goddamn return code or pass it through.

Edit:
code:
   # Restart command
   restart)
        $0 stop
        sleep 5
        $0 start
        ;;

That's like every init script ever written. I've seen one that used a web-interface to shut down the daemon, and never checked the output to find if that failed or not.

zeekner
Jul 14, 2007

Zhentar posted:

I just realized that in MUMPS, since '+' and '-' are also unary operators, this is legal syntax.

code:
>write 2++++++++++++++++2
4

MUMPS is signified by swelling, fever, headaches, and rashes. It has been eliminated in the first-world but remains a common issue in developing countries.

See also: Mumps_(disease).

zeekner
Jul 14, 2007

Munkeymon posted:

I get to support it because I'm the only one who will admit to knowing anything about PHP other than that it's terrible. Thankfully, I don't have to take the marketing director's code and make it not suck poo poo because we outsourced that. The guy doesn't understand loops and uses PHP. Use your imagination and I guarantee reality was worse.

Isolate that box from the network and name it Tortuga, there ain't no way that whore will stay clean.

zeekner
Jul 14, 2007

A A 2 3 5 8 K posted:

Every time I see a PHP blog post, it looks like this to me: http://techinfogurus.com/modules/editor/view_article.php?id=6

GOTOs are Bad, so I'll use do-while-break!
Happy Programming !!

zeekner
Jul 14, 2007

yaoi prophet posted:



I see.

ArchLinux? I haven't installed it in a while, but the installer was pretty barebones for such a nice customizable distro.

zeekner
Jul 14, 2007

Get that new job quickly, before they get hacked and that entry on your resume becomes a burden.

zeekner
Jul 14, 2007

Chopper posted:

Current fashionable languages/frameworks are Python/Django and Ruby/Rails. Personally I prefer Django.

And if you must use PHP, CodeIgniter is the only competent framework.

Good documentation, reasonable design standards, no lovely comments by terrible coders in the documentation. It almost made PHP seem like a normal language, until I had to look up some core PHP functionality and came crashing back to earth.

zeekner
Jul 14, 2007

There's also the bit where he's calling row() without checking num_results() first. CodeIgniter will actually throw a proper exception if you try to access a row in an empty cursor.

But I wouldn't expect a PHP programmer to know what an exception is.

zeekner
Jul 14, 2007

Goddamn, never roll your own crypto implementation. How hard is that? It's literally less work and cheaper to use a professionally written and publicly licensed library.

zeekner
Jul 14, 2007

Hammerite posted:

I know it's not nice to make fun instead of helping, but goddamn.

Oh god the varchar(2) that he will most assuredly use as the item count. 99 Erasers is enough for anyone!

zeekner
Jul 14, 2007

Dont forget that Google customizes results based on your search history. I get a lot more programming based results for otherwise ambiguous terms, where I would get much more generic results from a non-customized search.

zeekner
Jul 14, 2007

Zamujasa posted:

I'd consider another job but right now I've worked hard for my lowly $15/hour wage. At least I have benefits, even if they do come out of my paycheck at the end of the week.

Hey, stop selling yourself short. If your competent enough to point out those flaws, you're probably worth more than $15/hr. Seriously, IT helpdesk people make more than that.

Even if you are dangerously incompetent you could still make $25/hr like any bog-standard PHP developer.

zeekner
Jul 14, 2007

yaoi prophet posted:

I don't know C++ at all, what's the horror?

Returning the memory location of a local variable. Probably some other horrors too.

Adbot
ADBOT LOVES YOU

zeekner
Jul 14, 2007

Cirian posted:

Imagine what you get when you start with a horrible, ugly, slow language (Objective-C), and you selectively discard some (but not all C-isms), replacing them with a sprinkling of JavaScript, Pascal and Ruby. Finish it off with a dash of pure crazy, and you get this, the Eero Programming Language.

Amazingly the guy behind it actually wrote a full Clang module to support it.

Some of the epic features:
- (Mostly-)Optional semicolons
- Removal of braces in favour of indentation-level blocks, except where you have to explicitly put "end" to mark the end of some special blocks
- Removal of certain C language features for "safety" (goto, switch fall-through)
- Magic extraction of variable names from method calls based on the last camel-case word in the method name
- Automatically adding "NS"- prefix to typenames if it can't find the type

Anyone who thinks switch fall-through isn't a good feature should write a state machine. :doom:

Heh, NSNSSomeType errors.

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