News for hackers. Stuff that matters.
Re:More functional C# by Dewie on Sunday January 12, 2014 @05:44PM (#7047806)
I have read a lot of lang. wars and complaints about programming languages... but C# is one of the only languages that I can't remember reading any complaints about. None.

I must conclude, by the usual Stroustrup quote, that no one uses C#. (yes this is tongue in cheek)

Re:More functional C# by MaulingMonkey on Sunday January 12, 2014 @06:25PM (#7047948)
You're not hanging around in the right circles then, I hear complaints about C# all the time ;).

While there's plenty of limitations and frustrations you can run into with C#, I've generally felt they were largely due to intentional tradeoffs I can understand, and fail to know a better alternative to. This makes me significantly less ranty about it, in contrast to my other daily bread and butter of C++. Even if I felt both were as limiting as each other, I'd be ranting about the latter significantly more -- simply out of a sense that "it shouldn't have to be this way".

Re:More functional C# by eldavido on Sunday January 12, 2014 @06:53PM (#7048023)
Am currently reading "Thinking Fast and Slow" by Kahneman, this is a perfect example of a base-rate fallacy (something addressed in the book).

Absent any other evidence, one should assume the amount of complaining a language would get is about proportional to how widely it's used. So the lack of complaining (asserted by the parent) about C# might be as much a reflection on how widely it's used, than on the language itself.

Re:More functional C# by delluminatus on Sunday January 12, 2014 @08:54PM (#7048407)
There is other evidence, though. For instance, C# is currently #5 on the TIOBE programming index [0].

[0]: http://www.tiobe.com/index.php/content/paperinfo/tpci/index....

Re:More functional C# by MaulingMonkey on Sunday January 12, 2014 @11:00PM (#7048835)
> Am currently reading "Thinking Fast and Slow" by Kahneman, this is a perfect example of a base-rate fallacy (something addressed in the book).

I disagree that Dewie's individual experience constitutes a "base-rate". If you're referring to something else as a "base-rate", you'll have to spell it our more clearly for me, as I'm having difficulty seeing how to apply it validly here.

> Absent any other evidence, one should assume the amount of complaining a language would get is about proportional to how widely it's used.

That's reasonable, and my own experiences and anecdotes don't turn out to be capital D Data. However, neither are Dewie's experiences and anecdotes. And what I would argue isn't reasonable is assuming the amount of complaining that one individual developer hears about a language we get is about proportional to how widely it's used. The data set is far too small to extrapolate that far.

My own experience is that the amount of complaining about a language I hear about varies wildly by what my peers in my communities happen to be using at the time. I went years without hearing any complaints about PHP... and then someone gets employed writing it and it spikes up to the language I hear the most complaints about. I'd be very absurd to assume that PHP went from not used very widely at all to the most used language in that same timeframe!

While I cast a wide net, my time is finite and I pay more attention to some communities than others, quite understandably biasing what I hear significantly.

> So the lack of complaining (asserted by the parent) about C# might be as much a reflection on how widely it's used, than on the language itself.

Granted, but "might be" is a far cry from "is" or "should be assumed to be". Indeed, I wouldn't suggest that "C# might generally be less rant-inducing" to be worthy of assuming either. Dewie "might be" not hanging around .NET devs, but even that's a terribly poor assumption -- I know plenty of devs who don't complain about languages I consider absolutely terrible.

Re:More functional C# by egeozcan on Sunday January 12, 2014 @05:56PM (#7047850)
Well, I use it =) C# is a language with a somewhat limited market ("Enterprise" applications running on Windows Servers, and yes, I know about Mono). And in this market, a very strict subset of C# (see: Java) is happily used. I know a lot of people who refrain from using even lambdas and implicit typing, let alone the other "fringe functional stuff", because "they make things complicated".
Re:More functional C# by nawitus on Sunday January 12, 2014 @06:24PM (#7047944)
C# is a great language, in fact, I believe it's the best "general language", if there ever was one. The only real problem C# has is it's bad support of non-Windows platforms. As a language, it's excellent.
Re:More functional C# by miguelrochefort on Sunday January 12, 2014 @08:52PM (#7048394)
Xamarin
Re:More functional C# by yachtintransit on Sunday January 12, 2014 @10:49PM (#7048805)
ahh no good! C# + X-Platform = #Remarkable
Re:More functional C# by V-2 on Sunday January 12, 2014 @06:21PM (#7047931)

   C# is a language with a somewhat limited market 
   ("Enterprise" applications running on Windows Servers,
   and yes, I know about Mono)
One would think that Windows Phone - fastest growing smartphone OS - would go before Mono... geez, I make a living out of desktop C# apps (WPF). Not solely, but on a daily basis.
Re:More functional C# by smilliken on Sunday January 12, 2014 @06:49PM (#7048010)
Fastest growing is easier to achieve when you have low market share.

Mono is significantly more important for the future of C# than Windows Phone.

Re:More functional C# by Danieru on Sunday January 12, 2014 @08:15PM (#7048281)
You can make it even easier by pretending old versions of your mobile OS don't count. Or at least it appears you're allowed to do this if you left all your prior mobile users high & dry after promising them upgrades, twice.
Re:More functional C# by V-2 on Monday January 13, 2014 @04:25AM (#7049604)
"Easier" doesn't mean easy - many players to the table, we are yet to see whether Tizen or Firefox OS manage to pull that easy feat.

What makes you think Mono plays (or is about to play) such a pivotal role?

Re:More functional C# by Ramp_ on Monday January 13, 2014 @04:46PM (#7053653)
I would be interested to know what these apps are? Who buys them? Where do you sell them? I never found a decent place to sell WPF desktop apps.
Re:More functional C# by rjbwork on Sunday January 12, 2014 @10:34PM (#7048757)
I've actually worked at 2 startups using C# and been contacted by 2 others in the last year trying to poach talent. C# is popular in many contexts.
Re:More functional C# by EnderMB on Monday January 13, 2014 @04:31AM (#7049621)
The same goes for me! My first job was at a startup that used ASP.NET with C# (with PHP for micro-sites). From there, I've worked at agencies where I've built both large sites and small sites using ASP.NET and C#.

The whole notion of .NET only being suitable for enterprise development is bullshit.

Re:More functional C# by JackMorgan on Monday January 13, 2014 @06:25AM (#7049979)
It's not that it is only ever used for enterprise, just that it seems to be mostly used for enterprise. Think of the licensing costs for visual studio, sqlserver and windows server. Sure there is the Bizspark, but it runs out, and I think most founders would be squeamish with the potential business-technical debt that would represent.

At least right now, MS is still seen (although less lately) like the Big Bad, so giving them money to use what you can get for free or near-free elsewhere seems uncool and like bad business sense.

I suspect too from my own extremely limited sample size that .NET developers make more money on average than the average of the other languages, so that is also a liability when looking for talent when you have limited cash.

Re:More functional C# by EnderMB on Tuesday January 14, 2014 @11:52AM (#7058054)
Actually, in my experience, I'd say that while .NET is used in enterprise, it's mostly used by small businesses. My experience is mainly within .NET based CMS's, and I've worked for a few agencies and startups that build on .NET, sometimes amongst other things.

I've never really bought the argument that building for .NET is too expensive. Yes, it's a lot more expensive than free, but for a company it's peanuts when it guarantees the company a stable platform and a growing dev market. The only people that will be priced out are bootstrappers. I've built more small-business sites on Umbraco than I can count.

Re:More functional C# by V-2 on Monday January 13, 2014 @06:53AM (#7050053)
I worked professionally on VS Express for quite a while. Yes it's less convenient, but it can be done. Still a better IDE than (say) NetBeans. I know it's apples and oranges, but I'm speaking about an overall impression.
Re:More functional C# by JackMorgan on Monday January 13, 2014 @07:09AM (#7050093)
You should check out Intellij. http://www.jetbrains.com/idea/

I think its free version is still better than most paid VS editions. The $500 edition is the best IDE I've seen. And it supports basically every language but the three .NET languages.

Re:More functional C# by V-2 on Monday January 13, 2014 @07:47AM (#7050214)
I know, it's very good. I use Android Studio and PHPStorm, both are mutations of Idea.
Re:More functional C# by rjbwork on Monday January 13, 2014 @08:18AM (#7050344)
"Think of the licensing costs for visual studio, sqlserver and windows server."

Think of the costs of paying your developers. Those things are a pittance compared to the cost of hiring and retaining good developers.

Re:More functional C# by JackMorgan on Monday January 13, 2014 @12:43PM (#7052064)
Shrug, your costs might be different, but 13k per developer per year is hardly a pittance compared to my salary. I'd much rather have 13k in my pocket or in awesome stuff like monitors, desk, keyboard, etc.
Re:More functional C# by rjbwork on Monday January 13, 2014 @11:22PM (#7055361)
In what world are you paying 13k per developer for year to use Microsoft products? Top of the line MSDN sub is like ~3k, and we get good desks and monitors and keyboards and computers too. Most places don't even buy MSDN, I do fine with a <1k in software to develop on .NET.
Re:More functional C# by JackMorgan on Tuesday January 14, 2014 @09:55PM (#7061375)
I got that price right off their site, top line Ultimate (only slightly less feature rich then Intellij IDEA) clocks in roughly $12500 more than IDEA.

http://www.visualstudio.com/en-us/products/how-to-buy-vs

Then most drop another couple hundred to make it actually have some of the cool Intellij IDEA features by adding in Resharper. I'm not trying to hate, I use VS at work, just I can see why it's not a popular startup ecosystem.

Re:More functional C# by mwg66 on Wednesday January 15, 2014 @03:37PM (#7065978)
I don't know how that price is arrived at but it's totally not realistic. I would expect to spend ~1.5K on VS2013 Professional plus associated dev. tools (R#, dotTrace etc).
Re:More functional C# by JackMorgan on Friday January 17, 2014 @06:28AM (#7075265)
Just yesterday morning (oh the timing) I shook my fists in rage after discovering the long awaited Fakes system for mocking static functions is only available in the Ultimate edition. An actual language feature, restricted to the 13k edition. Shrug, I had that in php 5 years ago...

What I don't get is: if people aren't even buying the top line IDE to use all its features, and are just buying the crappy subset IDEs, why use .NET at all? Where's the value proposition over Java/Scala? It runs on fewer architectures, the language is only mildly better than Java and certainly not better than Scala, and the long promoted IDE has less features and is exorbitantly overpriced. I just don't get it. Is it just inertia at this point? The question in my mind isn't: "why are so few startups using it?" It's "why is anyone still picking that as their business's main stack?"

I know my team is currently locked in to agreements with other companies who require it (naturally). So when a new customer wants our stuff, they have to handle it. Is that the main reason? Everyone using it is in a circle of dependence?

Oh I forgot to mention, the functionality of Fakes used to be free, but in the new iteration it no longer is, so they can squeeze a few more 13k editions.

Re:More functional C# by blar on Sunday January 12, 2014 @11:47PM (#7048972)
That really cracks me up! I work in C# probably 80% of the year (python and shudder vbscript make up the remainder) and I use lambda statements, implicit typing, and anonymous functions almost every day. The Linq IEnumerable<> extensions are also pretty well indispensable for me. My biggest complaint with C# is the limitations imposed by the static typing system: anonymous functions can't be generic, so you're forced to either declare delegates or explicitly declare each of your anon signatures; and KeyValuePair<> and Tuple<> both force you into sometimes excruciatingly, comically long object declarations, eg

Tuple<string, IEnumerable<string>, IEnumerable<KeyValuePair<string, bool>>

I've come to a point where I can comfortably write functional code in the language (though I should stress that I don't write "pure" functional code; I don't fall into the camp that abhors side effects in all scenarios). Day to day, it really is a fine language to work in, notwithstanding a few warts. In all honesty though, I'd rather be working in Python or a LISP most of the time

Re:More functional C# by JackMorgan on Monday January 13, 2014 @06:00AM (#7049912)
For me, LINQ was definitely a "gateway feature" to the lisp world. If you still use C# at work, I strongly suggest checking out F#: https://news.ycombinator.com/item?id=7048522
Re:More functional C# by jagawhowho on Sunday January 12, 2014 @06:16PM (#7047923)
You're not giving mono the credit it's due.
Re:More functional C# by egeozcan on Monday January 13, 2014 @04:14AM (#7049586)
I think Mono is great. It's just not a big market but of course it has great potential.
Re:More functional C# by viraptor on Sunday January 12, 2014 @08:03PM (#7048239)
It's in other places too. It's just hiding itself very well. For example Unity and the games that are based on it: http://en.wikipedia.org/wiki/List_of_Unity_Engine_games
Re:More functional C# by bsamuels on Sunday January 12, 2014 @07:09PM (#7048072)
>C# is one of the only languages that I can't remember reading any complaints about

I've been using C# for about 3 years now. A year or two into using it I thought I was developing fanboy syndrome so I started a list of all of the dumb quirks and pitfalls the language has. Last time I checked, there were only 3 or 4 items on the list compared my python/c++/java lists which have 1-2 orders of magnitude more quirks.

C# really is a solid language, it's just a terrible shame it had to have the Microsoft label attached to it.

Re:More functional C# by CmonDev on Monday January 13, 2014 @08:11AM (#7050304)
Every good thing has some sort of label attached to it (look at Android now)...
Re:More functional C# by TillE on Sunday January 12, 2014 @06:23PM (#7047939)
It's a little bit too verbose, it doesn't have quite the flexibility or metaprogramming ability of a language like Python.

But in general it's a very solid choice. You can even get around a lot of the inefficiency of GC by careful usage of structs.

Re:More functional C# by pionar on Sunday January 12, 2014 @10:01PM (#7048644)
With the rise of Roslyn[0], your second argument is kinda void (metaprogramming)

I never got the verbosity argument. Verbosity comes down to the person using the language. With C#, you can be as verbose as you want to. Do you have any examples?

What kind of inefficiency are you speaking of? the CLR's GC is one of, if not the, most efficient around.

[0] http://msdn.microsoft.com/en-gb/roslyn

Re:More functional C# by darklajid on Monday January 13, 2014 @06:48AM (#7050043)
Speaking as a C# developer:

I do consider C# more verbose than the languages I love to look at. Think 'SelectMany', 'FirstOrDefault' and similar constructs - even if you write functional C# as much as possible, it still .. is verbose. If compared to F#, Clojure for example.

I don't think that's an issue, mostly, but that I do agree with the notion that C# is 'verbose'.

Re:More functional C# by Touche on Monday January 13, 2014 @08:50AM (#7050494)
> Do you have any examples?

Sure, write a self-executing function in C#.

Re:More functional C# by paulmcpazzi on Monday January 13, 2014 @09:12AM (#7050604)

  ((Action)(() => Console.WriteLine("Hello")))();
or

  new Action(() => Console.WriteLine("Hello"))();
Yeah, it's verbose because you have to cast the lambda expression before executing it, but honestly I don't know any case where a self executing function can be useful in C#.
Re:More functional C# by Touche on Monday January 13, 2014 @10:23AM (#7051032)
Not too bad. Actions return null though. How about a self-executing function that returns a value? This is useful for assigning values to variables. IIRC it's going to start getting more ugly from here.
Re:More functional C# by noblethrasher on Monday January 13, 2014 @10:45AM (#7051183)

    (new Func<int>(() => 2))();
Re:More functional C# by CmonDev on Monday January 13, 2014 @08:09AM (#7050294)
But Python only supports dynamic where C# supports both static and dynamic. It's a good trade-off.
Re:More functional C# by EpicEng on Friday January 24, 2014 @04:05PM (#7118019)
Of course it's more verbose than a dynamically typed language. Silly comparison.
Re:More functional C# by frou_dh on Monday January 13, 2014 @12:11AM (#7049033)
An obvious complaint is that code like the OP's won't even run because it isn't pointlessly wrapped in a class ("class MyProgram").
Re:More functional C# by jdc0589 on Monday January 13, 2014 @11:02AM (#7051294)
I have 1. You can't do generic constructors for custom attributes. That's a pretty small complaint though...
Re:More functional C# by insidenorm on Sunday January 12, 2014 @10:07PM (#7048665)
Re:More functional C# by mcgwiz on Sunday January 12, 2014 @11:31PM (#7048925)
Whitespace insensitivity and inability to return void in generic contexts are "critical flaws"?

Anyway, no one's saying C# is flawless. Personally, I would love the ability to declare immutable graph references.

Re:More functional C# by V-2 on Monday January 13, 2014 @04:51AM (#7049691)
http://hestia.typepad.com/flatlander/2012/01/action-func-voi...

I fail to see how it is an "obvious critical flaw" :)

   You have to create a separate overload that takes an Action instead of a Func, 
   and has an identical implementation except for omitting the return keyword.  
   Granted, that’s not much work for a simple helper like the above, 
   but what if it were more complicated?  
No, it's simply not true that you need "an identical implementation except for omitting the return keyword"...

Eg. this would do the trick without repeating the implementation: http://pastie.org/8628864

Just two one-line overloads as entry points.

Re:More functional C# by raphaelj on Monday January 13, 2014 @09:43AM (#7050778)
Your solution is at least as ugly as the one mentioned in the article.

The problem is that void can't be used as a regular type identifier.

In a lot of langages (like Python, Haskell, F#, ...) there is a regular type for void. This type is often implemented as such :

  sealed struct Void {
  }
Then you can define Action<...> just as Func<Void, ...>.

As the compiler is smart enough to see there is only one kind of Void value, it can be entierly removed from the generated code and thus doesn't make your code slower.

Re:More functional C# by V-2 on Monday January 13, 2014 @10:08AM (#7050938)
And quite what's so ugly about it? It's hackish, but once you create these overloads, you don't need to worry about it anymore and you can call the method just as if Func<T> could be casted to Action. I don't think it can even be compared to the one suggested in the article, since it does not require "creating a separate overload with an identical implementation" (!!!), potentially copy-pasting hundreds of lines of code if the method in question was indeed "more complicated". This is ridiculous and the fact the author couldn't think of a workaround that didn't involve it baffles me.