Why is everyone getting this riddle wrong? | How sharp is your C# | Riddle 1

  Рет қаралды 6,711

Amichai Mantinband

Amichai Mantinband

Жыл бұрын

Connect with me on 'em socials:
Twitter: / amantinband
LinkedIn: / amantinband
GitHub: github.com/amantinband

Пікірлер: 24
@OllyWood688
@OllyWood688 Жыл бұрын
Great, more ways for me to flex my code-fu and produce unmaintainable masterpieces that I won't remember what they do and how they do it in a year lol :D
@jamesmussett
@jamesmussett Жыл бұрын
having async still makes it 0, what i find more amusing however is that the following is still valid c#: using System; using System.Runtime.CompilerServices; class await { async async async(async async) => await async; } [AsyncMethodBuilder(typeof(builder))] class async { public awaiter GetAwaiter() => throw null; } class awaiter : INotifyCompletion { public bool IsCompleted => true; public void GetResult() { } public void OnCompleted(Action continuation) { } } class builder { public builder() { } public static builder Create() => throw null; public void SetResult() { } public void SetException(Exception e) { } public void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine => throw null; public async Task => throw null; public void AwaitOnCompleted( ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine => throw null; public void AwaitUnsafeOnCompleted( ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine => throw null; public void SetStateMachine(IAsyncStateMachine stateMachine) => throw null; }
@pagorbunov
@pagorbunov Жыл бұрын
Following the same logic as with 'var' the output is going to be 0
@dmisterb
@dmisterb Жыл бұрын
using async = System.Int32; async async() { async async = default; return async; }
@varunaggarwal7126
@varunaggarwal7126 Жыл бұрын
Working with c# for more than 2 years, learn something new 👍
@reikooters
@reikooters Жыл бұрын
"backwards compatibility with C# before version 3" because of course
@gg15
@gg15 Жыл бұрын
@amantinband Unrelated: How is your terminal set up? zsh + oh my zsh + what theme? + custom config? Thx!
@amantinband
@amantinband Жыл бұрын
Yup, zsh and oh-my-zsh. The theme is p10k with some customizations, and then I have some plugins for the output colors, vi mode etc, my full configuration is available here: github.com/ amantinband/dotfiles
@pilotboba
@pilotboba Жыл бұрын
I'm assuming its oh-my-posh which is cross platform and excellent. (written in go)
@amantinband
@amantinband Жыл бұрын
Nope. On my Mac I use oh-my-zsh 🫣
@pilotboba
@pilotboba Жыл бұрын
@@amantinband A Mac - heresy !!!
@gg15
@gg15 Жыл бұрын
@@amantinband Thank you! I like it.
@williamliu8985
@williamliu8985 Жыл бұрын
horrible code! M$ should really ban them...
@maxron6514
@maxron6514 Жыл бұрын
Fully agreed but They won’t because of their almighty lizardgod called „downwards compatibility“ 😂
@bobweiram6321
@bobweiram6321 Жыл бұрын
Thank god for your comments because I was questioning my own intellect for criticizing this appalling design choice. It means the compiler can no longer help in detecting errors resulting from reserved word ambiguity. The better choice is to flag an error and offer a pragma option to warn instead. This choice favors convenience over correctness, a very bad trade off. Such terrible decisions provides a lot of insight into why Microsoft's products are so shoddy.
@bobweiram6321
@bobweiram6321 Жыл бұрын
@@maxron6514 Yes, but sadly you can have downwards compatibility without allowing unchecked ambiguity.
@piotrc966
@piotrc966 Жыл бұрын
0
@bobweiram6321
@bobweiram6321 Жыл бұрын
What a terrible design decision! Allowing new reserved words for variable names in order to maintain backward compatibility, defeats the point of disambiguation. It is likely to make it nearly impossible to detect certain errors when porting old code. The proper way to handle this is with a compiler error with an option to use a pragma to override it with a warning.
@Kann_lol
@Kann_lol Жыл бұрын
I literally guessed the right answer ez default is 1 on int but we have given default! so its 0
@amantinband
@amantinband Жыл бұрын
Lol
@catsgotmytongue
@catsgotmytongue Жыл бұрын
as a professional developer, I'd say there's no excuse to use the c# keywords as names for things so please don't, not even with the @ symbol in front. This usage of c# while possible wouldn't work well for a team. What if I put that same var alias in a global using ? There's a reason we have coding standards.
@amantinband
@amantinband Жыл бұрын
Maybe I should add a “These riddles are meant as brain teasers and a fun way to learn language features, not recommendations” disclaimer
@catsgotmytongue
@catsgotmytongue Жыл бұрын
@Amichai Mantinband fine, I would argue you should never see such a scenario, and if you do it's a red flag that the person needs talked to about why you should never do this. The language shouldn't allow the scenario but it does and thanks for pointing out where the compiler fails to prevent the developer from making tragic mistakes for a team.
How Sharp is Your C#? | Riddle #2
3:45
Amichai Mantinband
Рет қаралды 6 М.
This BIG Modeling Mistake Is Ruining Your Performance
12:31
Amichai Mantinband
Рет қаралды 11 М.
[柴犬ASMR]曼玉Manyu&小白Bai 毛发护理Spa asmr
01:00
是曼玉不是鳗鱼
Рет қаралды 49 МЛН
Joven bailarín noquea a ladrón de un golpe #nmas #shorts
00:17
КАРМАНЧИК 2 СЕЗОН 6 СЕРИЯ
21:57
Inter Production
Рет қаралды 445 М.
Dependency injection fundamentals in C# - DI vs IoC vs DIP
13:30
Amichai Mantinband
Рет қаралды 22 М.
Exceptions are evil. This is what I do instead.
24:41
Amichai Mantinband
Рет қаралды 16 М.
Clean Architecture vs Domain-Driven Design (DDD) - Understand the Difference
11:26
What are record types in C# and how they ACTUALLY work
15:36
Nick Chapsas
Рет қаралды 116 М.
Stop Calling Your API a "REST API"
17:42
Amichai Mantinband
Рет қаралды 13 М.
Stop returning custom error responses from your API. Do this instead.
12:07
Amichai Mantinband
Рет қаралды 78 М.
5 C# Naming Conventions I Wish Everyone Followed
12:46
Amichai Mantinband
Рет қаралды 14 М.
Winglang in 10 minutes
11:39
Amichai Mantinband
Рет қаралды 10 М.
Making LINQ Blazing fast with PLINQ (Parallel LINQ) | .NET & C# Essentials
36:26
Обзор игрового компьютера Макса 2в1
23:34
iphone fold ? #spongebob #spongebobsquarepants
0:15
Si pamer 😏
Рет қаралды 283 М.
What percentage of charge is on your phone now? #entertainment
0:14
😱НОУТБУК СОСЕДКИ😱
0:30
OMG DEN
Рет қаралды 2,7 МЛН