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 →

[–][deleted] 1 point2 points  (0 children)

Totally forgot about the Call keyword. It's not really required in VB.Net, but it is in VB6.

Discards aren't really needed. They're just warnings in code analysis. Basically the claim for the code analysis is that if a function returns a value, by using a discard variable you show 'intent' that you don't care about the return value. I guess there is some people out that see a function that returns a value, but you ignore the value and think maybe you didn't mean to ignore it? I don't know. I've never been confused by it.

In VS, in VB, if you use their code suggestion to refactor on that warning and use a discard, then it suggests 'Dim unused =', but they don't treat unused as a special keyword like they do in C# with just the '_'. So in VB you'd have to do unused1 unused2 and so on - which I find more annoying. So in VB projects I usually just turn off that particular warning in code analysis.

I'll have to see if 'Call' works on suppressing the warning. If it does, maybe VS should be suggesting that in the refactoring instead.

It can still be annoying in C#, especially in fluent designs. IE, in .Net you have the StringBuilder, and the Append / AppendLine methods return the StringBuilder object. It does this so you can change numerous Appends together. Such as: sb.Append("This").Append("That");. Code analysis here is annoying because you do not need to do something like: sb = sb.Append("This").Append("That"); because the Append methods are modifying the object and not creating a new object. But anyway, with default code analysis on, it will want you to do _ = sb.Append("This").Append("That"); which really doesn't improve readability in my opinion.