
Analysing C# code on GitHub with BigQuery - matthewwarren
http://www.mattwarren.org/2017/10/12/Analysing-C-code-on-GitHub-with-BigQuery/
======
tybit
1\. ArgumentNullException, 2. ArgumentException and 5.
ArgumentOutOfRangeException shows how badly C# needs more ability to
specify/enforce contracts.

It's awesome that C# 8 will address the number 1 problem, with non nullable
references but number 2 won't be addressed until records post C# 8 by the
looks of things and number 5 not until exhaustive pattern matching which
doesn't look to be on the cards at all AFAIK.

~~~
stult
Seriously. Contracts. I inherited a relatively substantial C# WCF business
line app with a large number of classes each with many nullable properties.
The null handling was awful, but there were too many classes to easily
refactor to apply data contract attributes across the board (at least given
that I am the sole available resource to do so). Instead I tried selectively
applying the null object pattern to some of the most common troublemakers.
It's improved things but god I wish the original dev had used data contract
attributes from the beginning.

Similarly, it's staggering the number of times I've seen someone wrap their
entire method (or worse yet their entire program) in empty try-catch blocks
just to avoid responsibly handling null and out of range exceptions. To me, it
seems like the ubiquity of this antipattern indicates that there's something
inadequate about the language, tooling, or developer culture. Or some
combination thereof.

I'm not enough of an expert to say what the problem is or how to fix it, but
in my relatively limited experience I've found requiring data contracts up
front smooths over a lot of the pain points. But it comes at a cost. I've
never used an equivalent in any other language, so I don't how C# and .NET
compare, but it does seem like a lot of boilerplate code that can limit
decoupling if misapplied.

~~~
emodendroket
Well this is the problem Option classes are meant to solve but it's pretty
tough to make that work without breaking all the old code where any reference
value can be null

------
nawtacawp
_C# developers overwhelmingly prefer putting an opening brace { on it’s own
line (query used)_

Putting it on it's own line seems like a waste of space to me and doesn't
contribute to the readability.

~~~
partisan
If I am not mistaken, Visual Studio automatically places an opening brace on
the next line. When setting up coding standards, I asked my team not to fight
Visual Studio. It generally has good auto-formatting functionality, but even
more important is the uniformity and consistency of the code.

~~~
shoover
Opening brace on a new line is the default, but VS has excellent granular
settings in this area. I was tired of having different standards for C and C#,
so at one point we switched our defaults and ran a utility to convert all our
C# code. We use a new line for namespaces, classes, and methods and the same
line for everything else. VS handles it flawlessly and we haven’t looked back.
Thinking back, I have not seen any inconsistencies committed in that time. VS
autoformat is that good, with braces and white space.

~~~
omgtehlion
> a new line for namespaces, classes, and methods and the same line for
> everything else

accidentally, we arrived to the same code style for both C# and C++...

~~~
shoover
Probably accidental here, too, in that the C code was older and larger. There
was no good answer for the question of why C# was different, so the change was
made.

The only downside would be if I worked on someone else’s project with
different standards. I don’t think VS can figure out autoformat at the project
level, like, say, python mode in emacs.

~~~
nwah1
Have you looked at editorconfig?

~~~
shoover
I hadn't seen it before, but that looks great. It has such a wide variety of
plugins. Thanks for the tip.

------
mulrian
Interesting to see 'var' isn't used as much as I thought it would be.

~~~
weavie
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.

~~~
romanovcode
What's the point of not using stable language features? I don't get it.

~~~
JustSomeNobody
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.

~~~
romanovcode
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.

~~~
emodendroket
Sometimes ReSharper makes some seriously wild, unreadable suggestions for
converting code to Linq.

~~~
romanovcode
Yeah, but IMO after Roslyn I don't see the benefit of ReSharper, definitely
not for the 100 dollar price per year.

~~~
emodendroket
That happened right when I started a new job so I haven't touched it that
much. R# used to be absolutely essential though.

------
CDillinger
Interesting how 'css/style.cs' is number 10 on the size list. Is this just a
style sheet with the wrong extension? I always assumed GitHub's language
detection was based on syntax rather than just extension. Does anyone know if
this is the case?

~~~
niftich
By the way, GitHub's language detection is powered by their Linguist library
[1].

[1] [https://github.com/github/linguist](https://github.com/github/linguist)

~~~
matthewwarren
Thanks for the link, I've always wondered how GitHub does language detection

------
emodendroket
I'm surprised to see so little var, especially when ReSharper by default
scolds you for not using it.

------
sAbakumoff
It's always nice to see BQ-based research like this!

~~~
matthewwarren
Yeah BQ is basically magic, it's so impressive how much data is can process in
30 secs or less.

(I know under-the-hood it consists of some very impressive
algorithms/hardware/programming etc, as explained in
[https://cloud.google.com/blog/big-data/2016/08/in-memory-
que...](https://cloud.google.com/blog/big-data/2016/08/in-memory-query-
execution-in-google-bigquery), but it feels like magic!)

~~~
isp
Some good reading on BigQuery: [https://medium.com/@thetinot/bigquery-
required-reading-list-...](https://medium.com/@thetinot/bigquery-required-
reading-list-71945444477b)

~~~
matthewwarren
Thanks for that list, I've seen a few of those, but quite a lot of new ones in
there, reading my way through them now!

~~~
isp
I'm glad it was helpful. I found this list (a very helpful list, with good
posts!) during $DAY_JOB. Following your comment, I've shared this more widely
here:
[https://news.ycombinator.com/item?id=15464921](https://news.ycombinator.com/item?id=15464921)

------
recursive
> Finally, an interesting list is the top 10 using statements that aren’t
> System, Microsoft or Windows namespaces:

> using System.Web.Mvc;

But... that is a System namespace.

~~~
matthewwarren
LOL, yeah I completely missed that one!!

I've just updated the post, 'log4net' makes in into the top 10 now.

------
codeulike
using UnityEngine;

Is the second most used 'using' that's non-Microsoft (after Nunit). Shows how
important Unity is for C# take up. And presumably most people using Unity to
write games are not going to be sticking their code on GitHub either so this
must be a fraction of the real use.

~~~
throwawayReply
IT's important to _open source_ C# take-up, but I'd wager the vast majority of
C# usage is closed-source shops.

c# just isn't favoured by hobbyists except for game-programming. But in
business world (at least from my UK perspective) where nothing comes close to
github, c# still seems as healthy as ever and that doesn't depend on unity at
all.

~~~
codeulike
Oh yes for sure, but that's always been there. .NET has always been used
widely for business internal stuff and that's what kept it alive. But the
recent C# renaissance seems to be about app building stuff like Xamarin or
Unity.

------
Nucode
I’m really confused why you think #regions are terrible. I use them generously
to collapse sections, and they objectively make code more organized. I would
not be as productive without them.

------
oaiey
It always disappoints me as a C# dev is the lack of top level application
products like WordPress and friends. All the top lists in Matt's post are
either infrastructure or development tools.

~~~
mattmanser
Iguess it's the pre-compilation requirement. Might change with the new
version, but I think the inertia was lost for the language long ago.

Here in the UK C# seems a lot more popular than Java, but I must admt I'm
getting more and more js jobs these days, which fills me with a slight dread
for the future as I really dislike programming in it.

I think Unity has helped C# become more popular for the masses again.

~~~
oaiey
I am not worried about C#. It just lacks open source applications. There are
tons of poster boy closed source applications :)

------
joepour
Surprised there wasn't more Class1.cs

