News for hackers. Stuff that matters.
Re:Analysing C# code on GitHub with BigQuery by mulrian on Friday October 13, 2017 @05:52AM (#15464287)
Interesting to see 'var' isn't used as much as I thought it would be.
Re:Analysing C# code on GitHub with BigQuery by matthewwarren on Friday October 13, 2017 @05:59AM (#15464312)
Yeah, I thought the same.

I now realise the better test of 'var' would be to compare it to how many times it's not used. That is count the times that 'var myClass = new MyClass()' is used v 'MyClass myClass = new MyClass()'. But my regex skills aren't good enough for that and I'm not even sure if you can do it purely in a regex?

Also I imagine that 'var someNumber = 1' is used less that 'int someNumber = 1', but again, I'm not sure how to do the regex? I certainly only use 'var' when the same word is on both sides of the '=', so not in the case of int/double/decimal etc.

Re:Analysing C# code on GitHub with BigQuery by mattmanser on Friday October 13, 2017 @06:25AM (#15464407)
I still use var in that scenario, because if you need different types you have to suffix numbers with an identifier anyway:

    var i = 1; //int
    var j = 1f; //float
    var k = 1m; //decimal
    var l = ""; //string
    var m = ''; //char
Re:Analysing C# code on GitHub with BigQuery by lukepothier on Friday October 13, 2017 @08:35AM (#15465022)
There are a few more for numeric types:

  var integer = 1;
  var long = 1l;
  var float = 1f;
  var double = 1d;
  var decimal = 1m;
  var unsignedInteger = 1u;
  var unsignedLong = 1ul;
Re:Analysing C# code on GitHub with BigQuery by matthewwarren on Friday October 13, 2017 @06:32AM (#15464438)
Yeah, I know you can do that, but I can never remember which suffix is which ;-)
Re:Analysing C# code on GitHub with BigQuery by weavie on Friday October 13, 2017 @06:32AM (#15464437)
Back when I used to work at a large enterprise the use of 'var' was banned in our coding standards.

Using Linq was heavily frowned upon. It took quite a few years before it started to be accepted..

At one point we were also strongly encouraged to place a #region around every single method! I never understood why, and luckily that one did get dropped.

Re:Analysing C# code on GitHub with BigQuery by romanovcode on Friday October 13, 2017 @06:38AM (#15464464)
What's the point of not using stable language features? I don't get it.
Re:Analysing C# code on GitHub with BigQuery by Cakez0r on Friday October 13, 2017 @07:11AM (#15464608)
I've (unfortunately) had to work with this rule before. The justification was that it makes the code more readable.

I can understand banning SQL style linq and allowing only functional style, but I guess that's more of a personal preference.

Re:Analysing C# code on GitHub with BigQuery by kylereeve on Friday October 13, 2017 @10:07AM (#15465781)
I used to work in a company with a similar policy. Never got a satisfactory answer, I think there's just lots of FUD around any language feature that looks different than what people are used to.
Re:Analysing C# code on GitHub with BigQuery by weavie on Friday October 13, 2017 @07:07AM (#15464584)
Neither did I.
Re:Analysing C# code on GitHub with BigQuery by recursive on Friday October 13, 2017 @11:26AM (#15466506)
goto is a stable language feature.
Re:Analysing C# code on GitHub with BigQuery by JustSomeNobody on Friday October 13, 2017 @07:18AM (#15464641)
While it shouldn’t be banned, it should be used appropriately. We have some areas of our project that communicate with hardware where we cannot use it because of the performance hit.
Re:Analysing C# code on GitHub with BigQuery by tigershark on Friday October 13, 2017 @09:00AM (#15465170)
Why on earth? It is resolved by the compiler, there is absolutely no performance difference between using var and explicitly specifying the type.
Re:Analysing C# code on GitHub with BigQuery by ambulancechaser on Friday October 13, 2017 @10:46AM (#15466147)
undoubtedly that person was talking about LINQ and not var usage
Re:Analysing C# code on GitHub with BigQuery by tigershark on Saturday October 14, 2017 @10:21AM (#15472267)
Undoubtedly he didn't read properly then. The banned feature was var, linq was just heavily frowned upon.
Re:Analysing C# code on GitHub with BigQuery by dbattaglia on Friday October 13, 2017 @11:34AM (#15466571)
Or possibly confusing "var" and "dynamic"?
Re:Analysing C# code on GitHub with BigQuery by JustSomeNobody on Friday October 13, 2017 @11:33AM (#15466568)
Yes, LINQ not var.
Re:Analysing C# code on GitHub with BigQuery by btschaegg on Friday October 13, 2017 @01:01PM (#15467399)
Well, that on the other hand does indeed make sense, depending on the context. The only question there could be if it's a good idea to use a garbage collected language to directly[1] interact with hardware.

[1]: Well, at least directly enough for LINQ performance to be a problem.

Re:Analysing C# code on GitHub with BigQuery by JustSomeNobody on Friday October 13, 2017 @03:56PM (#15468815)
We're not real time, but we do have some time constraints.

Yes, all this was kicked around and argued about.

Re:Analysing C# code on GitHub with BigQuery by romanovcode on Friday October 13, 2017 @08:58AM (#15465153)
Yeah, I agree. You can make some seriously shitty unreadable code using LINQ just to look smart. But that's what code reviews are there for.
Re:Analysing C# code on GitHub with BigQuery by btschaegg on Friday October 13, 2017 @01:07PM (#15467439)
I agree. That, and not using LINQ often enough doesn't resolve that problem per se. Rethinking the problem (or the way you attempt to solve it) might very well improve the code much more.

One of Kevlin Henney's talks references a really neat quote by Poul Anderson on this subject:

> I have yet to see any problem, however complicated, which, when you looked at it in the right way, did not become still more complicated.

Re:Analysing C# code on GitHub with BigQuery by emodendroket on Friday October 13, 2017 @03:16PM (#15468510)
Sometimes ReSharper makes some seriously wild, unreadable suggestions for converting code to Linq.
Re:Analysing C# code on GitHub with BigQuery by romanovcode on Friday October 13, 2017 @07:03PM (#15469777)
Yeah, but IMO after Roslyn I don't see the benefit of ReSharper, definitely not for the 100 dollar price per year.
Re:Analysing C# code on GitHub with BigQuery by emodendroket on Saturday October 14, 2017 @01:52AM (#15470981)
That happened right when I started a new job so I haven't touched it that much. R# used to be absolutely essential though.
Re:Analysing C# code on GitHub with BigQuery by lightbyte on Friday October 13, 2017 @09:25AM (#15465371)
Are you talking about "var"? Because that shouldn't affect your performance, this generates equal IL code:

var x = 10;

int x = 10;

Re:Analysing C# code on GitHub with BigQuery by darklajid on Friday October 13, 2017 @07:09AM (#15464595)
Yesterday a colleague wanted to compile _and deploy_ code. Checked it out. It .. failed to compile. Sure enough, he fixed it (and checked the change in) before deploying it (test env, thank god).

The code was generating some JSON using Linq and created JSON properties: new JsonObject(LinqExpressionHere)

The name for the property was defined as

$"SomePrefix_{x.Name}"

which he helpfully changed to

"SomePrefix_{x.Name}"

which then compiled, but crashed in the test environment because of - surprise - duplicate attributes..

Re:Analysing C# code on GitHub with BigQuery by maxxxxx on Friday October 13, 2017 @07:38AM (#15464739)
I just did this in my code! Ported a ton of PHP to C# and forgot to add $ to the front of strings. A compiler warning would be nice for this.
Re:Analysing C# code on GitHub with BigQuery by matthewwarren on Friday October 13, 2017 @06:33AM (#15464445)
> At one point we were also strongly encouraged to place a #region around every single method! I never understood why, and luckily that one did get dropped

Shudder!!

Especially since VS has plugins (or maybe it's built-in?) that will let you fold/hide individual methods, if you really want to do that!

Re:Analysing C# code on GitHub with BigQuery by acidshards on Friday October 13, 2017 @07:39AM (#15464745)
FYI: It's built-in.
Re:Analysing C# code on GitHub with BigQuery by mattmanser on Friday October 13, 2017 @06:17AM (#15464376)
I use it religiously now, so much quicker to program with imo as you don't need to find out the return type. Surprised it's less used than async/await though, which I think MS massively overhypes the usefulness of (and is annoyingly making a lot of classes have async behaviour by default which can result in very weird random hangs).

Although I imagine a significant number of class declarations would contain no var or async/await simply because of their nature.