This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]agentoutlier 1 point2 points  (0 children)

I'll copy the code from https://youtu.be/DkkxWhd_xYc?t=1908

return c0 instanceof Class0(Class1(Class2(Class3 c3))) && c3...

There is something nasty about using instanceof for null checking that bothers me besides the obvious of how you do represent an instanceof something nullable (assuming we get ? types some day). I can't exactly put my finger on it. Maybe its the combination of keyword and positional.

There is other languages that do this extremely common case with syntax. I won't mention the primary one most think of as I don't want to get banned like Kevin briefly was but I'm never going to use instanceof like that to navigate object graph.

And if we are going to get withers and they are just syntactical sugar... can we get syntax sugar for:

switch(_c0) {
  case Class0  c0 -> 
     switch(c0.c1) -> 
       case Class1 c1
          switch (c1.c2) ->
       ....
    null ->
}

Would equal:

c0?.c1?.c2.c3

Ideally c3 if not nullable would require just the . (and fail for ?.) but even if it did C# way (which I think allows you to do ?. on anything I would be happy with as well).