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
Carbon dioxide
Oct 9, 2012

Today I saw something that looked like this:

code:
if ( httpResponse.statusCode() / 100 != 2 ) {
     throw new IOException(); 
}

Adbot
ADBOT LOVES YOU

necrotic
Aug 2, 2005
I owe my brother big time for this!
That's all kinds of special.

SupSuper
Apr 8, 2009

At the Heart of the city is an Alien horror, so vile and so powerful that not even death can claim it.

Mr. Crow posted:

HOW DO YOU HAVE A JOB IN IT?

I've been telling this kid how to do his job for the better part of a year; normal people actually learn things and it's no big deal but he is as clueless as the day I met him.
Oh I know I know! What you actually meant was "please replace the branch with the contents of master" :downs:

Mr. Crow
May 22, 2008

Snap City mayor for life

SupSuper posted:

Oh I know I know! What you actually meant was "please replace the branch with the contents of master" :downs:

Actually he ended up merging his branch into master, saying he pushed it (he didn't), then asking me to create pull request. From the pull request I was already reviewing.

He also kept trying to commit and push updates to his branch directly into master and we went through at least 6 back and forths of "I pushed it, can you see it??" "No, you need to switch to your branch, make the commit there and then push the branch"... "I pushed master can you commit it??" (Literally something he said).

And this is why we restrict commits on master to pull requests.

:eng99:

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe

Carbon dioxide posted:

Today I saw something that looked like this:

code:
if ( httpResponse.statusCode() / 100 != 2 ) {
     throw new IOException(); 
}

I don't know the first thing about netcode, but seems like a fairly reasonable way to test for codes in the 200s?

xzzy
Mar 5, 2009

That does work but it's in the "I'm so loving clever look how loving smart I am" category. Why not just do a couple greater than/less than comparisons and make the code way more legible?

Plus there's the issue where many of the 200 series response codes require special handling if you ever actually get one.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
Also there's the bit where relying on integer division to behave itself is an easy way to introduce errors later on. It's like not having curly braces for a conditional block -- sure, it works, and it's even defined in the language spec to work the way it does, but you're really better off being more rigorous.

necrotic
Aug 2, 2005
I owe my brother big time for this!

xzzy posted:

That does work but it's in the "I'm so loving clever look how loving smart I am" category. Why not just do a couple greater than/less than comparisons and make the code way more legible?

Plus there's the issue where many of the 200 series response codes require special handling if you ever actually get one.

It's also wrong since 3xx is not an error. Classic mistake.

Raising exceptions at all for a successful HTTP response, success code or not, is the real horror.

canis minor
May 4, 2011

Joda posted:

I don't know the first thing about netcode, but seems like a fairly reasonable way to test for codes in the 200s?

Cool that redirects throw an exception.

edit: ^^^ Or what he said

necrotic
Aug 2, 2005
I owe my brother big time for this!
I guess 1xx aren't errors either. Make it >3 problem solved?

canis minor
May 4, 2011

But wouldn't you want 404 to display "page not found" message, while serving the 404 code as well? Like here https://github.com/ffffffffffffffffffffffffffffffffff for example

necrotic
Aug 2, 2005
I owe my brother big time for this!
That was in the context of that snippet and would not fix anything probably. But don't raise exceptions for legit responses of which 4xx and 5xx are. Maybe use a monad or some poo poo but they are not exceptional unlike say a connection failure.

Carbon dioxide
Oct 9, 2012

Okay, to be completely fair, I found this in code that runs before a bunch of regression tests start. It makes a http connection to the test server's DB to store mock data in case it has been changed since the last run. That way the tests can reproducibly check if the DB query works properly.

If it doesn't return a 200 something is wrong with the local DB and you can't run the tests anyway.

necrotic
Aug 2, 2005
I owe my brother big time for this!
So it's mongo? I'm not aware of many DBs that have an HTTP protocol

Volte
Oct 4, 2004

woosh woosh

necrotic posted:

That was in the context of that snippet and would not fix anything probably. But don't raise exceptions for legit responses of which 4xx and 5xx are. Maybe use a monad or some poo poo but they are not exceptional unlike say a connection failure.
If you are doing an RPC call and it returns a 400 error, an exception makes sense. If you are writing an HTTP request library, then obviously do not raise exceptions on 4xx errors.

EssOEss
Oct 23, 2006
128-bit approved
That is an opinion but it is a wrong one. I prefer to work in a universe where failures are exceptional, thank you.

ErIog
Jul 11, 2001

:nsacloud:

Volte posted:

If you are doing an RPC call and it returns a 400 error, an exception makes sense. If you are writing an HTTP request library, then obviously do not raise exceptions on 4xx errors.

I smell the start of an exciting new exception derail! Every time it happens we get person after person talking about how, "well exceptions should be like X not like Y and in my favorite language they are like X" and it makes for really tedious discussion because their use is 100% implementation-dependent.

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

ErIog posted:

I smell the start of an exciting new exception derail! Every time it happens we get person after person talking about how, "well exceptions should be like X not like Y and in my favorite language they are like X" and it makes for really tedious discussion because their use is 100% implementation-dependent.

Only 50 odd pages since the last time! https://forums.somethingawful.com/showthread.php?threadid=2803713&pagenumber=913&perpage=40#post462693270

Soricidus
Oct 21, 2010
freedom-hating statist shill

ErIog posted:

I smell the start of an exciting new exception derail! Every time it happens we get person after person talking about how, "well exceptions should be like X not like Y and in my favorite language they are like X" and it makes for really tedious discussion because their use is 100% implementation-dependent.

also the good old "my english dictionary says exception means X and therefore the programming construct should have behaviour Y", because we definitely slavishly follow standard english definitions for every other bit of computer jargon, that's how jargon works right?

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
Instead of exceptions, computers should just catch fire. There would be far fewer bugs.

Volte
Oct 4, 2004

woosh woosh

EssOEss posted:

That is an opinion but it is a wrong one. I prefer to work in a universe where failures are exceptional, thank you.
That's cool, my job is in this universe though.

john donne
Apr 10, 2016

All suitors of all sorts themselves enthral;

So on his back lies this whale wantoning,

And in his gulf-like throat, sucks everything

That passeth near.

EssOEss posted:

That is an opinion but it is a wrong one. I prefer to work in a universe where failures are exceptional, thank you.

What about the Try pattern? Maybe monads? Error codes?

Ika
Dec 30, 2004
Pure insanity

Not code as such, but I have been trying to track down why a program had excessive memory usage. It turns out that the canon SDK function which converts a RAW image in memory to a RGB array spawns ~1100 threads and loads + unloads some of the SDK DLLs repeatedly.

WHY!?

Ika fucked around with this message at 16:15 on Jan 11, 2017

Volte
Oct 4, 2004

woosh woosh

Ika posted:

Not code as such, but I have been trying to track down why a program had excessive memory usage. It turns out that the canon SDK function which converts a RAW image in memory to a RGB array spawns ~1100 threads and loads + unloads some of the SDK DLLs repeatedly.

WHY!?
No surprise there. When I was a computer janitor I had to fix someone's computer that basically stopped working at all and it turned that some camera driver (either Kodak or Canon I think) was producing something like 1000 blank files per second in some temp folder, forever. The hard drive had filled up with just the file metadata from all these blank files and I couldn't even open the folder because it probably had a billion files in it. I don't think I could even delete the folder by normal means.

Ika
Dec 30, 2004
Pure insanity

It gets better. If I update the SDK, it still uses 1100 threads, but the newer version only opens the image data if I pass a file image reference, and not when passing a memory image reference (which worked before). So I have to dump the data to a temp. file.

steckles
Jan 14, 2006

Found while trying to figure out why one of our queries was taking five minutes to run:
code:
on percentMultiplier(val)
    local loc = 0
    val = double(val)
    val = string.insert ("00", val, 1)
    loc = string.find('.', val)
    val = string.delete(val, loc, 1)
    val = string.insert('.' , val, loc - 2)
    return( double(val) )

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

steckles posted:

Found while trying to figure out why one of our queries was taking five minutes to run:

Look, you can't trust floats to be precise; everyone knows about rounding errors. That's why we do all our math using strings, it's much safer.

Hughlander
May 11, 2005

Soricidus posted:

also the good old "my english dictionary says exception means X and therefore the programming construct should have behaviour Y", because we definitely slavishly follow standard english definitions for every other bit of computer jargon, that's how jargon works right?

I don't believe I am the horror here but if I were I doubt I'd know... but that is a line I use when we monitor and alarm on exceptions in production. "Someone trying to cheat at the game is not exceptional, it happens all day every day. Don't throw an exception for it."

Kazinsal
Dec 13, 2011

dougdrums posted:

Instead of exceptions, computers should just catch fire. There would be far fewer bugs.

if you ain't segfaulting you ain't poo poo

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Hughlander posted:

I don't believe I am the horror here but if I were I doubt I'd know... but that is a line I use when we monitor and alarm on exceptions in production. "Someone trying to cheat at the game is not exceptional, it happens all day every day. Don't throw an exception for it."

At some point I saw the aphorism "exceptions should be exceptional," and I've never seen a case that disproved it.

Although, that was in a Ruby-focused book, so...

lifg
Dec 4, 2000
<this tag left blank>
Muldoon
Whereas Python will throw an exception just to say that an iterator is out of items to iterate over.

Soricidus
Oct 21, 2010
freedom-hating statist shill

Doc Hawkins posted:

At some point I saw the aphorism "exceptions should be exceptional," and I've never seen a case that disproved it.

Yeah that was the line I was thinking of. Like most such aphorisms it is clever, pithy, memorable, and practically worthless, because it describes someone's theoretical ideal world, not the actual ways exceptions are used by real programmers every day -- almost certainly including the programmers who wrote that standard library that all your scrupulously aphorism-compliant code relies on.

Exceptions should be used when they're the right tool for the job. When this is the case depends on factors like the costs involved, the idioms of the language in use, the coding standards being followed, and the maintainability of the resulting code. It rarely depends on someone's interpretation of the word "exceptional" (although the expected frequency of the error case may well be a factor in runtime cost analysis).

Volte
Oct 4, 2004

woosh woosh

Doc Hawkins posted:

At some point I saw the aphorism "exceptions should be exceptional," and I've never seen a case that disproved it.
I think that applies more to the catch block than the exception itself. If you're writing code inside a catch block that is supposed to execute, then you've hosed up by not treating exceptions as exceptional. Other than that, where and when to use what exceptions is highly application-dependent. As a rule of thumb I would say that exceptions should never contain any information that will be carried forward into the normal state of the application. The exception should be logged or reported to the user, but if any of the data in the exception is stored in the application state or even used to figure out what to do next, then you basically used the exception like a valid return value and broke the rule. Not a hard-and-fast rule, it should be broken when it makes sense. Knowing when it makes sense is the art of being an engineer.

steckles
Jan 14, 2006

TooMuchAbstraction posted:

Look, you can't trust floats to be precise; everyone knows about rounding errors. That's why we do all our math using strings, it's much safer.
Strings can have an infinite number of characters therefore strings have infinite precision. Not like those puny doubles with their laughably small number of bits. :smugdog:

To tie it to exception chat, if a negative number is passed the final coercion to double throws an exception that's never checked for anywhere.

Axiem
Oct 19, 2005

I want to leave my mind blank, but I'm terrified of what will happen if I do

steckles posted:

Strings can have an infinite number of characters therefore strings have infinite precision. Not like those puny doubles with their laughably small number of bits. :smugdog:

Kinda makes me want to write a floating-point adder that takes in two strings, for fun. I can't imagine it would be that difficult.

Dylan16807
May 12, 2010

Axiem posted:

Kinda makes me want to write a floating-point adder that takes in two strings, for fun. I can't imagine it would be that difficult.

That's basically a bignum library. Go for it. I'm sure it's good practice.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
Speaking of exceptions, can someone please tell me what Go is good for? Because I'm not seeing it myself. In particular, there's poo poo like there not being any exceptions, so you do every single function call as
code:
if result, err := func(args); err != nil {
  die in a fire;
}
and the fact that the compiler decides what symbols to export from your package by whether or not the symbol name is capitalized, and then there's the style guide going and saying that you should prefer short variable names which invariably means that developers think "every variable name should be at most five letters long even if that completely nukes any semblance of readability."

And I'm sure there's even worse horrors, but these are ones that seem to be especially unique to Go. So what does it do well?

eth0.n
Jun 1, 2012

Axiem posted:

Kinda makes me want to write a floating-point adder that takes in two strings, for fun. I can't imagine it would be that difficult.

For extra credit, support the combining overline for repeating decimals.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Soricidus posted:

Yeah that was the line I was thinking of. Like most such aphorisms it is clever, pithy, memorable, and practically worthless, because it describes someone's theoretical ideal world, not the actual ways exceptions are used by real programmers every day -- almost certainly including the programmers who wrote that standard library that all your scrupulously aphorism-compliant code relies on.

Exceptions should be used when they're the right tool for the job. When this is the case depends on factors like the costs involved, the idioms of the language in use, the coding standards being followed, and the maintainability of the resulting code. It rarely depends on someone's interpretation of the word "exceptional" (although the expected frequency of the error case may well be a factor in runtime cost analysis).

Actually, of late I've mostly been programming in a language that doesn't have them, and I don't miss them at all. I assume you wouldn't count that as the real world though.

"Other people don't do this," by itself, seems like a weak argument against a programming practice.

Doc Hawkins fucked around with this message at 04:36 on Jan 12, 2017

Adbot
ADBOT LOVES YOU

xtal
Jan 9, 2011

by Fluffdaddy
A goto by any other name would be considered as harmful

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