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

Sdílet
Vložit
  • čas přidán 18. 04. 2023
  • Connect with me on 'em socials:
    Twitter: / amantinband
    LinkedIn: / amantinband
    GitHub: github.com/amantinband
  • Věda a technologie

Komentáře • 24

  • @OllyWood688
    @OllyWood688 Před rokem +13

    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

  • @pagorbunov
    @pagorbunov Před rokem +7

    Following the same logic as with 'var' the output is going to be 0

  • @jamesmussett
    @jamesmussett Před rokem +6

    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;
    }

  • @dmisterb
    @dmisterb Před rokem +7

    using async = System.Int32;
    async async()
    {
    async async = default;
    return async;
    }

  • @varunaggarwal7126
    @varunaggarwal7126 Před rokem +4

    Working with c# for more than 2 years, learn something new 👍

  • @gg15
    @gg15 Před rokem

    @amantinband Unrelated: How is your terminal set up? zsh + oh my zsh + what theme? + custom config? Thx!

    • @amantinband
      @amantinband  Před rokem +2

      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 Před rokem

      I'm assuming its oh-my-posh which is cross platform and excellent. (written in go)

    • @amantinband
      @amantinband  Před rokem

      Nope. On my Mac I use oh-my-zsh 🫣

    • @pilotboba
      @pilotboba Před rokem

      @@amantinband A Mac - heresy !!!

    • @gg15
      @gg15 Před rokem

      @@amantinband Thank you! I like it.

  • @reikooters
    @reikooters Před rokem

    "backwards compatibility with C# before version 3" because of course

  • @piotrc966
    @piotrc966 Před rokem

    0

  • @bobweiram6321
    @bobweiram6321 Před rokem +1

    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.

  • @williamliu8985
    @williamliu8985 Před rokem +4

    horrible code! M$ should really ban them...

    • @maxron6514
      @maxron6514 Před rokem

      Fully agreed but They won’t because of their almighty lizardgod called „downwards compatibility“ 😂

    • @bobweiram6321
      @bobweiram6321 Před rokem

      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 Před rokem

      @@maxron6514 Yes, but sadly you can have downwards compatibility without allowing unchecked ambiguity.

  • @Kann_lol
    @Kann_lol Před rokem

    I literally guessed the right answer ez default is 1 on int but we have given default! so its 0

  • @catsgotmytongue
    @catsgotmytongue Před rokem

    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  Před rokem +5

      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 Před rokem +1

      @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.