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
my homie dhall
Dec 9, 2010

honey, oh please, it's just a machine
i thought it literally won’t compile with unused variables? which is actually infuriating at times

Adbot
ADBOT LOVES YOU

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

my homie dhall posted:

i thought it literally won’t compile with unused variables? which is actually infuriating at times

it won’t but you can use underscores in assignment to indicate that the variable is expected to be unused

also if you hoist a variable for conditional assignment or have a named return then assignment to those vars is considered use even if you don’t use them later in the code

Xarn
Jun 26, 2015

Kazinsal posted:

this all continues to validate my belief that go is just c/c++ for people who are too stupid to write c/c++

Nobody is smart enough to write C++ tho

Sapozhnik
Jan 2, 2005

Nap Ghost
also C

because compiler writers treat the C language spec the same way that Exxon-Mobil accountants treat the tax code

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

Blinkz0rz posted:

it won’t but you can use underscores in assignment to indicate that the variable is expected to be unused
it must feel really productive when debugging that when you've commented out a block of code you also have to hunt down any variables that are now unused

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Sagacity posted:

it must feel really productive when debugging that when you've commented out a block of code you also have to hunt down any variables that are now unused

i'm confused, you're arguing against further deletion of go code?

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

pokeyman posted:

i'm confused, you're arguing against further deletion of go code?
well played

FlapYoJacks
Feb 12, 2009
Probation
Can't post for 3 hours!

Kazinsal posted:

this all continues to validate my belief that go is just c/c++ for people who are too stupid to write c/c++

it’s not a belief. It’s literally why Google created Go.

FlapYoJacks
Feb 12, 2009
Probation
Can't post for 3 hours!

pokeyman posted:

i'm confused, you're arguing against further deletion of go code?

:hmmyes:

toiletbrush
May 17, 2010
I've just started working on a C# codebase that has nullability checking turned on, and it seems a bit...poo poo. Like, first off, it seems that 'null' for reference types vs 'null' for value types is handled completely differently by the language, which makes it impossible to return 'null' from a method generic in T, even if the T in the return type is optional, unless you constrain T to be either a struct or a class, which is obviously a bit of a dealbreaker if you want the class to be generic over any T. Otherwise you have to return 'default', which doesn't work if you want to tell the difference between, say, null and zero.

Also it seems like the '!' operator on nullable types doesn't mean 'unwrap and throw if null' like in many other languages, but just means 'ignore the warning', so dumb poo poo like this not only compiles, but *doesnt crash*:

code:
string? optional = null;
string notOptional = optional!;
Is there some shorthand for 'I expect this value to be non-null so pls unwrap it but throw an exception if it isnt'?

mystes
May 31, 2006

I haven't used nullability checking in c# yet but based on https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/nullable-value-types it seems like you're just supposed to cast it to the nonnullable type to get the desired behavior (equivalent to "unwrapping" it and panicking if it's null in another language)?

The syntax/behavior seems a bit weird compared to just disallowing nullability and adding straight up optional types to the language with syntactic sugar but I think that's a side effect of how they have tried to ensure compatibility unfortunately.

CarForumPoster
Jun 26, 2013

⚡POWER⚡
Anyone seen places do maybe 2-4 weeks of pair programming either all day or part day to help onboard entry level people and get them up to speed on older/larger code bases? How'd it go? We've got docs...kinda...but our dev team has always been 1-3 people so theres been lots of changes from the original baseline docs that might not be documented well.

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

CarForumPoster posted:

Anyone seen places do maybe 2-4 weeks of pair programming either all day or part day to help onboard entry level people and get them up to speed on older/larger code bases? How'd it go? We've got docs...kinda...but our dev team has always been 1-3 people so theres been lots of changes from the original baseline docs that might not be documented well.

4 weeks full time pairing sounds like a lot.

Typically I have an onboarding doc/tutorial/exercises i give people. If they run into issues I ask them to bring things up. I plan for daily check-ins, and dial it up if there's some issue. Usually takes people about a week.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

toiletbrush posted:

Is there some shorthand for 'I expect this value to be non-null so pls unwrap it but throw an exception if it isnt'?

the c# non-nullability hack is a compile-time thing so runtime checks are not included

Enterprise® Best® Practices® would require you to throw a useful exception every time:

code:
if (myButt == null) {
  throw new ArgumentNullException(nameof myButt)
}
or you can be a shameless hack and do something like

code:
#nullable enable

[return: System.Diagnostics.CodeAnalysis.NotNull]
public static T NotNull<T>(this T x) {
    if (x == null) {
        throw new NullReferenceException();
    }
    return x;
} 

string? a = null;
string b = a; // warning
string c = a.NotNull(); // no warning

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

NihilCredo posted:

the c# non-nullability hack is a compile-time thing so runtime checks are not included

Enterprise® Best® Practices® would require you to throw a useful exception every time:

code:
if (myButt == null) {
  throw new ArgumentNullException(nameof myButt)
}
or you can be a shameless hack and do something like

code:
#nullable enable

[return: System.Diagnostics.CodeAnalysis.NotNull]
public static T NotNull<T>(this T x) {
    if (x == null) {
        throw new NullReferenceException();
    }
    return x;
} 

string? a = null;
string b = a; // warning
string c = a.NotNull(); // no warning

code:

int? butt = null;
int poop { public get { return butt; } }

Shaggar
Apr 26, 2006

toiletbrush posted:

I've just started working on a C# codebase that has nullability checking turned on, and it seems a bit...poo poo. Like, first off, it seems that 'null' for reference types vs 'null' for value types is handled completely differently by the language, which makes it impossible to return 'null' from a method generic in T, even if the T in the return type is optional, unless you constrain T to be either a struct or a class, which is obviously a bit of a dealbreaker if you want the class to be generic over any T. Otherwise you have to return 'default', which doesn't work if you want to tell the difference between, say, null and zero.

Also it seems like the '!' operator on nullable types doesn't mean 'unwrap and throw if null' like in many other languages, but just means 'ignore the warning', so dumb poo poo like this not only compiles, but *doesnt crash*:

code:
string? optional = null;
string notOptional = optional!;
Is there some shorthand for 'I expect this value to be non-null so pls unwrap it but throw an exception if it isnt'?

! is a hack to work around the compiler not being able to understand certain null checks. Like imagine you have IEnumerable<Butt?> butts. If you try to iterate the content you're gonna have to null check everything, so a simple way to avoid nulls would be var nonNullButts = butts.Where(_=>_!=null). However, the compiler cant really understand that and will treat nonNullButts as still being IENumerable<Butt?>. As a workaround you can change it to butts.Where(_=>_!=null).Select(_=>_!) which will force the compiler to treat the output as IEnumerable<Butt>.

As far as im aware Nullable is enforced entirely at the compiler level for backwards compat. So string? optional and string notOptional in your example are both nullable strings under the hood and its the compiler slapping your hand when you try to mix the syntax.

In general though i've been loving nullable being turned on.

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

Shaggar posted:

! is a hack to work around the compiler not being able to understand certain null checks. Like imagine you have IEnumerable<Butt?> butts. If you try to iterate the content you're gonna have to null check everything, so a simple way to avoid nulls would be var nonNullButts = butts.Where(_=>_!=null). However, the compiler cant really understand that and will treat nonNullButts as still being IENumerable<Butt?>. As a workaround you can change it to butts.Where(_=>_!=null).Select(_=>_!) which will force the compiler to treat the output as IEnumerable<Butt>.

As far as im aware Nullable is enforced entirely at the compiler level for backwards compat. So string? optional and string notOptional in your example are both nullable strings under the hood and its the compiler slapping your hand when you try to mix the syntax.

In general though i've been loving nullable being turned on.

string is a reference type anyway, so string? as a type sounds weird to me

Powerful Two-Hander
Mar 10, 2004

Mods please change my name to "Tooter Skeleton" TIA.


Shaggar posted:

.

In general though i've been loving nullable being turned on.

foreverialy nullable, fully typesafe, turned on and loving it

mystes
May 31, 2006

leper khan posted:

string is a reference type anyway, so string? as a type sounds weird to me
Huh? Isn't the whole point of the nullable stuff so that you can treat reference types as non-nullable so if you want to make it nullable you have to use stuff like "string?"? Are you just saying that you don't like nullability checking?

Nullable types suck so even if the c# nullability checking is uglier than option types in other languages and there's some weirdness based on how it had to be implemented, it still seems like a huge improvement.

DELETE CASCADE
Oct 25, 2017

i haven't washed my penis since i jerked it to a phtotograph of george w. bush in 2003

Powerful Two-Hander posted:

foreverialy nullable, fully typesafe, turned on and loving it

wrapped up like a monad, fully wrapped in permanent data constructor

gonadic io
Feb 16, 2011

>>=
type check me daddy

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

mystes posted:

Huh? Isn't the whole point of the nullable stuff so that you can treat reference types as non-nullable so if you want to make it nullable you have to use stuff like "string?"? Are you just saying that you don't like nullability checking?

Nullable types suck so even if the c# nullability checking is uglier than option types in other languages and there's some weirdness based on how it had to be implemented, it still seems like a huge improvement.

String can be null already. It is a reference type.

Int is a value type. It can not be null.

A nullable int is a value typed wrapper around an int, allowing semantically for a null valued int. Not that the meaning of that is immediately clear (probably set vs unset)

mystes
May 31, 2006

leper khan posted:

String can be null already. It is a reference type.

Int is a value type. It can not be null.

A nullable int is a value typed wrapper around an int, allowing semantically for a null valued int. Not that the meaning of that is immediately clear (probably set vs unset)
Isn't the entire point of the nullability checking stuff in c# is that you can change the behavior so the compile won't allow reference types to be assigned null unless you explicitly mark it as nullable?

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

mystes posted:

Isn't the entire point of the nullability checking stuff in c# is that you can change the behavior so the compile won't allow reference types to be assigned null unless you explicitly mark it as nullable?

The nullable syntax stuff (eg int?) is to allow value types to be null.

Not to prevent reference types from being null.

mystes
May 31, 2006

leper khan posted:

The nullable syntax stuff (eg int?) is to allow value types to be null.

Not to prevent reference types from being null.
????????

pseudorandom name
May 6, 2007

Now go take a screenshot of the first three paragraphs of that page.

sb hermit
Dec 13, 2016





kotlin is pretty good about nullable references

I never got into C# (or dot net for that matter) but avoiding Null Pointer Exceptions at compile time seems to be something that should have been implemented in every language higher than C

Like, it should have been a feature in the 90s.

mystes
May 31, 2006

pseudorandom name posted:

Now go take a screenshot of the first three paragraphs of that page.


I have no idea which part you're referring to?

And I don't see anything implying the part of nullability checking is "Not to prevent reference types from being null" like leper khan was saying which I understand to be literally the whole point of nullability checking?

I guess either I must be misunderstanding the whole point of adding nullability checking to c# or I have no idea why I'm even bothering posting in yospos anymore.

Zlodo
Nov 25, 2006

sb hermit posted:

kotlin is pretty good about nullable references

I never got into C# (or dot net for that matter) but avoiding Null Pointer Exceptions at compile time seems to be something that should have been implemented in every language higher than C

Like, it should have been a feature in the 90s.

compilers were very primitive in the 90s and most efforts back then was about generating code that didn't completely suck

"compilers generate better assembly than you can write by hand" was not always true

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
i think they're just unaware of the c# 8 changes because explicitly nullable reference types were just sort of nonsense in c# for a very long time due to the lack of non-nullable reference types

pseudorandom name
May 6, 2007

mystes posted:



I have no idea which part you're referring to?

And I don't see anything implying the part of nullability checking is "Not to prevent reference types from being null" like leper khan was saying which I understand to be literally the whole point of nullability checking?

I guess either I must be misunderstanding the whole point of adding nullability checking to c# or I have no idea why I'm even bothering posting in yospos anymore.

this is a feature added in C# 8.0

distortion park
Apr 25, 2011


leper khan posted:

The nullable syntax stuff (eg int?) is to allow value types to be null.

Not to prevent reference types from being null.

The "Nullable reference types" feature does the opposite, it's a dumb name. It adds static analysis to check that reference types are not null, unless marked as nullable (e.g. String?).


mystes
May 31, 2006

pseudorandom name posted:

this is a feature added in C# 8.0
Seriously what are you even trying to say here? The "string?" type was specifically brought up in this conversation in the context of enabling nullability checking and then leper khan said that it made no sense because strings are already reference types and then proceeded to argue with me when I tried to explain how nullability checking works.

So wow you really got me by making me scroll up the page to the c# 8.0 part which I guess I stealthily omitted from my post in the middle of this discussion which was explicitly about nullability checking in recent versions of c# in the first place.

Great job, terrible programming thread.

mystes fucked around with this message at 18:11 on Jul 1, 2022

Achmed Jones
Oct 16, 2004



throwin a programming fit on a saturday morning

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

mystes posted:

Seriously what are you even trying to say here? The "string?" type was specifically brought up in this conversation in the context of enabling nullability checking and then leper khan said that it made no sense because strings are already reference types and then proceeded to argue with me when I tried to explain how nullability checking works.

So wow you really got me by making me scroll up the page to the c# 8.0 part which I guess I stealthily omitted from my post in the middle of this discussion which was explicitly about nullability checking in recent versions of c# in the first place.

Great job, terrible programming thread.

I'm in management now. Giving slightly outdated programming guidance is praxis

:smugbert:

sb hermit
Dec 13, 2016





Achmed Jones posted:

throwin a programming fit on a saturday morning

I wish. Friday morning here.

mystes
May 31, 2006

Achmed Jones posted:

throwin a programming fit on a saturday morning
Gee I was starting to wonder if everyone in this thread was just totally checked out and waiting to retire now but you have definitely reassured me

FlapYoJacks
Feb 12, 2009
Probation
Can't post for 3 hours!
lol imagine getting angry about programming languages.

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

I don't have to imagine, I use them all the time

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.

FlapYoJacks posted:

lol imagine getting angry about programming languages.

Imagine not getting angry about programming languages

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