#nullable — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #nullable, aggregated by home.social.
-
CW: Q: 요즘 C#에는 (7.0인가 8.0인가부터) #nullable 이 기본으로 켜져있어요 ㅋㅋ #neo_quesdon
A: 그런 당신에게, WELCOME TO Unity 6000.0.36f1
https://neo-quesdon.serafuku.moe/main/user/@[email protected]/cmieanujz0w0vk70jqs9p3tlf
#neo_quesdon -
CW: Q: nulltable님은 nullable한 자료를 다루는 특별한 노하우가 있나요? #neo_quesdon
A: 딱 하나의 《진리》를 알려드리겠습니다. nullable과 non-nullable형을 명백하게 구분하는 언어를 쓰세요. 아니면 최소한 몰?루형?과 아!!루형을 정적으로 구분해서 둘을 섞으려는 순간 당신의 머리를 깡!!!! 해버리는 친구를 사귀어 가까이 두어요.
C#이면 #nullable 디렉티브를 켜요. TS이면 strict를 켜요. 그런 게 없어요? 오답이니까 창 밖으로 집어던지고 다른 언어를 찾아요.
그러면 그대의 가정이 당분간 평안할 것이며 당신의 두통이 최대 47%p[출처 필요] 감소할 것이에요. 그러니 깊이 새겨 두도록 해요.
https://neo-quesdon.serafuku.moe/main/user/@[email protected]/cmie56u4j0v27k70j5hjxicl0
#neo_quesdon -
Nullable-аннотации: MaybeNull и NotNullWhen в C#
Привет, Хабр! Сегодня мы рассмотрим nullable-аннотации в C#: как с помощью [MaybeNull] и [NotNullWhen] (плюс родственных атрибутов вроде [MaybeNullWhen] , [NotNullIfNotNull] , [DoesNotReturn] ) формально описывать те самые «ну тут иногда null, а тут точно нет».
https://habr.com/ru/companies/otus/articles/928286/
#c# #nullable #nullableаннотации #nullable_reference_types #SystemDiagnosticsCodeAnalysis #MaybeNull #NotNullWhen #MaybeNullWhen
-
Was fällt euch auf? Ist das wirklich sinnvoll so?
Diskutiert mal! 👀Bitte denkt selbst nach und fragt nicht einfach eine KI – eure eigenen Ideen interessieren mich viel mehr!
#CSharp #dotnet #fail #dotnetperle #cleancode #boolLogic #CodeReview #nullable #bug
-
@badcel @khalidabuhakmeh I guess I'm not fully understanding what #nullable does then, since it clearly does not mean things can't be null, at least not in all contexts.
I did use `where T: notnull` now and the error also goes away. But in my mind, that should be the default when #nullable is enabled.
-
@mortoray @khalidabuhakmeh I think it is a bit confusing because T could either be a reference type or a value type. Value types having a completely different nullability mechanic which is not at all related to #nullable pragma. If you exclude structure types via : “ where T : class” the warning goes away, too and the class should behave as expected as it does not need to care for structs anymore.
-
@khalidabuhakmeh But yes, nonetheless, declaring it nonnull does fix the problem.
`class Something<T> where T : notnull`
But I still don't understand why. It seems to go against what `#nullable enable` means.
-
@khalidabuhakmeh But I have `#nullable enable` on the file, implying all references are non-null unless declared otherwise, like `T?`.
Also, if I mark source as `T? source` then I get errors in my code, implying that it isn't actually nullable, except in this circumstance.
-
@andrewlock I see you enabled nullable, which is quite a minefield with a source-only package that wants to be able to work not only with nullable on or off, but also in a language where nullable isn't an option.
You end up with stuff like this:
You can't just "#nullable disable" because the compiler might not support it. So if they enable nullable but forget to "tell you", then you have to turn off a bunch of nullable "violations".
-
This is super duper extra important.
C# Nullable Reference Types are a compile-time thing, not a runtime thing. "string?" and "string" are both just "string" at runtime.
This means:
- Always guard against your users passing `null` even for types that _shouldn't_ allow it, because it's *not a runtime guarantee*.
- You can't create overloads that differ only on nullability (i.e., Method(string) vs. Method(string?)) because *they're the same type at runtime*.
-
Hey @jasonbock, excellent walkthrough on source generators in https://www.youtube.com/watch?v=KTsyS3rDUgg.
You don't need to restart VS to observe changes to a source generator in another project. A `dotnet build-server shutdown` at the command line resets the build-server cache and forces the generators to re-run from scratch.
Wrt. to nullable, I typically wrap generated code in `#nullable annotation`/`#nullable restore`. Then I do not have to use the damn-it operator.
-
-
for #dotnet people, when we have #nullable checking on, how do you feel about DTO fields initialised to " = null!;"
e.g.public string Name { get; set; } = null!;
It seems wrong to me "Name is not nullable, and also, surprise, it's null!"
It seems like that could go wrong.
But if it's the accepted idiom than I'll go with it.Is there a better one?
"= string.Empty;" is verbose.What do you think?
-
@khalidabuhakmeh like with "#nullable disable" or in VB.net "option strict" and "option explicit".
-
Maybe not that controversial take, but I love the nullable feature in C#. There are occasional situations where the nullable warning appears and I'm like "why???" But all in all, it has been a great help, and has generally made me a better programmer, even when doing stuff with .NET Framework.
-
#CSharpForMarkup 2 for #WinUI3 and @unoplatform is coming along nicely🙂
-🔥Windows C# #hotreload updates UI on Ctrl+S
- All #dotnet 7 target platforms, #csharp 11
- Nested view files in sln explorer
- Fully #nullable + #editorconfig enabled dotnet new template -
Is there a recommended pattern to follow when dealing with #nullable types in #TypeScript ?
This snippet is just from the #supabase #nextjs quickstart guide. Since data maybe null when fetched from the Supabase bucket, TS complains since createObjectURL requires the parameter.
I know that I could guard the line with an "if" statement but that just seems unnecessary. Like there should be a more elegant solution, something like optional chaining. :thinking: :javascript: :react:
-
New null policy: whenever I get a NullReferenceException, I put
#nullable enable
at the top of the file and enable warnings as errors. C#’s progressive inclusion of null reference checking is a life savor on old projects.
🐦🔗: https://twitter.com/praeclarum/status/1161830903556915200