News for hackers. Stuff that matters.
Re:How many keywords I can fit into a single C# expression? by ramenmeal on Wednesday February 06, 2019 @08:27PM (#19102089)
C# is a mess. I'd love a C# light.
Re:How many keywords I can fit into a single C# expression? by stcredzero on Wednesday February 06, 2019 @09:02PM (#19102266)
First follow Great Scott's instructions for making an Arduino capacitative switch light.

https://www.youtube.com/watch?v=mWR9Q_pTagw

Then enable it to be integrated with C# code:

https://www.allaboutcircuits.com/technical-articles/csharp-w...

Voila! A C# light!

Re:How many keywords I can fit into a single C# expression? by maxxxxx on Wednesday February 06, 2019 @08:36PM (#19102131)
What for? You can write code C# 2.0 style if you want to.
Re:How many keywords I can fit into a single C# expression? by nicoburns on Wednesday February 06, 2019 @09:06PM (#19102288)
Really? C# seems very balanced and coherent to me. What seems messy to you?
Re:How many keywords I can fit into a single C# expression? by klodolph on Wednesday February 06, 2019 @09:10PM (#19102315)
The messy part of C# is the way it does function overloading. (Speaking as someone who likes C#.)
Re:How many keywords I can fit into a single C# expression? by lsadam0 on Wednesday February 06, 2019 @09:23PM (#19102397)
Why do you think function overloading is messy?
Re:How many keywords I can fit into a single C# expression? by klodolph on Wednesday February 06, 2019 @09:37PM (#19102458)
I’m not making any claims about function overloading in general. Only C#.

It interacts in surprisingly complicated ways with a surprising number of other parts of the language. It causes problems with prospective new features. IIRC there have been a number of bugs in the spec and in the compiler wrt overloading. Given the overall high level of expertise of people working on the spec I would say it’s a bit of a minefield, compared to the rest of the language.

Edit: Found a Q&A by John Skeet, https://youtu.be/8UvTdobOiJk?t=1292

“Overload resolution is the nexus that every feature ends up contributing to. […] All of these things make overload resolution and type interface really really really complex and it’s always a bit of the C# specification that I found hardest to understand […] and it turns out so did the spec designers, because they got it wrong, and we’ve been trying to fix it.”

Re:How many keywords I can fit into a single C# expression? by OskarS on Thursday February 07, 2019 @08:49AM (#19105156)
It might be tricky from a standards point of view, but as a user of the language, I don't think I've ever had an issue with how it handles overload resolution. Every once in a while you get an "call is ambiguous" compiler error, but I've always found the "ambiguity" to be reasonable and easy enough to fix (by making generics explicit or using an explicit cast). It's also a very minor bummer that you can't overload on return type, but that is A LOT to ask of a language.

Generally speaking, I've found C# to be a very pleasant language to work in, by far my favorite in that particular "lane" of computer languages (i.e. annoyingly object-oriented enterprise languages, like C#, Java or C++).

Re:How many keywords I can fit into a single C# expression? by lsadam0 on Friday February 08, 2019 @08:49AM (#19114042)
Thanks for the detailed reply. There’s lots here I had not considered. I’ve realized my overloading implementations have been rather simple cases.
Re:How many keywords I can fit into a single C# expression? by tonyedgecombe on Thursday February 07, 2019 @05:11AM (#19104213)
I sort of agree, it's OK if you have a history with it because all these features are incremental. However if you are a beginner then it could look overwhelming.

JavaScript has the same problem but is much worse.

It seems we don't know when to stop with this stuff.

Re:How many keywords I can fit into a single C# expression? by grndn on Thursday February 07, 2019 @08:02AM (#19104915)
Re:How many keywords I can fit into a single C# expression? by hornetblack on Wednesday February 06, 2019 @09:01PM (#19102261)
You can set the language version and go back to pre linq, pre async days.
Re:How many keywords I can fit into a single C# expression? by coolreader18 on Wednesday February 06, 2019 @08:46PM (#19102193)
C natural? (I tried to type U+266E but it didn't save)
Re:How many keywords I can fit into a single C# expression? by klodolph on Wednesday February 06, 2019 @09:07PM (#19102292)
Why not C-flat? We already have a C--, to pair with C++.

https://www.microsoft.com/en-us/research/wp-content/uploads/...

(Note to the pedants: Although C-flat and B are enharmonically equivalent they are not the same.)

Re:How many keywords I can fit into a single C# expression? by SmellyGeekBoy on Thursday February 07, 2019 @04:42AM (#19104118)
I'd just like to throw C#m into the mix!
Re:How many keywords I can fit into a single C# expression? by jasonboyd on Wednesday February 06, 2019 @08:36PM (#19102135)
A mess in what way?
Re:How many keywords I can fit into a single C# expression? by ramenmeal on Wednesday February 06, 2019 @10:52PM (#19102858)
So many features have been added over time, I think it's beginning to show that the features are piled on top of a language that weren't designed for them.

Things that I think feel awkward are the tuples handling, switch case pattern matching. As a go developer, when I see the Func, Action, Expression, and Predicate objects... oof I shudder. When you layer function overloading on top of those, you can get in a mess.

Obviously it's an unpopular opinion, but I would like to see what c# would look like if it was designed from scratch again.

Re:How many keywords I can fit into a single C# expression? by mattnewport on Wednesday February 06, 2019 @11:13PM (#19102939)
I tend to think F# is what C# would look like if designed from scratch these days. My take is that C# started out not very good because it copied a not very good language (Java) but they improved on Java a bit and have continued to add things that tend to improve the language within the constraints of remaining backward compatible.

Choosing just on the language I wouldn't choose C# but when working in an ecosystem built around C# (like Unity for me currently) I appreciate many of the features as making things a bit nicer.

Re:How many keywords I can fit into a single C# expression? by oaiey on Thursday February 07, 2019 @12:12AM (#19103167)
I disagree. First of all, F# is functional and therefore has another design. C# also intentional followed C style languages to pick up developers. C# was built for the masses while functional programming is for the elites (F# is has 10k devs using it, VB.NET has 100k and C# more than a million active users). I agree that there are some syntax they would have designed differently when they would have understand the functional programming influence they have today a bit earlier.

When they would design it today from scratch, I think they would look at JavaScript.

Re:How many keywords I can fit into a single C# expression? by mattnewport on Thursday February 07, 2019 @12:36AM (#19103262)
C# comes from a statically typed language tradition (the dynamic keyword aside) and has very little in common with Javascript beyond the surface level of curly braces. The trend in C# features seems very much influenced by functional programming, adapted to be more familiar and palatable to non functional programmers.

Some features of C# that seem influenced by functional programming in general or F# in particular include lambdas, type inference, Enumerable (F# pipelines), pattern matching, tuples, null coalescing (a Maybe if you squint), expression bodied members, record types and Range expressions. There is also what looks like an 'aesthetic' influence of F# in language features that reduce ceremony and make for more concise code like auto properties as well as a functional inspired recommended practice of making immutable types.

Re:How many keywords I can fit into a single C# expression? by oaiey on Thursday February 07, 2019 @03:31AM (#19103872)
Fair assessment and I agree.

My comment regards JavaScript was more about to pick up existing developers. C# was always meant for productivity. A rapid learning curve (as opposed to learning functional programming first) is very important here.

Re:How many keywords I can fit into a single C# expression? by titanix2 on Thursday February 07, 2019 @12:20AM (#19103192)
F# wasn't created from scratch at all, it's the last descendant of the ML language family. It was originally developed with some compatibility in mind. So no, a hypothetic today's C# wouldn't look like F# if is wasn't intentionally functional.
Re:How many keywords I can fit into a single C# expression? by mattnewport on Thursday February 07, 2019 @12:42AM (#19103289)
I didn't say that F# was created from scratch, I'm familiar with its heritage. My point was that C# started as a slightly improved Java but the trend in new language features, particularly in recent years, has shown a strong influence of functional programming in general and F# in particular. Hence the idea that if in some hypothetical universe C# was making changes not constrained by backwards compatibility I would expect it to look more like F# and less like Java.
Re:How many keywords I can fit into a single C# expression? by pjmlp on Thursday February 07, 2019 @03:33AM (#19103877)
In that hypotetical universe, without Java history, Microsoft would be focusing on VB and C++, with COM Runtime having replaced COM+.
Re:How many keywords I can fit into a single C# expression? by moron4hire on Wednesday February 06, 2019 @11:09PM (#19102925)
Quite the contrary, as someone who has been doing C# since it was invented, I find all of the new features to be implemented in a very coherent, even respectful way. It can seem like things are arbitrarily tacked on, but once you start using the features in earnest, it becomes quite clear that they are very well designed, very well thought out. I have much, much respect for the C# language committee. They've done amazing work in adding features and keeping the language clean and forwards compatible!
Re:How many keywords I can fit into a single C# expression? by oaiey on Thursday February 07, 2019 @12:16AM (#19103178)
Well said. I am also on that journey and compared to C++ the complexity is still very low and readability very high. I think the only C# feature I have not cracked yet is co/contravariance. And that is more due to the fact, that you rarely need to declare it.
Re:How many keywords I can fit into a single C# expression? by mattnewport on Thursday February 07, 2019 @12:46AM (#19103306)
I generally like the new features of C# but I still find C++ to be a much more coherently designed language. C# can't escape its poisoned roots in Java despite its best efforts.
Re:How many keywords I can fit into a single C# expression? by rjf72 on Thursday February 07, 2019 @12:57AM (#19103354)
Out of curiosity, what do you find poorly designed about them? In my opinion many of these things are elegant to the point of self documentation. Switch case pattern matching in particular is just great:

        void foo()
        {
            object pi = 3.14d;

            switch (pi)
            {
                case int i:
                    Console.WriteLine("pi is an int of value " + i);
                    break;

                case float f:
                    Console.WriteLine("pi is a float of value " + f);
                    break;

                case double d:
                    Console.WriteLine("pi is a double of value " + d);
                    break;

                default:
                    Console.WriteLine("pi is of an unknown type.");
                    break;
            }
        }
Elegance is of course in the eye of the beholder, so what would you propose as an improvement to something like this?
Re:How many keywords I can fit into a single C# expression? by vermorel on Thursday February 07, 2019 @02:10AM (#19103591)
Well, C# 8 will be having something much nicer syntax actually:

        void foo()
        {
            object pi = 3.14d;

            Console.WriteLine(pi switch 
            {
                int i => "pi is an int of value " + i,
                float f => "pi is a float of value " + f,
                double d => "pi is a double of value " + d,
                _ => "pi is of an unknown type.";
            });
        }
Check-out https://neelbhatt.com/2018/05/19/c-8-0-expected-features-par... Cheers!
Re:How many keywords I can fit into a single C# expression? by maxxxxx on Wednesday February 06, 2019 @11:09PM (#19102922)
To some degree I agree but I am pretty impressed how much they have been able to add while still keeping C# a pretty clean language. I am sure most language designers dream about starting from scratch....
Re:How many keywords I can fit into a single C# expression? by pjmlp on Thursday February 07, 2019 @03:25AM (#19103849)
Like any product or human languages, programming languages either evolve to make it easier to deal with the complexity of the problems their users need to tackle, or they fade away.

Every programming language that advertises itself as simple, it isn't any longer simple if it actually is adopted by the market at large.

Go is the newest example, already with a few quirks, needed to revamp their dependecy story, the team finally cave in to look into better solutions for error handling and generic programming.

Re:How many keywords I can fit into a single C# expression? by hombre_fatal on Thursday February 07, 2019 @04:00AM (#19103967)
> Go is the newest example, already with a few quirks

Here's a fun game for people who use Go: why does this error?

https://play.golang.org/p/6LTbtuocu5-