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
tef
May 30, 2004

-> some l-system crap ->

MononcQc posted:

Also mandatory post on optional type checking I make every time this debate comes on.

mandatory quote, also standard mention of http://sage.soe.ucsc.edu

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->

Shaggar posted:

java is a good language that makes it easy to do things correctly and outright prevents the worst programming offenses

java saves you from some of the mistakes coders make in C, like buffer overflow, and segfaulting, but doesn't save you from all of them, like memory leaks, resource leaks, and integer overflow. atop of this, java also doesn't save you from the mistakes people make in java, which are many. there is a reason why "effective java" is so big.

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

pseudorandom name posted:

preferably signaling.

i've never met anyone who's ever encountered a snan in the wild in any context

Innocent Bystander
May 8, 2007
Born in the LOLbarn.

tef posted:

no it just means you find it difficult to show off

and you've never worked with someone with a phd who likes dropping 25,000 lines of code into a project over a weekend.

i've been "on a roll" before, but never 25k loc on a roll, drat. Was his secret this?

code:
cat /dev/random > tef.pl
that might work.

Bloody
Mar 3, 2013

*farts out thousands of lines of auto-generated code* 10x developer yopos bith

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Otto Skorzeny posted:

i've never met anyone who's ever encountered a snan in the wild in any context

hi, come here often? i'm your host for "some rear end in a top hat plugin changed the signaling mode for your whole application" theatre.

Shaggar
Apr 26, 2006

tef posted:

java saves you from some of the mistakes coders make in C, like buffer overflow, and segfaulting, but doesn't save you from all of them, like memory leaks, resource leaks, and integer overflow. atop of this, java also doesn't save you from the mistakes people make in java, which are many. there is a reason why "effective java" is so big.

you can just tell eclipse "find my leaks" and eclipse will do it for you.

Shaggar
Apr 26, 2006
I like using/idisposable in c# a lot its another thing that c# looked at java and said "ok, that makes sense but lets do it better".

Shaggar
Apr 26, 2006
also regarding the "end-to-end" principle or whatever dumb crap, even if code at a higher level cant immediately resolve an exception, sometimes it can add more useful information that can help further up the stack. This is especially true for exceptions that will require human intervention to resolve like a file being missing or w/e.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Shaggar posted:

also regarding the "end-to-end" principle or whatever dumb crap, even if code at a higher level cant immediately resolve an exception, sometimes it can add more useful information that can help further up the stack. This is especially true for exceptions that will require human intervention to resolve like a file being missing or w/e.

yes, log-and-propagate can be helpful, too bad you end up with everything wrapped in void * RuntimeException. But "recoverable" and "can add some context" aren't the same, and I don't think the "better be able to recover or what are you some retarded savage" line of argument extends well to annotating things as they pass through.

(what does "RuntimeException" mean, anyway? it's not like others are generated statically or something, and the VM internals are hardly the only source of them)

Shaggar
Apr 26, 2006
no you don't, it ends up getting wrapped in an exception that's part of the higher level api.

RuntimeException and anything that inherits from it (ex: NullPointerException, ArrayOutOfBoundsException) are treated as unchecked exceptions. They are intended to be used only to describe code faults like "hey, idiot, you forgot to check for null" or "hey, idiot, you off by oned your loop variable".

if you extend runtimeexception yourself you should probably be murdered.

JewKiller 3000
Nov 28, 2006

by Lowtax

Shaggar posted:

you can just tell eclipse "find my leaks" and eclipse will do it for you.

no it won't that's undecidable, eclipse is great but come on shaggar.

also lol that being able to forget to check for null and explicit loop index variables are still things in supposedly modern java in tyool 2014

Shaggar
Apr 26, 2006
eclipse will warn you if you forget to close streams and stuff. also theres a memory leak plugin that is really good, but I haven't had to use it in forever.

Soricidus
Oct 21, 2010
freedom-hating statist shill
eclipse supports java nullability annotations pretty well these days

unfortunately they're pointless because none of the standard library has them, so the moment you use one you have to start adding all kinds of stupid assertions to tell the compiler that no, seriously, StringBuilder.toString() is probably never going to return null

zokie
Feb 13, 2006

Out of many, Sweden

Shaggar posted:

sometimes

gee it sure would be nice to not jump through hoops for a bunch of sometimes. I mean, given a "good" architecture littered with abstractions and facades were an exception occurs and the origin of the request can be quite distant and while the layers inbetween can sometimes provide some information a lot of the time they can't.

I guess I'm Shaggar but instead of hating unions and loving java I love unions and hate java...

Bloody
Mar 3, 2013

zokie posted:

gee it sure would be nice to not jump through hoops for a bunch of sometimes. I mean, given a "good" architecture littered with abstractions and facades were an exception occurs and the origin of the request can be quite distant and while the layers inbetween can sometimes provide some information a lot of the time they can't.

I guess I'm Shaggar but instead of hating unions and loving java I love unions and hate java...

let us call you raggahs

gonadic io
Feb 16, 2011

>>=
today in just starting to mess around with Agda: booleans are a code smell



the idea being that you really should be including some information about what the bool means

are two numbers equal? if not, what's their difference?
is x an element in some structure? if so, then where?
does some server exist at a location? haha just kidding nobody has ever asked this in agda

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

AlsoD posted:

today in just starting to mess around with Agda: booleans are a code smell



the idea being that you really should be including some information about what the bool means

are two numbers equal? if not, what's their difference?
is x an element in some structure? if so, then where?
does some server exist at a location? haha just kidding nobody has ever asked this in agda

wouldn't the information about what the bool means be encoded in the name of the bool

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

AlsoD posted:

today in just starting to mess around with Agda: booleans are a code smell



the idea being that you really should be including some information about what the bool means

are two numbers equal? if not, what's their difference?
is x an element in some structure? if so, then where?
does some server exist at a location? haha just kidding nobody has ever asked this in agda

this is p. interesting, but im not sold on it as a code smell. replacing booleans with more detailed information does major damage to encapsulation - suppose im implementing an equality method, but instead of a boolean i return an object explaining how the two arguments differ. then if at a later date i want to alter my implementation, maintaining the contract with the method's users is much more burdensome than if all was expected out of the method was a single bit.

gonadic io
Feb 16, 2011

>>=

Otto Skorzeny posted:

wouldn't the information about what the bool means be encoded in the name of the bool

this is a similar argument to "why do you need types of values, can't you just encode it in the name?". obv you can do things both ways but the former gives the compiler more leeway to enforce invariants


coffeetable posted:

replacing booleans with more detailed information does major damage to encapsulation

yup! also there's major efficiency concerns too but i don't think maintainability or speed or even being able to run this code are concerns of agda programmers. most people use it as a proof assistant that's got a nicer syntax than coq. idris on the other hand is a different story but i don't know much about that.

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

AlsoD posted:

obv you can do things both ways but the former gives the compiler more leeway to enforce invariants

i don't see how making every predicate function return an enumerated type rather than a bool gives the same sort of net gain that you might get from having separate types for kelvin and celsius temps or separate types for escaped and unescaped strings though. eg. i've seen bugs caused by passing a float representing a pressure in inhg@20c to a function expecting a float representing a pressure in psi which could be avoided with a more expressive type system, but i've never seen a bug caused by passing a boolean representing "yes turn that pin on" to a function expecting a boolean representing whether the ADC should be on

shrughes
Oct 11, 2008

(call/cc call/cc)

Otto Skorzeny posted:

i've never seen a bug caused by passing a boolean representing "yes turn that pin on" to a function expecting a boolean representing whether the ADC should be on

I have. And it certainly makes the code more readable to pass expired::YES and expired::NO than to pass some "true" and "false" value where true means one of expired or unexpired. But that's not precisely what these Adgans are talking about.

Shaggar
Apr 26, 2006

zokie posted:

gee it sure would be nice to not jump through hoops for a bunch of sometimes. I mean, given a "good" architecture littered with abstractions and facades were an exception occurs and the origin of the request can be quite distant and while the layers inbetween can sometimes provide some information a lot of the time they can't.

I guess I'm Shaggar but instead of hating unions and loving java I love unions and hate java...

most of the importance of checked exceptions is in letting you know they can happen so you can plan for them instead of having your code die unexpectedly. ex: even if you don't even try to handle the exception, you may want to clean up something you were doing. if you cant do anything with them or cant add information, then don't. just throw. its not a big deal

but obviously the idea of doing the right thing doesn't mesh with your programming style. its not surprising you like unions

Bloody
Mar 3, 2013

sorry shags but unions are good things

MononcQc
May 29, 2007

AlsoD posted:

today in just starting to mess around with Agda: booleans are a code smell



the idea being that you really should be including some information about what the bool means

are two numbers equal? if not, what's their difference?
is x an element in some structure? if so, then where?
does some server exist at a location? haha just kidding nobody has ever asked this in agda

I like to call it booleanitis. P-langs have stringitis (everything is a string), and languages which can't represent some abstract datatypes well enough have booleanitis. This shows up a lot when you end up having more than two choice and they no longer map very well to booleans.

Instead of having a traffic light with 'is_red(Light)', 'is_yellow(Light)', 'is_green(Light)', you should have 'color(Light) -> green | red | yellow', for example.

Enums are a way to help fix this, but you always have to be careful that the Enums are: serialized safely, unserialized safely, won't have clashing values (or will be type checked), etc.
The other ways I've seen it done were through Erlang/Prolog atoms or Lisp symbols, or through types in good type systems (Haskell's and other MLs').

Shaggar
Apr 26, 2006
java enums are really good

gonadic io
Feb 16, 2011

>>=

Shaggar posted:

java enums are really good

abstract data types are a million times better than enums

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Shaggar posted:

most of the importance of checked exceptions is in letting you know they can happen so you can plan for them instead of having your code die unexpectedly. ex: even if you don't even try to handle the exception, you may want to clean up something you were doing. if you cant do anything with them or cant add information, then don't. just throw. its not a big deal

The type system doesn't tell you enough to plan for what to do, so you still have to read the documentation (or source) to figure out exactly what state you are in once you get an exception back. So at that point you basically just want the C++ nothrow protocol, and in Java that's meaningless because of RuntimeExceptions, so...

"Making people think about it" feels to me more like making users click through a browser security warning: they'll do whatever to shut it up, but you can blame the user afterwards for being dumb! Then it *looks* like it's handled, which is even worse than it unraveling to the top and fataling out the app in many cases. People who are diligent will do the right thing with checked exceptions, but they'd do the right thing anyway because they're diligent. People who aren't will effectively stomp out the compiler error like they're clicking through a EULA or browser security dialog. When they're first writing that code they haven't started to think about error handling yet anyway, so they just want it out of the way so that they can see if the main path works.

It seems that there's some confusion about the correct use of booleans; luckily I am here to explain the truth. Booleans are for storing the results of logical operations, and use as positively-named properties (gently caress off "isDisabled"). They should not appear as parameters. Please govern yourselves accordingly.

gonadic io
Feb 16, 2011

>>=

Subjunctive posted:

[Booleans] should not appear as parameters.

What do you mean by "parameters" in this context?

Sapozhnik
Jan 2, 2005

Nap Ghost
Which of these is clearer?

var x = new Dictionary(false, true);

or

var x = new Dictionary(SortOrder.ASCENDING, DictionaryComparison.CASE_INSENSITIVE);

?

(to give a particularly contrived example)

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

AlsoD posted:

What do you mean by "parameters" in this context?

C++ code:
/* get out */
void DoAThing(bool quickly, bool withLogging);

/* get in */
enum speed { QUICKLY, SLOWLY };
enum loglevel { WITH_LOGGING, WITHOUT_LOGGING};
void DoAThing(speed theSpeed, loglevel theLogLevel);
I used to eschew the extra typing, but every time I see a call site that's like this instead, I am glad:

C++ code:
DoAThing(QUICKLY, WITH_LOGGING);
There's the extensibility smoothness too (VERBOSE_LOGGING), but mostly I like being able to understand what I'm reading without remembering what order the booleans are in or going to the header file each time.

Shaggar
Apr 26, 2006

Subjunctive posted:

The type system doesn't tell you enough to plan for what to do, so you still have to read the documentation (or source) to figure out exactly what state you are in once you get an exception back. So at that point you basically just want the C++ nothrow protocol, and in Java that's meaningless because of RuntimeExceptions, so...

"Making people think about it" feels to me more like making users click through a browser security warning: they'll do whatever to shut it up, but you can blame the user afterwards for being dumb! Then it *looks* like it's handled, which is even worse than it unraveling to the top and fataling out the app in many cases. People who are diligent will do the right thing with checked exceptions, but they'd do the right thing anyway because they're diligent. People who aren't will effectively stomp out the compiler error like they're clicking through a EULA or browser security dialog. When they're first writing that code they haven't started to think about error handling yet anyway, so they just want it out of the way so that they can see if the main path works.

It seems that there's some confusion about the correct use of booleans; luckily I am here to explain the truth. Booleans are for storing the results of logical operations, and use as positively-named properties (gently caress off "isDisabled"). They should not appear as parameters. Please govern yourselves accordingly.

as someone who likes checked exceptions i hate c#'s unchecked exceptions because i have to handle them by hand rather than letting the ide help me handle them. for people who don't care i don't care about them. they're going to gently caress everything up no matter which way exceptions work so I'd rather have them work the way I like in both places.

Shaggar
Apr 26, 2006
the compromise that would work for everyone i think would be for the compiler to automatically add throws to the end of methods that internally call methods that throw things that aren't handled.

so like in

C# code:

void MethodThatExplicitlyThrows() throws Exception
{
	//some dangerous stufff
}

void MethodThatImplicitlyThrows()
{
	MethodThatExplicitlyThrows()
}

the compiler would add the throws declaration to the second method automatically so it shows up whenever that method is used.

Soricidus
Oct 21, 2010
freedom-hating statist shill

Subjunctive posted:

"Making people think about it" feels to me more like making users click through a browser security warning: they'll do whatever to shut it up, but you can blame the user afterwards for being dumb! Then it *looks* like it's handled, which is even worse than it unraveling to the top and fataling out the app in many cases. People who are diligent will do the right thing with checked exceptions, but they'd do the right thing anyway because they're diligent. People who aren't will effectively stomp out the compiler error like they're clicking through a EULA or browser security dialog. When they're first writing that code they haven't started to think about error handling yet anyway, so they just want it out of the way so that they can see if the main path works.
the thing about checked exceptions is that they provide a useful tool to help diligent but merely human coders avoid mistakes.

are poo poo coders going to catch (Exception ex) {}? sure, but at least that gives me a clear indication that i'm looking at poo poo code. without checked exceptions it might not be so visible.

the same goes for all the other features that some people reject because they can be subverted by idiots. like private members, say. "oh you don't need private members, they're pointless because some idiot can always access them through reflection." i don't give a gently caress, the point of them isn't to stop idiots writing poo poo code, it's to tell my tools what the public api is ... and if i see code using reflection to access a private member i know i'm looking at purestrain poo poo.

Shaggar
Apr 26, 2006
^

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Soricidus posted:

the thing about checked exceptions is that they provide a useful tool to help diligent but merely human coders avoid mistakes.

I get that, and I'm sympathetic to it. I think that an IDE telling you about unhandled things that appear in @throws annotations would be great. I just don't like the ergonomics of Java's checked exceptions, because they motivate you to do *something* right now when you're likely not thinking about the code that way, and then you have to go back and check all the cases again anyway to see if you actually did the right thing or were just shutting it up so you could try something out. And then the IDE *can't* help you, because you've got this stub handling all over.

I used to be a believer, but when I watched how I actually interacted with them (and I was definitely trying to be diligent, and I'm pretty sure I'm on the right-hand side of the coding bell curve), I started to really feel that they pushed unhelpfully.

We can still be friends, though.

Breakfast All Day
Oct 21, 2004

this conversation is too reasonable and well informed for yospos, either take it offsite or get tbc to start posting again

Scaevolus
Apr 16, 2007

Subjunctive posted:

I used to eschew the extra typing, but every time I see a call site that's like this instead, I am glad:

C++ code:
DoAThing(QUICKLY, WITH_LOGGING);
There's the extensibility smoothness too (VERBOSE_LOGGING), but mostly I like being able to understand what I'm reading without remembering what order the booleans are in or going to the header file each time.

C++11 adds enum classes that add proper scoping and type checking to the mix (you can't just pass an int!)
code:
/* get in */
enum class Speed { QUICK, SLOW };
enum class LogLevel { ON, OFF };
void DoAThing(Speed theSpeed, LogLevel theLogLevel);

/* OK */
DoAThing(Speed::QUICK, LogLevel::ON);

/* Compile error */
DoAThing(LogLevel::ON, Speed::QUICK);
DoAThing(Speed::QUICK, 1);
also this is something that smalltalk solves by forcing you to name all of your parameters when you invoke a function :haw:

MononcQc
May 29, 2007

Now imagine if Enums were values ~on their own~ and could be considered their own data type? Welcome to Prolog, Welcome to Erlang, Welcome to Lisp!

Now imagine if instead of being their own type, they were actually types? Welcome to Haskell, Welcome to OCaml, Welcome to F#, Welcome to SML, etc!

Adbot
ADBOT LOVES YOU

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

MononcQc posted:

Now imagine if Enums were values ~on their own~ and could be considered their own data type? Welcome to Prolog, Welcome to Erlang, Welcome to Lisp!

Now imagine if instead of being their own type, they were actually types? Welcome to Haskell, Welcome to OCaml, Welcome to F#, Welcome to SML, etc!

f# fakes it by bolting it on over sealed classes since the clr is bad but not jvm bad

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