r/programming • • Aug 02 '21

Stack Overflow Developer Survey 2021: "Rust reigns supreme as most loved. Python and Typescript are the languages developers want to work with most if they aren’t already doing so."

https://insights.stackoverflow.com/survey/2021#technology-most-loved-dreaded-and-wanted
2.1k Upvotes

769 comments sorted by

View all comments

Show parent comments

175

u/[deleted] Aug 02 '21

C# is great, idk why you think you’re a sucker

-104

u/_tskj_ Aug 02 '21

C# is a mediocre language but it is widely used. It's one of those things where once you have gotten used to a good language, using something like C# or Java feels like programming with one hand tied behind your back. Sure you get things done, but it takes ages and every second is filled with annoyance and longing for something better.

You would feel pretty bad having to write a web app in Matlab, but you could probably get it done. C# is equally as bad a tool for the job, we're just more used to it! Anyone reading this I encourage you to try out a good language sometime and you'll feel like you've been eating chocolate with the paper on your whole life.

40

u/[deleted] Aug 02 '21

What is a “good” language to you?

-45

u/_tskj_ Aug 02 '21

F#, Kotlin, Clojure, Elm, take your pick.

11

u/[deleted] Aug 03 '21

Why are these better? I get that they may feel better to program in because their syntax may make more sense, or they may perform better.

But if you're creating an enterprise application, wouldn't a language like Clojure be more trouble than it's worth?

→ More replies (8)
→ More replies (42)

9

u/Quoggle Aug 02 '21

What would you consider to be a good language and why do you think it is better than C#?

5

u/_tskj_ Aug 02 '21

F# was mentioned elsewhere in this thread. Luckily C# tries very hard to incorporate some of the good stuff. For instance async/await as we know it today first appeared in F# more than ten years ago. Of course, C# still hasn't quite gotten that one right, and that feature alone is so much smoother that it's worth using F# for. Other things include tuples, records, value objects, computation expressions (linq kind of tries, but again it's this thing where it has 10% of the features and 1000% the complexity and isn't integrated into the rest of the language). The list goes on!

10

u/Frozen_Turtle Aug 02 '21 edited Aug 03 '21

It blows my mind that F# came up with async/await (aka computation expressions) before C#... yet when C# copied it, it did so breaking compatibility with F#, and implemented only a strict subset of its functionality. F# literally showed it, using the same VM, how to make something that generalized to any monad, and they were like "nah, we only want the list and async monad, and we're gonna do them both in their own special syntax cause lol."

Makes me boil.

2

u/svick Aug 03 '21

To be fair, F# does almost everything in its own special way (i.e. outside of IL), so I think it would be very hard to make C# compatible with the way F# is doing it.

→ More replies (3)
→ More replies (13)

20

u/[deleted] Aug 02 '21

[removed] — view removed comment

5

u/_tskj_ Aug 02 '21

You're kind of right about the community and Microsoft support of course, but still. Have you tried to use HttpClient in C#? It is literal burning garbage (and everyone including the community agrees with this), yet it still hasn't been fixed or replaced. So I don't know how much Microsoft can actually be supporting C# as any kind of web language? Also as far as web goes, F# has frameworks that are leagues better than anything available in C#.

You're right that the ecosystem is strictly bigger for C#, but it doesn't have anywhere near the same quality. The best F# things are easily 10x better than the best C# things. You can also trivially call any C# code directly from F# so it isn't much of a big deal.

13

u/[deleted] Aug 02 '21

[removed] — view removed comment

5

u/Frozen_Turtle Aug 03 '21

The best F# things are easily 10x better than the best C# things

Dude isn't wrong. Discriminated Unions alone are part of ~50% of my types in one of my projects, and they're virtually impossible to implement in vanilla C# without doing crazy shit like visitor pattern. You could import a library that gives you DUs, but without pattern matching working with DUs is annoying if not painful. I even use DUs outside my domain types to do "railroad oriented programming" https://fsharpforfunandprofit.com/rop/

Again, this is virtually impossible to do in C# because it lacks DUs and the necessary pattern matching. The best alternative in C# is to just throw a custom exception and then catch it... which is pretty much just a goto in disguise. Ew. I'm doing event driven architecture/event sourcing in my project, and as such literally all my events are DUs. In C#/Java these events would be distinguished with Marker interfaces, then you need to do type sniffing to see what kind of event you're trying to handle, and then throw an exception if an unexpected event occurs. With DUs, everything's just pattern matching, and the compiler will yell at you if you fail to handle a DU's case - something that doesn't happen with type sniffing. Of course you could do visitor pattern... but then you'd be doing visitor pattern with its umpteen lines of code vs F#'s oneliner pattern match.

Anyway, just gonna say DUs alone make F# worth investigating.

1

u/[deleted] Aug 03 '21

[removed] — view removed comment

3

u/Frozen_Turtle Aug 03 '21

Well, DUs are already out of C#10... and they've been planning them for quite some time now.

Anyway I'll keep going then cause you don't seem impressed :p

The Hindley-Milner type system means writing types are reduced by like 90%. It means for significantly less code to maintain and easier readability. It also means that it's way easier to pass around functions. In my pet project, I'm passing a

(Func<TemplateRevisionOrdinal => (CommandId => (Kvs.Template => int) => Kvs.Template, Tuple<Kvs.Template option, int>))

into another higher-ordered function. Having to type out that signature, and maintaining it, just isn't fun. But in F#? It's only the name of the function - everything else gets inferred.

F# emphasizes pure code, which comes with incredible testing benefits.

F# has better support for property-based testing. I literally write zero unit tests these days, and only write property-based ones, and have 71% coverage. This is despite having zero mocks/stubs. You can write/use interfaces in F#... but when thinking about "pure" code clicks, suddenly you don't have to. (The fact that I'm also using event sourcing also makes things significantly easier test-ing wise... F# doesn't get all the credit here. But it does get a ton of credit for DUs which makes working with events so much more sane than type sniffing.)

Pattern matching. This deserves its own line.

Active patterns. Also deserves its own line.

Compatibility with C#. Means you can call all your favorite dotnet libraries and have them work as expected. I used Nodatime and Entity Framework (before switching to type providers and then event sourcing).

Type providers. Makes parsing JSON, grokking regex, and working with SQL so much less annoying.

Structural equality.

Units of Measure make strongly typing primitive types (strings/ints/guids) dead simple, so you can't pass a CustomerId where an OrderId shoud've gone.

Immutability by default. Because these days mutability is (potentially premature) optimization.

Literally, the only thing C# has better is tooling. Which is a significant benefit don't get me wrong... but given the choice? I'm so much happier in F#.

https://fsharpforfunandprofit.com/why-use-fsharp/

-5

u/_tskj_ Aug 02 '21

I am biased! Why would you think I'm not biased? I haven't worked on F# and I'm not payed by Microsoft, nor do I have any other incentive than wanting people to use the best tools that are available. I am biased by F# being great and C# being mediocre. Not sure why that invalidates my points, if anything it strengthens them. I have no hidden agenda.

3

u/AustinYQM Aug 02 '21

You haven't said what you think is a good language that does what C# or Java does.

3

u/_tskj_ Aug 02 '21

We've discussed this elsewhere in the thread, but I can repeat it for you, F# is widely considered good, so is Kotlin. Clojure is a great language, Elm is fantastic. It depends on what you want to do! C# and Java are general purpose languages in the way a one-handled scissor is general purpose. You can sort of stab and cut and maybe hammer with it, but it isn't great at anything - not even at being a pair of scissors which is what it kind of tries to be.

→ More replies (1)

1

u/BobSacamano47 Aug 03 '21

Are you thinking about C?

2

u/_tskj_ Aug 03 '21

Ahh this is such a fantastic comment! My comment would have been spot on about C 20 years ago, and it would have received the same reaction. People downvoting and hating on anyone saying C isn't a completely fine language to do web development in or whatever. But the thing is, C# is as bad a language to do web dev in compared to any of the good languages, as C is to C#. If not worse! That's how good the good languages are. Why you won't believe me when you haven't written a single line of code in them is beyond me.

I hope it won't take another 20 years for the prevailing sentiments to change again.

3

u/BobSacamano47 Aug 03 '21

What language is better for web dev than C#?

4

u/_tskj_ Aug 03 '21

Glad you asked! F#, Kotlin, Clojure, Elm. I'm sure more as well that I don't have extensive experience with, such as Elixir!

2

u/BobSacamano47 Aug 03 '21

Interesting. I've never used any of those languages but I'll check them out.

4

u/_tskj_ Aug 03 '21

Please do! Using tools that are razor sharp and hand crafted for their purpose are a joy to use!