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
Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

No Safe Word posted:

http://www.diogonunes.com/blog/custom-build-configurations-visualstudio/

How not to use build configurations with Visual Studio :doh:

I mean, yeah that's how you set them up. But it's not what they're for.

code:
#if   RELEASE_CLIENT_ABC
    bool _isDebug = false;
    Organization _currentOrg = new ClientABC();
#elif RELEASE_CLIENT_XYZ
    bool _isDebug = false;
    Organization _currentOrg = new ClientXYZ();
#elif RELEASE
    bool _isDebug = false;
    Organization _currentOrg = new DevTest();
#else
    bool _isDebug = true;
    Organization _currentOrg = new DevTest();
#endif
:sigh:

I sort of did this with an iOS app, back before IAP when the way to let people purchase "consumables" was to distribute multiple versions of an app at different prices.

Adbot
ADBOT LOVES YOU

Mellow_
Sep 13, 2010

:frog:

GrumpyDoctor posted:

"This so-called 'problem' isn't a problem because you can just bolt your own conceptual constraints on top of the language and rely, never making any mistakes, on the comprehensive, accurate documentation for any libraries you use."

NOW you're thinkin like shrughes.

sarehu
Apr 20, 2007

(call/cc call/cc)
No really, null pointers/references aren't the big deal people make of them. If you get one you don't expect, it's a bug, and you fix it. If somebody's outputting a value that can be null, they can make a big deal of it, or just don't do that. The mistake is sitting there with your tinfoil hat afraid that everything could be null and is out to get you.

raminasi
Jan 25, 2005

a last drink with no ice
I'm honestly having trouble parodying the idea that because you can fix bugs after they happen, there's no substantial benefit of having language tools that can minimize their presence in the first place.

Soricidus
Oct 21, 2010
freedom-hating statist shill
Yeah, there's really nowhere left to go. Coding horrors? Dunno what you're acting all horrified about, you can just rewrite the code, or maybe try not having horrible code in the first place? Wrap it up programmailures we're done here

sarehu
Apr 20, 2007

(call/cc call/cc)
Did I say there's no substantial benefit? No? Okay then.

I said they're the most overrated problem in software The reason it became this way is, any idiot can understand what a null pointer is and point at it as a problem to make themselves feel smart for being one of those people that know how things really should be. You can see the same kinds of idiots talking about goto statements, tail call optimization [sic], object oriented programming, and functional programming. In fact they're trivial bugs to track down and fix, and preventing them from existing requires designing your language so that it can always force variables to be initialized, which is kind of freaky and inflexible.

Workaday Wizard
Oct 23, 2009

by Pragmatica
It's a pain in the loving rear end is what it is.

euclidian88
Aug 3, 2013
To be fair even Haskell has its own version of null.

Mellow_
Sep 13, 2010

:frog:

Shinku ABOOKEN posted:

It's a pain in the loving rear end is what it is.

I think the most annoying thing about null is constantly checking everything for a potential null status.

E: I don't find NPEs that terrible to debug, but I'm probably just used to the process by now.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
We should all just follow Objective-C's approach: calling a method on nil does nothing and returns zero. If it don't crash, ship it! :v:

sarehu
Apr 20, 2007

(call/cc call/cc)

AuxPriest posted:

I think the most annoying thing about null is constantly checking everything for a potential null status.

You should not need to do this and should not be doing this.

Meat Beat Agent
Aug 5, 2007

felonious assault with a sproinging boner
Just put "if (!this) return ..." at the start of all your member functions, no big deal

fritz
Jul 26, 2003

daft punk railroad posted:

Just put "if (!this) return ..." at the start of all your member functions, no big deal

That's too much typing, stick it in a macro.

ExcessBLarg!
Sep 1, 2001

Flobbster posted:

We should all just follow Objective-C's approach: calling a method on nil does nothing and returns zero.
I like Ruby's middle ground where nil is an object, and so, supports Object's methods (==, to_s, etc.). Combined with its false evaluation boolean context, a fair bit of code is nil safe by default, but you still get a NoMethodError if you do call an unsupported method.

1337JiveTurkey
Feb 17, 2005

Optional types feel half-assed when mixed with parametric polymorphism because while Foo[T] and Foo[Option[T]] may look closely related, they're nothing alike. Any situation where a method could return an Option[T], it should be equally valid to return a T rather than a Some[T]. So if T is covariant with Foo, then Foo[T] should be a subtype of Foo[Option[T]]. But if you want that in Scala for instance, then it needs to be Foo[Some[T]] which seems a tad ridiculous in terms of overhead when I want to use a Foo that always returns a T in a situation that calls for a Foo that may return a T without some sort of shim.

Brain Candy
May 18, 2006

But who shaves the barber?

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Brain Candy posted:

But who shaves the barber?

His wife

Soricidus
Oct 21, 2010
freedom-hating statist shill

sarehu posted:

Did I say there's no substantial benefit? No? Okay then.
The rest of your post essentially does.

sarehu posted:

In fact they're trivial bugs to track down and fix, and preventing them from existing requires designing your language so that it can always force variables to be initialized, which is kind of freaky and inflexible.
No, it just requires designing your language so that it can always distinguish between variables that have definitely been initialised and variables that might not have been.

And if you think they're always simple to track down and fix, well, I envy you your easy life working exclusively on well-written codebases with trivial control flow.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Thermopyle posted:

I dunno, if the volume of posts about null is anything to go by, null is the most serious problem since...Y2K!

yeah, it's just as bad a problem as your posting!!!

Corla Plankun
May 8, 2007

improve the lives of everyone
Is there a paper out there I can read about the negative side of null? I can't glean what's bad about it from the posts in here, just that it is very bad.

What does control flow look like without null? Do you just pick a magic number that signals that something has gone wrong instead, or is a null free world also a world where functions always return exactly what is expected (even when, for example, an api is non responsive?)

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



Corla Plankun posted:

Is there a paper out there I can read about the negative side of null? I can't glean what's bad about it from the posts in here, just that it is very bad.

What does control flow look like without null? Do you just pick a magic number that signals that something has gone wrong instead, or is a null free world also a world where functions always return exactly what is expected (even when, for example, an api is non responsive?)

Look at how Kotlin does it, it has types which have to be explicitly nullable to be assigned the value of null.

In the case of an API being non-responsive that seems like a good place to either throw an exception or explicitly return a type like Java's Optional which forces you to handle whether it was a successful return value or a value indicating an error. Rust has a type called Result I believe which does just that.

Steve French
Sep 8, 2003

sarehu posted:

No really, null pointers/references aren't the big deal people make of them. If you get one you don't expect, it's a bug, and you fix it. If somebody's outputting a value that can be null, they can make a big deal of it, or just don't do that. The mistake is sitting there with your tinfoil hat afraid that everything could be null and is out to get you.

Spoken like a true ruby programmer. Just replace null with literally anything!

robostac
Sep 23, 2009

Corla Plankun posted:

Is there a paper out there I can read about the negative side of null? I can't glean what's bad about it from the posts in here, just that it is very bad.

What does control flow look like without null? Do you just pick a magic number that signals that something has gone wrong instead, or is a null free world also a world where functions always return exactly what is expected (even when, for example, an api is non responsive?)

The control flow can be exactly the same as it's the actual implementation of null that is considered a bad idea. In most languages there isn't any way of signaling that a function is safe to pass null too, which means you have to be sure what every function called expects. You can have all your functions be null safe and check all parameters passed in, but that leads to a large amount of repeated checks and extra code. The alternative is you trust the parameters passed in, but this means you have to be sure that all of your code never passes null. Often you can end up with a mixture and aren't sure whether null is a valid parameter or not.

Option Types(https://en.wikipedia.org/wiki/Option_type) allow the function definition to say whether your function accepts null as a parameter, or if it can return null. If it just returns or accepts a type then that type must be non-null. If it accepts / returns an option<type> then it can be a null or it could have a value. The compiler can then give errors if you ever attempt to access the value contained in the option<type> without checking if it is null.

Another possibility is to use exceptions to signal errors instead of return values.

Steve French
Sep 8, 2003

1337JiveTurkey posted:

Optional types feel half-assed when mixed with parametric polymorphism because while Foo[T] and Foo[Option[T]] may look closely related, they're nothing alike. Any situation where a method could return an Option[T], it should be equally valid to return a T rather than a Some[T]. So if T is covariant with Foo, then Foo[T] should be a subtype of Foo[Option[T]]. But if you want that in Scala for instance, then it needs to be Foo[Some[T]] which seems a tad ridiculous in terms of overhead when I want to use a Foo that always returns a T in a situation that calls for a Foo that may return a T without some sort of shim.

How do you reconcile this at runtime, though? If you have something that depends on a Foo[Option[T]] returning Option[T], and you give it a Foo[T] returning T, what happens when you use that Foo and expect an Option[T] and call map on it, but instead you've been given a T? Does the compiler actually make your Foo[T] into a Foo[Option[T]] for you and wrap all your T instances with Some for you? Not saying this is intractable, just intrigued and wondering how you think it would work out in practice.

At any rate, having that be enforced at compile time is a pretty trivial issue; I've never been frustrated by it and it is really quite easy to just wrap the thing in an Option. I'd personally rather have an easy to fix compile time error than a lurking bug because I forgot an edge case because I'm a mistake-making idiot.

Linear Zoetrope
Nov 28, 2011

A hero must cook

Steve French posted:

Spoken like a true ruby programmer. Just replace null with literally anything!

Replace null with nil!

Tank Boy Ken
Aug 24, 2012
J4G for life
Fallen Rib

Jsor posted:

Replace null with nil!

Replace null with empty!

loinburger
Jul 10, 2004
Sweet Sauce Jones

Steve French posted:

How do you reconcile this at runtime, though? If you have something that depends on a Foo[Option[T]] returning Option[T], and you give it a Foo[T] returning T, what happens when you use that Foo and expect an Option[T] and call map on it, but instead you've been given a T? Does the compiler actually make your Foo[T] into a Foo[Option[T]] for you and wrap all your T instances with Some for you? Not saying this is intractable, just intrigued and wondering how you think it would work out in practice.

At any rate, having that be enforced at compile time is a pretty trivial issue; I've never been frustrated by it and it is really quite easy to just wrap the thing in an Option. I'd personally rather have an easy to fix compile time error than a lurking bug because I forgot an edge case because I'm a mistake-making idiot.

You could probably use an implicit conversion to automatically convert a T into a Some[T], but the fix might be worse than the problem (replace "return Some(t)" with "return t // this nonsense made possible by an implicit conversion!!!")

Kallikrates
Jul 7, 2002
Pro Lurker

Steve French posted:

At any rate, having that be enforced at compile time is a pretty trivial issue; I've never been frustrated by it and it is really quite easy to just wrap the thing in an Option. I'd personally rather have an easy to fix compile time error than a lurking bug because I forgot an edge case because I'm a mistake-making idiot.

Especially in the cases where your release cycle is outside of your control and releasing a patch to a crash is subject to a review process.

FamDav
Mar 29, 2008
Shrughes might be a rape apologist but these are some whacked out opinions on optional types.

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

Tank Boy Ken posted:

Replace null with empty!

Replace your desktop wallpaper with goatse!

brap
Aug 23, 2004

Grimey Drawer

Corla Plankun posted:

Is there a paper out there I can read about the negative side of null? I can't glean what's bad about it from the posts in here, just that it is very bad.

What does control flow look like without null? Do you just pick a magic number that signals that something has gone wrong instead, or is a null free world also a world where functions always return exactly what is expected (even when, for example, an api is non responsive?)

You don't need a paper. Use Swift as an example. If you declare a variable of some type T, it is required to contain a value of that type before it can be used. Once it does, you're good, the compiler lets you access members of that variable with no difficulty.

If you want to declare a variable where it might not contain a value when you access it and that's an acceptable condition, you declare it as an Option type. The language has syntactic sugar to automatically wrap a T that you assign to it into a Some(T) and to take the keyword nil and assign it a None.

The caller can't simply access the members on this Option variable! The caller must either access the Option value safely in a conditional block, use a nil-safe accessor ?. or use a "if this thing is nil, I want the program to crash" ! operator.

This is much, much better than the way C# and Java handle it because it lets the compiler help you make sure you're writing safe code.

Sedro
Dec 31, 2008

loinburger posted:

You could probably use an implicit conversion to automatically convert a T into a Some[T], but the fix might be worse than the problem (replace "return Some(t)" with "return t // this nonsense made possible by an implicit conversion!!!")
also this nonsense
code:
42.getOrElse(7)
for (i <- 3) ...
and if we're going to automatically box T into Option[T], we'd might as well unbox them too. We can just throw an exception if the Option turned out to be None...

Tank Boy Ken
Aug 24, 2012
J4G for life
Fallen Rib
Well this seems like a reasonable help with dealing with null checks: http://blogs.msdn.com/b/jerrynixon/archive/2014/02/26/at-last-c-is-getting-sometimes-called-the-safe-navigation-operator.aspx

Vanadium
Jan 8, 2005

So do we automatically box Option[T] into Option[Option[T]] too?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Vanadium posted:

So do we automatically box Option[T] into Option[Option[T]] too?

Always join your monads.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

Resharper has been updated to support this change too, so if you're on VS 2015 (which supports C#6), anytime it sees "if(foo != null)", it'll offer to change it to foo?.bar.

Adhemar
Jan 21, 2004

Kellner, da ist ein scheussliches Biest in meiner Suppe.

I really hate that they're doing this. I'm worried it will encourage people to keep passing nulls around willy-nilly. It's syntactic sugar to cover up a bigger problem in the code.

In my team we prefer the null object pattern, it works quite well. https://en.wikipedia.org/wiki/Null_Object_pattern

ExcessBLarg!
Sep 1, 2001

Corla Plankun posted:

Is there a paper out there I can read about the negative side of null?
In languages like C or C++ where memory management is manual and references (pointers) are freely manipulated by code, NULL is just a conventionally agreed-on invalid pointer that (on systems with memory protection) traps when you accidentally dereference it. Not to say that there aren't better ways to handle situations where NULL is traditionally used in these languages, but it's well understood that there's many ways to shoot yourself in the foot, so don't do that.

A language like Java, however, by using garbage collection, bounds checking, opaque references, and compiler-enforced type checking, invalid references (where valid means the reference always points to an object that implements the interface defined by its type) are simply impossible except for the fact that the compiler allows null to be assigned to any reference. As a concrete example, since every Java class extends Object, and Object implements the toString method, you should be able to call toString on any object reference with a sensible result. Except null is an invalid reference, does not point to any object, and so will cause a NullPointerException if one attempts to call toString, or anything else on it. That's a pretty serious gaping hole in the type system that encourages poor API design, leading to bugs.

The reality is that null is useful for indicating a number of things: error, "does not exist", an unprovided optional value, a not-yet-explicitly-set value, etc.; and it's used for all these things because it's convenient--it's a valid value for all reference types so long as you don't actually deference it. If Java didn't support nulls, sure you could create a NullType for every reference type where all public methods throw runtime exceptions, but the inconvenience of it would encourage folks to consider better alternatives for their APIs: using exceptions for indicating error, empty collections for "does not exist", optional types for optional values, and some kind of "sane default" for not-yet-explicitly-set values, etc. These are all better alternatives to null as they either avoid error conditions, force API callers to acknowledge them (checked exceptions and optional types), or fail-fast when errors are unavoidable.

ExcessBLarg! fucked around with this message at 19:34 on Jul 7, 2015

Tank Boy Ken
Aug 24, 2012
J4G for life
Fallen Rib

Adhemar posted:

I really hate that they're doing this. I'm worried it will encourage people to keep passing nulls around willy-nilly. It's syntactic sugar to cover up a bigger problem in the code.
In my team we prefer the null object pattern, it works quite well. https://en.wikipedia.org/wiki/Null_Object_pattern

Well I've only taken up progamming as hobby for a couple of months now and do see the benefit of an null object. Especially if it can still be checked for being null.

Adbot
ADBOT LOVES YOU

loinburger
Jul 10, 2004
Sweet Sauce Jones

Tank Boy Ken posted:

Well I've only taken up progamming as hobby for a couple of months now and do see the benefit of an null object. Especially if it can still be checked for being null.

My program processes batch jobs submitted by a user through a rest interface, with most of the work being done inside of a BatchState variable that gets instantiated at the start of a job. I can initialize this variable to null, in which case I need to add about two dozen null pointer checks and/or return a null pointer exception to the user (which they may not know how to interpret); instead I'm initializing it to a null object that returns a more meaningful message/exception if the user tries to execute a command that doesn't make sense while a job isn't running. The main benefit is that this concentrates the error handling to a NullBatchState object rather than spreading it out across the rest interface.

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