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
Max Facetime
Apr 18, 2009

instead of using option types and sprinkling error recovery code all over the place, why not use a singleton varying type to centralize error handling and correction into just one place?

Adbot
ADBOT LOVES YOU

hepatizon
Oct 27, 2010

tef posted:

in ruby parlance, a dsl is what they call libraries.


excel.

my job involves non-programmers writing highly abstract ruby in spreadsheets :getin:

Notorious b.s.d.
Jan 25, 2003

by Reene

Max Facetime posted:

instead of using option types and sprinkling error recovery code all over the place, why not use a singleton varying type to centralize error handling and correction into just one place?

wouldn't this just be exceptions again

Zlodo
Nov 25, 2006
the main rationale behind "exceptions should be used only for truly exceptional cases" is pretty simple: exception handling is slow.

I dunno how they are implemented in java but in c++ the way they work on a decent compiler (ie not vc++) is that when the exception is thrown a bunch of lookup tables are used to unwind the call stack and find out which objects need to be destructed until a suitable handler is found to catch the exception.

(vc++ just pushes and pop exception handlers on the stack during the normal execution flow so it slows you down even when you don't throw. Good job by microsoft as always)

so basically if you are at least slightly concerned about performance you shouldn't use exceptions for things that are expected to happen during a normal execution of your program

for instance imagine you can load config files or plugins from multiple location, like you try the current dir first, then a user specific location, then a system location. you try loading your thing from all these places and a lot of failures are expected. if you use exceptions for that you'll have a bunch of them thrown every time although nothing bad is actually happening that justifies using such a costly mechanism

unixbeard
Dec 29, 2004

Flaming June posted:

i'm not interested in writing an os or anything like that. i've just been a windows user for most of my life and now am in the, erm, wonderful world of unix. it isn't so much that i want to just learn a lot about unix, but the experience open ups a horizon that there are many ways to do even simple stuff in the background. i find it to be kind of cool in a nerdy way

This is the best book if you want to learn about how unix works http://www.amazon.com/Programming-Environment-Addison-Wesley-Professional-Computing/dp/0321525949 ignore the advanced part though, it gets into details for sure, but starts off pretty introductory

Condiv
May 7, 2008

Sorry to undo the effort of paying a domestic abuser $10 to own this poster, but I am going to lose my dang mind if I keep seeing multiple posters who appear to be Baloogan.

With love,
a mod


Zlodo posted:

the main rationale behind "exceptions should be used only for truly exceptional cases" is pretty simple: exception handling is slow.

I dunno how they are implemented in java but in c++ the way they work on a decent compiler (ie not vc++) is that when the exception is thrown a bunch of lookup tables are used to unwind the call stack and find out which objects need to be destructed until a suitable handler is found to catch the exception.

(vc++ just pushes and pop exception handlers on the stack during the normal execution flow so it slows you down even when you don't throw. Good job by microsoft as always)

so basically if you are at least slightly concerned about performance you shouldn't use exceptions for things that are expected to happen during a normal execution of your program

for instance imagine you can load config files or plugins from multiple location, like you try the current dir first, then a user specific location, then a system location. you try loading your thing from all these places and a lot of failures are expected. if you use exceptions for that you'll have a bunch of them thrown every time although nothing bad is actually happening that justifies using such a costly mechanism

I recently read exception handling is drat slow in java too. Pretty much if you have an error you can recover from, return it with an Either or something from your function or your code will perform like crap.

Condiv fucked around with this message at 09:57 on Aug 30, 2013

unixbeard
Dec 29, 2004

the cost of exceptions

is too drat high!!!

lol

Deus Rex
Mar 5, 2005

at my old PHP job I shaved like 300 ms off the average response time for a bunch of web API endpoints. how? an API endpoint specified its parameters with something like:

PHP code:
$id = Param::required(Param::Id, "id");
$butt_name = Param::optional(Param::String, "butt_name");
$butt_size = Param::optional(Param::Int, "butt_size");
/* etc... */
the implementation of Param::optional was something like:

PHP code:
class Param {
  private static function get($arr, $type, $name) {
    if (array_key_exists($name, $arr)) {
      /* do some poo poo to coerce $val into the type idk */
      $val = $arr[$name];
      return $arr[$name];
    } else {
      throw new ApiExceptions\MissingParam();
    }
  }

  public static function optional($type, $name) {
    try {
      return get($_GET, $type, $name);
    } catch (Exception $e) {
      return NULL;
    }
  }
}
you might wonder why a couple optional parameter lookups (and consequent exception throws/catches) per request added 300ms to the response time. as it turned out, the omakase DB conn/query object written by our senior developers had like 50 debug statements to dump information about the conn/query/whatever.

PHP code:
class Mysql {
  private function _somethingCalledSometimesHundredsOfTimesPerEndpoint() {
    /* ... */
    Debug::dump("mysql and php are omakase");
  }
}
and the loving impl of Debug::dump, loving of course:

PHP code:
class Debug {
  public static function dump($str) {
    $debugMode = Param::optional(Param::bool, "debug");
    if ($debugMode && self::someOtherStuff()) {
      self::logThatShit($str);
    }
  }
}
so that's how i learned that php also has agonizingly slow exceptions! (and also that the senior developers had never not once profiled anything)

Deus Rex fucked around with this message at 10:27 on Aug 30, 2013

unixbeard
Dec 29, 2004

cool web development story

a nest of hornets
Nov 17, 2012

by Ralp

unixbeard posted:

the cost of exceptions

is too drat high!!!

lol

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

Zlodo posted:

for instance imagine you can load config files or plugins from multiple location, like you try the current dir first, then a user specific location, then a system location. you try loading your thing from all these places and a lot of failures are expected. if you use exceptions for that you'll have a bunch of them thrown every time although nothing bad is actually happening that justifies using such a costly mechanism

in this case, would The Right Thing be to throw an exception only when there are zero config files?

unixbeard posted:

cool web development story

i thought so, too :)

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

prefect posted:

in this case, would The Right Thing be to throw an exception only when there are zero config files?
depends on context. like, are they config files the program put there itself on install? if the user has gone into the program directory and deleted them, i'd consider that exceptional behaviour.

if they're config files that won't be there if the user forgot to install some dependency, that's the kind of thing you should see coming.

Shaggar
Apr 26, 2006
You test for the existence and read/write-ability of the file before read/writing it, but sometimes things happen after that check so you'll have to handle a potential i/o exception.

In the case of loading configs from multiple places you'd be fine to ignore non-existence until you get to the last location assuming the config is required to run the program.

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band
what if one of the files turns out to be all mangled with binary non-text data in it? do you blow up there, or do you keep moving down the config-file tree?

Shaggar
Apr 26, 2006
You'd have to decide how you want to deal with it. Generally if a user config is corrupt you probably want to make it known you couldn't load it cause they're expecting it to be used either thru ui if you have one or by logging and exiting. Otherwise they're gonna assume its running with their config when its actually running with another and that could cause problems.

That won't always be the case of course so figure it out during your design phase.

Shaggar
Apr 26, 2006
I it has a ui you should help them recreate the config right there instead of exiting.

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

Shaggar posted:

You'd have to decide how you want to deal with it. Generally if a user config is corrupt you probably want to make it known you couldn't load it cause they're expecting it to be used either thru ui if you have one or by logging and exiting. Otherwise they're gonna assume its running with their config when its actually running with another and that could cause problems.

That won't always be the case of course so figure it out during your design phase.

what's your opinion on machine.config files? (i kinda want to murder them, but maybe i had bad experiences)

Shaggar
Apr 26, 2006
I had not heard of it before now. Anything that would go there would probably be fine in a shared system config in like program data or w/e. I wouldn't want to share a config file with other apps cause someone's gonna think they're special and not use the API to edit it and break it. The registry would be also be a better spot since there's no non-API access and it does the same thing.

Lastly you could also load configs from a central source based on application and machine id.

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

Shaggar posted:

I had not heard of it before now. Anything that would go there would probably be fine in a shared system config in like program data or w/e. I wouldn't want to share a config file with other apps cause someone's gonna think they're special and not use the API to edit it and break it. The registry would be also be a better spot since there's no non-API access and it does the same thing.

Lastly you could also load configs from a central source based on application and machine id.

well, in this situation, the stuff we put in machine.config was mostly connection-string data so the systems knew where the central source was

Brain Candy
May 18, 2006

also, the other things about exceptions being too slow

1) You don't care
2) You care because the profiler said so
3) If the profiler said so, a ton of bad things are probably happening in your code
4) and they're in the structure of your program

"x is slow" is usually given without context to make it useful, and I'm not a fan, no sir.

MononcQc
May 29, 2007

use a language with proper exception support :smug:

if your exceptions are so slow people fear to use them for what they were semantically meant for, they're poo poo :smuggo:

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

MononcQc posted:

use a language with proper exception support :smug:

if your exceptions are so slow people fear to use them for what they were semantically meant for, they're poo poo :smuggo:



well what they're semantically meant for is the bone of contention, isn't it? and really i think that argument comes largely from whether you prefer the devil of having the normal "happy path" control flow of a program obscured by error handling details, or the devil of having a non-local return obscure what the hell happens when something goes wrong.

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
ps czech out what one of the lil babbys at my alma mater is doin http://rcos.rpi.edu/project/smith-language/post/project-proposal-smith-language/ apparently its his third shot at doing a compiler. on the mailing list for the funding entity there have been good discussions, i teased out of him that internally it's a forth as i suspected as opposed to a paren-less lisp :3:

tef
May 30, 2004

-> some l-system crap ->

Otto Skorzeny posted:

well what they're semantically meant for is the bone of contention, isn't it? and really i think that argument comes largely from whether you prefer the devil of having the normal "happy path" control flow of a program obscured by error handling details, or the devil of having a non-local return obscure what the hell happens when something goes wrong.

don't you understand, exceptions are for whatever purpose I was told to use them for

tef
May 30, 2004

-> some l-system crap ->
a quick survey, who has read the paper on exceptions ?

quote:

In short, exceptions and exception handling mechanisms are not needed just to deal with errors. They are needed, in general, as a means of conveniently interleaving actions belonging to different levels of abstraction [2-7]. They are not necessarily rarely activated. For example, in their use in dealing with result classification, they might be activated on every invocation of an opera- tion. In their use in monitoring operations and receiving intermediate results, an exception might occur many times for a single invocation of the operation. Exception handling notations that imply a fixed implementation technique are therefore not suited for dealing with the complete range of exception requirements.

christ, programmers

Jonny 290
May 5, 2005



[ASK] me about OS/2 Warp
now i just might be an ignorant perl coder but isnt it a bad idea to use exceptions for non-error control flow?

tef
May 30, 2004

-> some l-system crap ->

quote:

eh, exceptions in modern languages are overloaded language features, doing a number of things:

- non local exits
- error handling (both of the recoverable and unrecoverable types)
- semipredicate problem (cf "0 but true", option types, python's generator protocol)

(aside: exceptions are overloaded much in the same way java decided to mash subclassing and code-reuse together, rather than say having separate features for each like traits and mixins.)

if you read higher order perl (or you know what "0 but true" is for in Perl), you'd know what the semipredicate problem is and how exceptions can be used

Shaggar
Apr 26, 2006

prefect posted:

well, in this situation, the stuff we put in machine.config was mostly connection-string data so the systems knew where the central source was

I would put it in web.config or app.config instead. Or something custom in programdata.

tef
May 30, 2004

-> some l-system crap ->
this sorta dogma ridden hand writing over a confused language feature is possibly why go didn't include them

tef
May 30, 2004

-> some l-system crap ->
let's break from the usual pattern and argue about something different to what we argued about last month

Shaggar
Apr 26, 2006
Exceptions aren't confusing in java and they're only slightly confusing in c#.

Jonny 290
May 5, 2005



[ASK] me about OS/2 Warp

tef posted:

let's break from the usual pattern and argue about something different to what we argued about last month

tab stops maybe?

unixbeard
Dec 29, 2004

is the term 'white space' inherently exclusionary?

tef
May 30, 2004

-> some l-system crap ->
unicode, we haven't done unicode in a while

double sulk
Jul 2, 2010

gofmt -w [filename] supremacy

tef
May 30, 2004

-> some l-system crap ->
how about timezones

dst?

calendaring?


the twepoch

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

unixbeard posted:

is the term 'white space' inherently exclusionary?

i use black backgrounds in my editors, but i've been saying "white space" all this time :aaaaa:

double sulk
Jul 2, 2010

trailing white space is the worst white space

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

gucci void main posted:

trailing white space is the worst white space

a proper editor can be set up to remove that :black101:

Adbot
ADBOT LOVES YOU

double sulk
Jul 2, 2010

prefect posted:

a proper editor can be set up to remove that :black101:

yeah

square released some auto vim setup thing but it borks my vim to not work. probably another dumb 10.9/clang issue though

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