|
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
|
# ? Apr 25, 2014 02:04 |
|
|
# ? May 31, 2024 15:35 |
|
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.
|
# ? Apr 25, 2014 02:15 |
|
pseudorandom name posted:preferably signaling. i've never met anyone who's ever encountered a snan in the wild in any context
|
# ? Apr 25, 2014 02:55 |
|
tef posted:no it just means you find it difficult to show off i've been "on a roll" before, but never 25k loc on a roll, drat. Was his secret this? code:
|
# ? Apr 25, 2014 04:08 |
|
*farts out thousands of lines of auto-generated code* 10x developer yopos bith
|
# ? Apr 25, 2014 04:09 |
|
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.
|
# ? Apr 25, 2014 04:41 |
|
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.
|
# ? Apr 25, 2014 05:05 |
|
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".
|
# ? Apr 25, 2014 05:05 |
|
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.
|
# ? Apr 25, 2014 05:08 |
|
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 (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)
|
# ? Apr 25, 2014 05:16 |
|
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.
|
# ? Apr 25, 2014 05:20 |
|
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
|
# ? Apr 25, 2014 05:24 |
|
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.
|
# ? Apr 25, 2014 05:43 |
|
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
|
# ? Apr 25, 2014 07:22 |
|
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...
|
# ? Apr 25, 2014 07:30 |
|
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. let us call you raggahs
|
# ? Apr 25, 2014 18:08 |
|
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
|
# ? Apr 25, 2014 19:07 |
|
AlsoD posted:today in just starting to mess around with Agda: booleans are a code smell wouldn't the information about what the bool means be encoded in the name of the bool
|
# ? Apr 25, 2014 19:16 |
|
AlsoD posted:today in just starting to mess around with Agda: booleans are a code smell 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.
|
# ? Apr 25, 2014 19:30 |
|
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.
|
# ? Apr 25, 2014 19:35 |
|
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
|
# ? Apr 25, 2014 19:44 |
|
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.
|
# ? Apr 25, 2014 19:46 |
|
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. 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
|
# ? Apr 25, 2014 19:56 |
|
sorry shags but unions are good things
|
# ? Apr 25, 2014 20:03 |
|
AlsoD posted:today in just starting to mess around with Agda: booleans are a code smell 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').
|
# ? Apr 25, 2014 20:08 |
|
java enums are really good
|
# ? Apr 25, 2014 20:11 |
|
Shaggar posted:java enums are really good abstract data types are a million times better than enums
|
# ? Apr 25, 2014 20:15 |
|
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.
|
# ? Apr 25, 2014 20:33 |
|
Subjunctive posted:[Booleans] should not appear as parameters. What do you mean by "parameters" in this context?
|
# ? Apr 25, 2014 20:49 |
|
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)
|
# ? Apr 25, 2014 20:54 |
|
AlsoD posted:What do you mean by "parameters" in this context? C++ code:
C++ code:
|
# ? Apr 25, 2014 20:57 |
|
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... 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.
|
# ? Apr 25, 2014 20:59 |
|
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:
|
# ? Apr 25, 2014 21:09 |
|
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. 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.
|
# ? Apr 25, 2014 21:13 |
|
^
|
# ? Apr 25, 2014 21:16 |
|
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.
|
# ? Apr 25, 2014 22:07 |
|
this conversation is too reasonable and well informed for yospos, either take it offsite or get tbc to start posting again
|
# ? Apr 25, 2014 22:10 |
|
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++11 adds enum classes that add proper scoping and type checking to the mix (you can't just pass an int!) code:
|
# ? Apr 25, 2014 23:11 |
|
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!
|
# ? Apr 25, 2014 23:51 |
|
|
# ? May 31, 2024 15:35 |
|
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! f# fakes it by bolting it on over sealed classes since the clr is bad but not jvm bad
|
# ? Apr 25, 2014 23:57 |