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
SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal
Fair enough. It is a bit of a pain to get utf16 out of it - you have to cast to []rune, then use unicode/utf16 to get []uint16, and then use encoding/binary to turn that into a []byte with whichever endianness you need.

Adbot
ADBOT LOVES YOU

slam5000
Aug 19, 2012
The only word I have in my vocabulary to describe the following
formatting of java code, would have to be "Horrifying":

code:
	{}aabx.setTransform(
	new AffineTransform())
        ;i++;{}Point mousescreen
	 = ZoomAndPanListener.
	screenMouseLoc
       ;{}Point2D.Float mouseworld
	 = ZoomAndPanListener.
	worldMouseLoc
	;{}
This was written by a friend of mine who's new to programming, and even though he's new, I have no idea where he learned (or rather got the idea in his head) that it's ok to just throw in blocks in wherever the hell you want, and put your semi-colons at the START of the line!

nielsm
Jun 1, 2009



slam5000 posted:

This was written by a friend of mine who's new to programming, and even though he's new, I have no idea where he learned (or rather got the idea in his head) that it's ok to just throw in blocks in wherever the hell you want, and put your semi-colons at the START of the line!

I'm more interested in what purpose he gives those squiggly {} things.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Tilt your head to the left.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
:stare:

So this is the person who jslint was made for.

Yes I know Java is not Javascript, but he needs his feelings hurt the jslint way.

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.
I came across something like this today, in some older code written by one of our more senior programmers that's still being used for live, production work:
Perl code:
@somearray = ( "this work has been updated", "updated",
               "this work hasn't been updated", "same",
               "this work is new", "new"
               # and so on
              );

$somearray_len = @somearray;
$counter = 0;

while ($counter < $somearray_len){
    my $var1 = $somearray[$counter];
    $counter++;
    my $var2 = $somearray[$counter];
    # do stuff
}
This was, by far, the sanest and most comprehensible part of the program.

omeg
Sep 3, 2012

slam5000 posted:

The only word I have in my vocabulary to describe the following
formatting of java code, would have to be "Horrifying":

code:
	{}aabx.setTransform(
	new AffineTransform())
        ;i++;{}Point mousescreen
	 = ZoomAndPanListener.
	screenMouseLoc
       ;{}Point2D.Float mouseworld
	 = ZoomAndPanListener.
	worldMouseLoc
	;{}

What the gently caress. :cthulhu:

Nippashish
Nov 2, 2005

Let me see you dance!

slam5000 posted:

The only word I have in my vocabulary to describe the following
formatting of java code, would have to be "Horrifying":

code:
	{}aabx.setTransform(
	new AffineTransform())
        ;i++;{}Point mousescreen
	 = ZoomAndPanListener.
	screenMouseLoc
       ;{}Point2D.Float mouseworld
	 = ZoomAndPanListener.
	worldMouseLoc
	;{}

Every time I look at this I am increasingly more appalled that this guy is apparently using an editor with a <35 character line limit.

pigdog
Apr 23, 2004

by Smythe

Extortionist posted:

I came across something like this today, in some older code written by one of our more senior programmers that's still being used for live, production work:
Perl code:
@somearray = ( "this work has been updated", "updated",
               "this work hasn't been updated", "same",
               "this work is new", "new"
               # and so on
              );

$somearray_len = @somearray;
$counter = 0;

while ($counter < $somearray_len){
    my $var1 = $somearray[$counter];
    $counter++;
    my $var2 = $somearray[$counter];
    # do stuff
}
This was, by far, the sanest and most comprehensible part of the program.
Came for awesome perl horrors, left slightly disappointed. Sure he could have just gone for %somehash = @somearray and worked it from there, but hey, TMTOWTDI. Sane and comprehensible is a tall order for Perl programs in the first place.


quote:

Every time I look at this I am increasingly more appalled that this guy is apparently using an editor with a <35 character line limit.
A junior Java dev of ours came from a startup company (where he was senior), where the framework they were working with expected developers to edit Java code literally in a HTML textbox with that kind of line limit.

pigdog fucked around with this message at 10:46 on Nov 30, 2012

Hughlander
May 11, 2005

pigdog posted:

Came for awesome perl horrors, left slightly disappointed. Sure he could have just gone for %somehash = @somearray and worked it from there, but hey, TMTOWTDI. Sane and comprehensible is a tall order for Perl programs in the first place.

A junior Java dev of ours came from a startup company (where he was senior), where the framework they were working with expected developers to edit Java code literally in a HTML textbox with that kind of line limit.

Let me guess, and no one told them that you can drag out the size of a textbox in modern browsers?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Or just copy and paste into an actual text editor.

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.

pigdog posted:

Came for awesome perl horrors, left slightly disappointed. Sure he could have just gone for %somehash = @somearray and worked it from there, but hey, TMTOWTDI. Sane and comprehensible is a tall order for Perl programs in the first place.
He could also have just used a hash in the first place--he didn't use it for anything that wouldn't have been easier with a hash. Probably also worth noting that @somearray and $var1/$var2 are the actual variable names (there's also a $thing that recurs infrequently throughout the program).

Anyway, probably more impressive in the program were the ~200 regular expressions, all trying to match variations of the same relatively simple string. Stuff like:
Perl code:
@regexes = (
    "[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}",
    "[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}",
    "[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}",
    "[0-9]{1,2}\.[0-9]{1,2}",
    ## and so on for another 200-something lines
    );
foreach $r (@regexes){
    if input =~ m/$r/ {
        ...
    }
}
Slightly more complex than that, and probably complex enough that you'd want to use 2 or 3 regexes, just to make it easier.

But I may be being overly harsh on his code because the program doesn't really work at all, and the fact that it doesn't work creates probably an extra few day's worth of incredibly tedious work a month for a couple unlucky people (though not me, anymore).

Polio Vax Scene
Apr 5, 2009



I'm starting to notice a slight trend in one of our developers' scripts.

code:
                    catch (Exception)
                    {
                        //DO Something
                    }
                }
            }
            catch (Exception)
            {
                //DO Something
            }

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Manslaughter posted:

I'm starting to notice a slight trend in one of our developers' scripts.

code:
                    catch (Exception)
                    {
                        //DO Something
                    }
                }
            }
            catch (Exception)
            {
                //DO Something
            }

Tell him about Pokemon Exception Handling and why it's bad.

Zamujasa
Oct 27, 2010



Bread Liar

Ithaqua posted:

Tell him about Pokemon Exception Handling and why it's bad.

My favorite is still echo "mail send... ERROR"; // or use booleans here.


Ithaqua posted:

Tell him about Pokemon Exception Handling and why it's bad.

I don't know why they used Pokemon Exception Handling as the name of that (anti-)pattern, because to be pretty honest that kind of exception handling is exactly what made Pokemon entertaining. :v:

An attempt at googling where that came from (since "// DO something") did reveal this gem, though:
code:
bool exception = false;
try{
    // something
}catch(Exception e){
    exception = true;
}finally{
    if(!exception){
        // i can do what i want here
    } 
}
http://stackoverflow.com/questions/10431413/try-catch-finally-do-something-if-no-exception-is-thrown

It makes a little more sense if you read the comments, but at first glance (and even afterwards) it's just a little :psyduck: worthy.

Opinion Haver
Apr 9, 2007

Zamujasa posted:

I don't know why they used Pokemon Exception Handling as the name of that (anti-)pattern, because to be pretty honest that kind of exception handling is exactly what made Pokemon entertaining. :v:


It's because you gotta catch 'em all!

Polio Vax Scene
Apr 5, 2009



It's not even the catch(Exception) that scares me. It's the fact that the guy looked at that, thought "yeah, I could throw or something here, but I'll just let it fly :geno:" and then published. It's doing exactly the opposite of something.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

yaoi prophet posted:

It's because you gotta catch 'em all!

Yup. The worst offender I've ever seen just did this:
code:
public static void Main()
{
	try 
	{
		Go();
	}
	catch (Exception) { }
}

public static void Go() 
{
	// Entire application branches off from here
}

nielsm
Jun 1, 2009



Ithaqua posted:

Yup. The worst offender I've ever seen just did this:
code:
public static void Main()
{
	try 
	{
		Go();
	}
	catch (Exception) { }
}

public static void Go() 
{
	// Entire application branches off from here
}

That's more like Iraqi exception handling.


"There is no exceptions in this program. None. Ever."

raminasi
Jan 25, 2005

a last drink with no ice
I posted about in an earlier iteration of this thread years ago but I can beat even that:

(to paraphrase,)
C++ code:
int main() {
    do {
        do_entire_program();
    }
    catch (...) {
        throw 1; // this part is not a paraphrase. this is a quote.
    }
    return 0;
}
do_entire_program even threw exceptions. I'm not entirely sure why.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Ithaqua posted:

Yup. The worst offender I've ever seen just did this:
code:
public static void Main()
{
	try 
	{
		Go();
	}
	catch (Exception) { }
}

public static void Go() 
{
	// Entire application branches off from here
}

Holy poo poo. Do... like professional programmers, any of them actually do this in production. Because that is the just the most braindead instance of coding by coincidence I've ever seen. Throw out the exceptions, she'll be right, we'll eventually have a working product.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
The only thing that code does is make the program exit cleanly when there's an uncaught exception rather than report an error. It's dumb, but unless it's being called from a batch file that actually bothers to check exit codes it's unlikely to actually cause any problems beyond making it harder to debug things.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Plorkyeran posted:

The only thing that code does is make the program exit cleanly when there's an uncaught exception rather than report an error. It's dumb, but unless it's being called from a batch file that actually bothers to check exit codes it's unlikely to actually cause any problems beyond making it harder to debug things.

But why would you do that? What's the benefit when you're still going to have to figure out what the exception is?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Maluco Marinero posted:

Holy poo poo. Do... like professional programmers, any of them actually do this in production. Because that is the just the most braindead instance of coding by coincidence I've ever seen. Throw out the exceptions, she'll be right, we'll eventually have a working product.

Yes, this was done by a professional programmer and it was production code. Some people never learn good practices by never being exposed to them or bothering to learn about them. That's okay in a young developer, you can usually beat sense into them. The guys with 20 years of experience who suck are the really dangerous ones.

The code example I gave above was like that from top to bottom. Every method started with a try block and ended with an empty catch. It was a program that was supposed to be run 24/7 (it wasn't a service because that's harder than a console application run on the task scheduler), so I guess the developer responsible never wanted it to crash.

Note: the application did not work very well or reliably for some reason. But it never crashed!

New Yorp New Yorp fucked around with this message at 01:51 on Dec 1, 2012

Freakus
Oct 21, 2000
I've got to imagine that people who blindly catch every exception and don't even log it have never had to support their own programs over the long haul. I don't see how else they could continue such a practice.

how!!
Nov 19, 2011

by angerbot

Freakus posted:

I've got to imagine that people who blindly catch every exception and don't even log it have never had to support their own programs over the long haul. I don't see how else they could continue such a practice.

I think most people just don't know any better. They don't know it can be done better. I worked on a project once where a 'try/except/pass' pattern could be found once every dozen lines or so. We were constantly having to fix stupid bugs and sometimes it would take a whole week to track down a single bug. But everyone there just thought that was how the job of software developer is supposed to be.

Its sort of like how some people spend their whole lives working for $8 an hour at Walmart instead of learning a skill that will allow them to make hundreds of dollars an hour because they just see their life as what it is and can't imagine anything else.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
C# code:
var r = new int[5];
Assert.IsFalse(r.IsReadOnly); // passes
IList<T> c = r;
c[0] += 1; // works. clearly not readonly
Assert.IsFalse(c.IsReadOnly); // fails
:haw:

Hughlander
May 11, 2005

Ithaqua posted:

Yup. The worst offender I've ever seen just did this:
code:
public static void Main()
{
	try 
	{
		Go();
	}
	catch (Exception) { }
}

public static void Go() 
{
	// Entire application branches off from here
}

Could be worse... Could be
code:
public static void Main()
{
	try 
	{
		while(true)
		{
			Go();
		}
	}
	catch (Exception) { }
}

public static void Go() 
{
	// Entire application branches off from here
}

akadajet
Sep 14, 2003

Maluco Marinero posted:

Holy poo poo. Do... like professional programmers, any of them actually do this in production. Because that is the just the most braindead instance of coding by coincidence I've ever seen. Throw out the exceptions, she'll be right, we'll eventually have a working product.

I've had a manager ask for exactly that before because "we can't crash in production".

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

Aleksei Vasiliev posted:

C# code:
var r = new int[5];
Assert.IsFalse(r.IsReadOnly); // passes
IList<T> c = r;
c[0] += 1; // works. clearly not readonly
Assert.IsFalse(c.IsReadOnly); // fails
:haw:

It's been several years since I dabbled in C#, but... how does this happen? Is this just flat-out bug or is there some remotely rational explanation that I'm missing here?

pigdog
Apr 23, 2004

by Smythe

Hughlander posted:

Could be worse... Could be
code:
public static void Main()
{
	try 
	{
		while(true)
		{
			Go();
		}
	}
	catch (Exception) { }
}

public static void Go() 
{
	// Entire application branches off from here
}

You could put actual exception handling code inbetween these { } at the catch statement, and for most programs, end up with excellently handled exceptions.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Flobbster posted:

It's been several years since I dabbled in C#, but... how does this happen? Is this just flat-out bug or is there some remotely rational explanation that I'm missing here?

http://nitoprograms.blogspot.ca/2009/11/icollection-isreadonly-and-arrays.html

Short answer is that arrays in C# implement multiple interfaces with conflicting definitions of IsReadOnly.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

pigdog posted:

You could put actual exception handling code inbetween these { } at the catch statement, and for most programs, end up with excellently handled exceptions.

Yeah, that's what I was thinking. Is it so bad to throw exceptions up the call stack until you pass it off to an error handling class?

If so, what's a better way to handle exceptions?

Sedro
Dec 31, 2008
Handle exceptions as appropriate when the exception is recoverable and expected. It's fine to handle exceptions in the main, so long as "handling" means logging them and immediately exiting.

raminasi
Jan 25, 2005

a last drink with no ice

Sedro posted:

Handle exceptions as appropriate when the exception is recoverable and expected. It's fine to handle exceptions in the main, so long as "handling" means logging them and immediately exiting.

Yeah, I think that many times Pokemon exception handling gets made fun of it's not clear that the horror isn't catch (Exception), it's the fact that there's nothing in the catch block itself.

nielsm
Jun 1, 2009



GrumpyDoctor posted:

Yeah, I think that many times Pokemon exception handling gets made fun of it's not clear that the horror isn't catch (Exception), it's the fact that there's nothing in the catch block itself.

Those really are separate horrors, I'd say. Catching all is wrong because you don't know what you will end up catching and thus might never see serious problems, while doing nothing on an exception is just shutting your ears pretending the world (and yourself) to be perfect. So let's call them Pokemon EH and Iraqi EH. I just can't think of a good name for the combination.

The Gripper
Sep 14, 2004
i am winner
Sometimes bad code throws exceptions where the only response you could possibly have is "so what? who cares". Sometimes that same bad code throws exceptions for stupid poo poo and you just don't care about anything other than keeping your own code running continuously.

The first case leaves you with either catch (SpecificException) { pass; } because the alternative is logging something you literally don't give any fucks about, and the second case leaves you either with catch (SpecificExceptions) { pass; } assuming you know every stupid exception the code can throw, or catch (Exception) { pass; } if literally no exception that code can throw is of any consequence to you and you just can't be bothered determining what specific exceptions are going to be thrown beforehand.

It's not something you're likely to come across in good code when you're dealing with current, in-house projects, but good lord it comes up way too often when you're dealing with legacy application/library support. I deal with manufacturing machinery from the late 80s and early 90s where the software for it is so flimsy that I spend 90% of my time just out loud saying "holy loving poo poo why are you even telling me about this aaaaAAAAAAA". edit; these are systems where if something legitimately breaks the machines stop running, and regardless of what exception is thrown the original software just restarted the process to try again anyway.

The Gripper fucked around with this message at 11:57 on Dec 2, 2012

Volte
Oct 4, 2004

woosh woosh
Catching all exceptions in Main is fine for production releases, since in the event of a fatal error you can display a pretty error message with an appropriate amount of information rather than whatever normally happens (like a generic .NET exception message followed by an illegal operation), plus you can generate an error report that can be sent in.

Catching all exceptions anywhere other than Main is really dumb though.

Gul Banana
Nov 28, 2003

Volte posted:

Catching all exceptions anywhere other than Main is really dumb though.

- a background thread or detached process which reports on its failure
- a WCF service which encodes them into faults
- a library component which needs to encapsulate failures of its own dependencies into a predictable exception type
- auditing code which logs the exceptions then lets them continue up the call stack

Adbot
ADBOT LOVES YOU

nielsm
Jun 1, 2009



Volte posted:


Catching all exceptions anywhere other than Main is really dumb though.

Well if, as The Gripper mentions above, have to deal with old, lovely code that throws anything and everything, then you may need to catch them all. But only around the calls to the old code!

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