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
CPColin
Sep 9, 2003

Big ol' smile.
Could God make a type so optional that even He couldn't reify it?

Adbot
ADBOT LOVES YOU

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Volte posted:

None and null aren't the same thing.
next you're gonna tell me that NULL and 0 aren't the same thing :o:

ExcessBLarg!
Sep 1, 2001

leper khan posted:

If they happen sooner, you're converting from a nullable or reference type to a non-nullable value-type. Checking for a value has similar semantics and failing to do that in both cases throws an exception.
:shrug:
I'm not sure I was clear in my original statement. What I was trying to say is that checking if an option type has value tends to happen sooner, since it's required to convert to a non-nullable type. Since a failing check happens sooner, it makes an unexpected empty value easier to debug.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Volte posted:

Forget the word "null", it's distorting your viewpoint. Option is effectively a list that can have either zero or one element in it, and as a result you can basically use all the nice patterns that you can use with lists (and a few others that come from the zero-or-one property too). Null specifically means an invalid pointer, and it is sometimes (mis)used to represent the "empty list" case, but None and null aren't the same thing.

Null is the absence of value. The concept isn't unique to pointers.

Bongo Bill
Jan 17, 2012

Having Optional in your statically typed language has a bigger benefit: the absence of value is now an invalid value for every type that isn't Optional. The problem with null is when the language lacks the ability to stipulate non-nullability for reference types.

If nothing is Optional, everything is.

Obviously, none of this applies to dynamically typed language, where everything can be anything or nothing all the time.

Bongo Bill fucked around with this message at 19:23 on Dec 12, 2023

Presto
Nov 22, 2002

Keep calm and Harry on.

RPATDO_LAMD posted:

I took an elective "number theory and cryptography" course where the professor was in that same "I don't care about what language you use just get the math parts right" stance.

I had a class like that, and the professor said the same thing about languages. Then I sat down for the final and there was a question that started with "Write a Fortran program that..."

I wrote down something like "There's no way I'm doing this in Fortrain, here's how to do it in C..."

No idea what grade I got.

Volte
Oct 4, 2004

woosh woosh

leper khan posted:

Null is the absence of value. The concept isn't unique to pointers.
I was using your own definition of null from this post, which you explicitly called out as being a pointer:

leper khan posted:

Horror from the thread and all, but I never understood the appeal of option types. Doesn't give any more information than a pointer.

You don't solve the problem of having null data. And you potentially confer that problem on to _value_ types, which implies you don't understand how data enters your system.

Oh you have to check HasValue everywhere instead of != NULL. Wow great good job.
Option types don't give any more information than a pointer because (in the environments we're discussing here) all pointers are implicitly optional. That's the entire problem. The problem you called out of having to check HasValue everywhere is exactly why option types are good and useful - because when Option<T> exists to represent "either T or nothing", then you can use just T by itself to represent "definitely T". When you have a "definitely T" there's no need to check HasValue, and it makes it clear by the types when the value might be missing and even where the lack of a value came from. But in your average language with null pointers, there's no such thing as a "definitely pointer", so you always have to check. You could eliminate the concept of a null pointer all together and replace it with Option<Ptr>, which is incidentally exactly what (safe) Rust does.

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

Volte posted:

Option is effectively a list that can have either zero or one element in it

*In a language where Optional is implemented in a useful way (i.e. not Java)

redleader
Aug 18, 2005

Engage according to operational parameters
making every method return an array since i heard about "monads" once

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.
monads mo problems

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


i have zero or more problems

Polio Vax Scene
Apr 5, 2009



my problems may be undefined or absent depending on the language i am using

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Polio Vax Scene posted:

my problems may be undefined or absent depending on the language i am using

My problems are severe but not representable.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

redleader posted:

making every method return an array since i heard about "monads" once

same but IO :getin:

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
People who like Haskell so they recreate Haskell in every language they use are a thing, unfortunately.

redleader
Aug 18, 2005

Engage according to operational parameters

Doc Hawkins posted:

i have zero or more problems

Bongo Bill
Jan 17, 2012

If it has flatMap, it's a monad. It really is that simple. People are just really bad at explaining it.

Athas
Aug 6, 2007

fuck that joker
flatMap is just the worst name. Who came up with that? We already had better names before that caught on in the bad languages.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

bind is arguably a worse name for being so opaque, >>= being even more so

at least for most people, the first monad they'll meet is List otherwise known as the non-deterministic choice monad :smuggo: so thinking of the operation as "map over each element, producing a nested list and then flatten it down" isn't totally unreasonable imo

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
"flatten" being the operation that takes M<M<T>> and turns it into M<T> makes sense generally, and "flatMap" being "map, then flatten" also makes sense.

Athas
Aug 6, 2007

fuck that joker
When you want to name an operation in a highly abstract concept, naming it after its behaviour in a specific instance of that concept seems more likely to muddle than clarify. Just don't mention monads as a concept if you are not ready to deal with the generality.

redleader
Aug 18, 2005

Engage according to operational parameters

Athas posted:

When you want to name an operation in a highly abstract concept, naming it after its behaviour in a specific instance of that concept seems more likely to muddle than clarify. Just don't mention monads as a concept if you are not ready to deal with the generality.

yeah, call it "monadize" or similar

or SelectMany

repiv
Aug 13, 2009

monads are a scam invented by big functional to sell more functions

redleader
Aug 18, 2005

Engage according to operational parameters

repiv posted:

monads are a scam invented by big functional to sell more functions

we haven't had a new thread title in a while...

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.

repiv posted:

monads are a scam invented by big functional to sell more functions
SalesFn

OddObserver
Apr 3, 2009
Big Lambda.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

OddObserver posted:

Big Lambda.

Computational complexity? That's just a lie you've been told by Big O

CPColin
Sep 9, 2003

Big ol' smile.
Look, we've all got plenty of experience with Big O lies, okay, don't rub it in

Carbon dioxide
Oct 9, 2012

OddObserver posted:

Big Lambda.

Black Mesa?

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


https://twitter.com/yiningkarlli/status/1736300787704426780

QuarkJets
Sep 8, 2008

deliberately writing bad code and then getting salty at visual studio for just say "nah"

Volguus
Mar 3, 2009
I agree with the compiler on this one.

Kazinsal
Dec 13, 2011
I love that the compiler docs for that "limitation" just outright tells you to refactor your code.

Jeffrey of YOSPOS
Dec 22, 2005

GET LOSE, YOU CAN'T COMPARE WITH MY POWERS
can probably "fix" it with a single pair of braces

Athas
Aug 6, 2007

fuck that joker
That limitation hints at a very weird representation inside the compiler, though. Also, when you have code like that, it is usually because it is generated, and then it can be very annoying to run into those arbitrary restrictions.

I also remember MSVC having a fairly low limit on the length of string literals (although still longer than sane for human written code).

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
I don’t think clang has a limit there that we enforce, but I wouldn’t be surprised if the practical limit is relatively low just because it’s a recursive position in the grammar and it’s natural to handle them in a million places in the compiler with recursive calls. We regularly have to chase down new bits of code that blow out the stack because they use recursion on e.g. switch cases instead of special-casing them to iterate.

fritz
Jul 26, 2003

That's an improvement over the compiler I was using in the early-mid 90s as a student which topped out way below that.

csammis
Aug 26, 2003

Mental Institution

I had to check the date on this tweet because I discovered the same msvc “limitation” in 2009ish. I think it had something to do with automated code generation for a JNI bridge.

ExcessBLarg!
Sep 1, 2001

Athas posted:

Also, when you have code like that, it is usually because it is generated, and then it can be very annoying to run into those arbitrary restrictions.
I'm struggling to think of a good example of having 100+ "else if" blocks even for generated code. Surely it could be converted to some kind of dispatch mechanism, or at least convert the conditional tests into a tree form.

Adbot
ADBOT LOVES YOU

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

ExcessBLarg! posted:

I'm struggling to think of a good example of having 100+ "else if" blocks even for generated code. Surely it could be converted to some kind of dispatch mechanism, or at least convert the conditional tests into a tree form.

I want to write my code generator in 5 minutes, and generating additional elif blocks is easy.

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