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.
 
  • Locked thread
cliffy
Apr 12, 2002

code:
try {
	for (int i = 0; /*wot no test?*/ ; i++)
		array[i]++;
} catch (ArrayIndexOutOfBoundsException e) {}
if anyone ever does this fire them immediately full stop

Adbot
ADBOT LOVES YOU

Cold on a Cob
Feb 6, 2006

i've seen so much, i'm going blind
and i'm brain dead virtually

College Slice

cliffy posted:

code:

try {
	for (int i = 0; /*wot no test?*/ ; i++)
		array[i]++;
} catch (ArrayIndexOutOfBoundsException e) {}

if anyone ever does this fire them immediately full stop

apparently this is basically how python iteration works if what i read is true

shaggar was right!?

Bloody
Mar 3, 2013

JewKiller 3000 posted:

modern programming languages (not java, definitely not any p-lang)
modern programming languages except for every modern programming language

PleasingFungus
Oct 10, 2012
idiot asshole bitch who should fuck off

Cold on a Cob posted:

you're avoiding my main point and a few of my side points.

main point:

if it's something that frequently or commonly happens that your program is expected to deal with and continue, you are dealing with control flow and should not rely on exceptions because they are an expensive non-obvious shortcut up the call stack. for example, if you're dealing with a resource in A that will frequently be unavailable and you need to notify C, it should be documented in the interface for A and B as a return/out value. yes this is more work.

if it's something that rarely happens, it's an exception and you should pass it up the stack, log it, probably halt the process or program depending on the exception type, etc.

side points:
- generating exceptions is an expensive operation. it's wasteful because you're rolling up the call stack and consuming excessive memory and processing power when a simple bool might be more than enough.
- you're hiding functionality. in your example, C knows that A might fail but since B doesn't know, if someone else consumes B they might not be prepared for the fact you're using a non-obvious method of controlling program flow, at least as far as the language is concerned (contrast this with an out parameter in a method signature). i guess checked exceptions might help with this, i'm not a java guy so i don't know much about them. and yeah, maybe python does it differently but like i said, they should at least call it something else then. semantics matter and words have meaning.
- you might accidentally swallow other exceptions (i didn't mention this before but it is a possibility, unless you start generating custom exceptions purely to handle control flow which is more work anyway so you probably wouldn't do that)

I don't really think I am avoiding your points, though. "expense" is language-dependent, and reeks of premature optimization in any case. "non-obvious" - there's nothing that's non-obvious about exceptions, especially if they're documented / in the interface. yes that is more work.

checked exceptions do solve exactly the ambiguity that you're complaining about, when everything needs to be nailed down. also I think this argument has driven me towards checked exceptions / shaggarism, which is a terrible feeling, but there you go.

there is no need to call python exceptions something else when they work in the exact same way as every other language's exceptions.

generating custom exceptions is super trivial & we do it all the time at my work.

Python code:
class ButtException(Exception):
   pass

throw ButtException("oh no butts")
--

honesty time: I think this argument has turned into "exceptions are fine to use for a lot of thing in Python!" "no they're terrible to use except for really rare cases in C#!" "no they're fine in Python!" "no they're terrible in C#!"

so maybe we should switch to mocking jewkiller 3k instead of continuing?

idk.

Juul-Whip
Mar 10, 2008

couple years ago I did a huge ~10,000 line java project in uni with 12 other guys and we abused the loving hell out of exceptions. every file had at least a couple try-catch blocks. it was atrocious and the prof rightly called us out on it

Cold on a Cob
Feb 6, 2006

i've seen so much, i'm going blind
and i'm brain dead virtually

College Slice

PleasingFungus posted:

I think this argument has turned into "exceptions are fine to use for a lot of thing in Python!" "no they're terrible to use except for really rare cases in C#!" "no they're fine in Python!" "no they're terrible in C#!"

*high pitched voice* python coders code like thiiisssssss and *low pitched voice* c# coders code like thiiisssssss

Cold on a Cob fucked around with this message at 12:56 on May 18, 2013

Cold on a Cob
Feb 6, 2006

i've seen so much, i'm going blind
and i'm brain dead virtually

College Slice
i had to edit that because all the black developers i know use c# and all the python coders i know are skinny white dudes with high pitched nasally voices

Armourking
Dec 16, 2004

Step off!
Step off!


you guys comment as you go, or just spew a whole bunch of lines out and comment anything non obvious?

Cold on a Cob
Feb 6, 2006

i've seen so much, i'm going blind
and i'm brain dead virtually

College Slice
i comment non obvious stuff (why not what)

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
its funny because even in C# you still need to handle the exception when you open a file that doesn't exist, because someone could have deleted it after you checked for it but before you actually opened it

PleasingFungus
Oct 10, 2012
idiot asshole bitch who should fuck off

Cold on a Cob posted:

*high pitched voice* python coders code like thiiisssssss and *low pitched voice* c# coders code like thiiisssssss

Mr SuperAwesome
Apr 6, 2011

im from the bad post police, and i'm afraid i have bad news

Jabor posted:

its funny because even in C# you still need to handle the exception when you open a file that doesn't exist, because someone could have deleted it after you checked for it but before you actually opened it

fun CJ knowledge: when using MS programs to edit files, they delete and recreate the file when u change one line in butts.docx so u gotta have delete permissions on the directory to edit, not just edit

Squinty Applebottom
Jan 1, 2013

yeah saving a file involves like a dozen steps of deleting, recreating, temp files. its a mess

AWWNAW
Dec 30, 2008

how about a true life terrible programmer story

found a painful bug in production yesterday written by a "senior developer" coworker

code:
object integerValue = datagridrow[hardcodednumber].value;
object oldIntegerValue = datagridrow[anotherhardcodednumber].value;
if (integerValue == oldIntegerValue)
{
    DoNeedful();
}
can any of yout errible programmers tell me why needful never gets done

i hope this post makes you a better program

shalom

Doc Block
Apr 15, 2003
Fun Shoe
lol

nrook
Jun 25, 2009

Just let yourself become a worthless person!
shoulda used =====

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

cliffy posted:

code:
try {
	for (int i = 0; /*wot no test?*/ ; i++)
		array[i]++;
} catch (ArrayIndexOutOfBoundsException e) {}
if anyone ever does this fire them immediately full stop

never allow people to omit braces on for/if statements :colbert:

Zaxxon
Feb 14, 2004

Wir Tanzen Mekanik

prefect posted:

never allow people to omit braces on for/if statements :colbert:

real talk

PleasingFungus
Oct 10, 2012
idiot asshole bitch who should fuck off
I leave out braces on for/ifs whenever I get the chance (when I'm using languages with braces)

I hate the sight of them

code:
			if (opIntValues && opIntValues.length)
				for each (var opIntValue:int in opIntValues)
					expectedOps.push(OpcodeValue.fromValue(new NumericValue(opIntValue)));
			else if (U.state)
				expectedOps = U.state.level.expectedOps.slice();
mmm

it's almost elegant

cliffy
Apr 12, 2002

prefect posted:

never allow people to omit braces on for/if statements :colbert:

holy crap lois I didn't even notice that

im gonna go lie down forever

coaxmetal
Oct 21, 2010

I flamed me own dad

PleasingFungus posted:

I leave out braces on for/ifs whenever I get the chance (when I'm using languages with braces)

I hate the sight of them

code:
			if (opIntValues && opIntValues.length)
				for each (var opIntValue:int in opIntValues)
					expectedOps.push(OpcodeValue.fromValue(new NumericValue(opIntValue)));
			else if (U.state)
				expectedOps = U.state.level.expectedOps.slice();
mmm

it's almost elegant

braces aside, please never have a nonsdescriptive variable name, particularly one that is just one letter. What the gently caress is U? Whatever it is, it could be called something meaningful.
We use modern technology that has at the very least local symbol autocomplete, presumable (if not, change the technology you use) and also minfiers/JIT compilers so there is no excuse to have a nondescriptive short variabe name, particularly in that context.

PleasingFungus
Oct 10, 2012
idiot asshole bitch who should fuck off

Ronald Raiden posted:

braces aside, please never have a nonsdescriptive variable name, particularly one that is just one letter. What the gently caress is U? Whatever it is, it could be called something meaningful.
We use modern technology that has at the very least local symbol autocomplete, presumable (if not, change the technology you use) and also minfiers/JIT compilers so there is no excuse to have a nondescriptive short variabe name, particularly in that context.

U is U(niverse/al); it's where the shameful globals live, all my poor design decisions come to roost in one place

I'm not aware of any way to have actual globals in this language, so I dumped them into a class as static members & referenced them by as short a name as possible

the good news is, it's a personal project which literally no one else will ever touch

(unless some maniac decides to mess around with it after I open-source it, in which case, good luck!)

so

Doc Block
Apr 15, 2003
Fun Shoe
Don't use global variables, problem solved.

a cyberpunk goose
May 21, 2007

Doc Block posted:

Don't use global variables, problem solved.

use singletons intead :getin:

Squinty Applebottom
Jan 1, 2013

use monads. monads are a thing, right?

Cold on a Cob
Feb 6, 2006

i've seen so much, i'm going blind
and i'm brain dead virtually

College Slice
yo leaving out braces is fine as long as you indent

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Jabor posted:

its funny because even in C# you still need to handle the exception when you open a file that doesn't exist, because someone could have deleted it after you checked for it but before you actually opened it

that's every programming environment

never check to see if something will work, do something and check to see if it failed

Cold on a Cob
Feb 6, 2006

i've seen so much, i'm going blind
and i'm brain dead virtually

College Slice

Cocoa Crispies posted:

check to see if something will work, do something and check to see if it failed

:colbert:

(though i guess if ur lucky enough to be using a language where exceptions aren't expensive as gently caress u can skip the first part)

Cold on a Cob
Feb 6, 2006

i've seen so much, i'm going blind
and i'm brain dead virtually

College Slice
no but seriuosly the answer is, and always is, understand your tools and how they work and code what makes sense in the moment

if you're processing 10 million files per day and they are always there and only one day two years ago a file was missing because some idiot cj deleted it from under your job, sure don't check in advance because it's wasted cycles

conversely if you're converting 10 million strings per day into numbers and roughly 1% of them won't convert and when they don't you put in a -1, use something like tryparse or isnumeric assuming it's faster than exception handling with the tools you use

Bloody
Mar 3, 2013

or just don't sweat the small stuff because you're probably already coding in some horrible slow plang anyways

Squinty Applebottom
Jan 1, 2013

ruby is neither slow nor horrible

Doc Block
Apr 15, 2003
Fun Shoe
LOL wrong

qntm
Jun 17, 2009

prefect posted:

never allow people to omit braces on for/if statements :colbert:

but but but K&R!!!

Ericadia
Oct 31, 2007

Not A Unicorn

Cold on a Cob posted:

yo leaving out braces is fine as long as you indent

Yeah I think it looks better this way tbh. When I see braces I think multiple statements.

double sulk
Jul 2, 2010

polpotpi posted:

ruby is neither slow nor horrible


Doc Block
Apr 15, 2003
Fun Shoe

Ericadia posted:

Yeah I think it looks better this way tbh. When I see braces I think multiple statements.

What happens when you add a statement but forget to add the braces?

Ericadia
Oct 31, 2007

Not A Unicorn

Doc Block posted:

What happens when you add a statement but forget to add the braces?

I'm not sure what other compilers do but using LLVM/clang with sublime text spits out "expected } before 'else'" for if statements.

I get your point though, avoid the failure in the first place

Cold on a Cob
Feb 6, 2006

i've seen so much, i'm going blind
and i'm brain dead virtually

College Slice

Doc Block posted:

What happens when you add a statement but forget to add the braces?

same as when u accidentally use assignment instead of checking for equality in an if statement: poo poo breaks because terrible programmer wasn't careful (i'm being nice b/c this is a safe zone for terrible programmers)

Armourking
Dec 16, 2004

Step off!
Step off!


spent an afternoon tracking down a bugge that was due 2 not practicing good code re-use
lesson learned

Adbot
ADBOT LOVES YOU

X-BUM-RAIDER-X
May 7, 2008

AWWNAW posted:

how about a true life terrible programmer story

found a painful bug in production yesterday written by a "senior developer" coworker

code:
object integerValue = datagridrow[hardcodednumber].value;
object oldIntegerValue = datagridrow[anotherhardcodednumber].value;
if (integerValue == oldIntegerValue)
{
    DoNeedful();
}
can any of yout errible programmers tell me why needful never gets done

i hope this post makes you a better program

shalom

who loving cares

  • Locked thread