News for hackers. Stuff that matters.
Re:How generics were added to .NET by ChicagoDave on Monday March 05, 2018 @08:06PM (#16526074)
I started looking at the source diffs and it triggers a panic attack. That's a ton of work.

All the more reason to admire and appreciate MS Research and the development of C# generics. Really amazing accomplishment.

And Linq is one of the single greatest inventions in modern day programming.

Re:How generics were added to .NET by EnderMB on Tuesday March 06, 2018 @04:59AM (#16527921)
LINQ is the reason I became a .NET developer after leaving university.

I was bored of Java at university, and as the project I was basing my dissertation on was a web-based search engine I decided to use C# and ASP.NET. The professor helping me was fine with it, since he didn't know PHP or Ruby, and he felt he could read C#.

I came across some stumbling blocks with some logic, so I remember posting on a forum somewhere asking for help with setting up a data structure. Someone sent me some LINQ, and I thanked them for the pseudocode. When they pointed out that it was real functioning code, I plopped it into Visual Studio and the whole thing worked. From that moment, I fell in love with the language - ASP.NET WebForms less so, but shortly after this MVC became a thing in the .NET world and I jumped on the bandwagon.

A decade later, and while I've moved onto other languages I still fight C#'s corner, and LINQ/the lambda syntax is one of the first points I raise when people bitch about Micro$oft. The only negatives about working as a .NET developer is being locking into an ecosystem, so if Microsoft and the .NET Foundation can get .NET Core to be feature compatible with .NET Standard then they've got a winner on their hands.

Re:How generics were added to .NET by mythz on Tuesday March 06, 2018 @11:11AM (#16529701)
Many other languages offer similar functional APIs for querying collections, here is C#'s 101 LINQ Examples rewritten in different languages:

   https://github.com/mythz/swift-linq-examples
   https://github.com/mythz/kotlin-linq-examples
   https://github.com/mythz/clojure-linq-examples
   https://github.com/mythz/java-linq-examples
   https://github.com/mythz/dart-linq-examples
   https://github.com/omnibs/elixir-linq-examples
   http://templates.servicestack.net/linq/
Java 8+ has since improved with their Streams API. The primary benefit that differentiates LINQ apart is that you can easily capture the Expression tree of the LINQ expression and rewrite its intent to apply to other sources, commonly used in LINQ -> SQL to provide a Typed Expression API for generating equivalent SQL to run on an RDBMS.
Re:How generics were added to .NET by dvlsg on Tuesday March 06, 2018 @12:34PM (#16530350)
Not op, but I think these are the equivalent of linq to objects. Linq also has the capability to treat lambdas as expression objects, so instead of executing them, you may further interpret them and turn them into something else. Like sql statements.
Re:How generics were added to .NET by mythz on Tuesday March 06, 2018 @04:07PM (#16532126)
I covered capturing LINQ expressions in my last sentence.
Re:How generics were added to .NET by ozim on Tuesday March 06, 2018 @05:38AM (#16528036)
I am .NET developer, I thought I will be Java dev or whatever else web backend brings. But years are showing .NET is getting well. Msft has skin in the game with .NET ecosystem and it is "developers, developers, developers". Other ecosystems don't have huge company living off it. Oracle for Java also does not have skin in the game, they will just take over next big thing and milk it away.
Re:How generics were added to .NET by pjmlp on Tuesday March 06, 2018 @06:20AM (#16528147)
Oracle was one of the first companies to adopt Java.

They used to do presentations together with Sun, had the crazy Network Computer idea together with those Java Stations at Sun, ported their installers to Java, were the first RDBMS to allow stored procedures to be written in Java, had their own JVM, IDE and JEE server long before Sun started to get into troubles.

Have kept Java team together, saved Sun labs, turned the Maxime research work into Graal, are making the effort of supporting AOT compilation (tabu at Sun),....

I am a polyglot developer, and while Oracle could be doing a better job, they surely are doing much better than Sun was doing on its later days.

Who knows, if Google hadn't ripped off Sun and they were getting some Android revenue, maybe Sun would still be around.

Re:How generics were added to .NET by geodel on Tuesday March 06, 2018 @09:33AM (#16529058)
> Who knows, if Google hadn't ripped off Sun and they were getting some Android revenue, maybe Sun would still be around.

Or maybe if Sun showed some promise with J2ME and tried to challenge iOS it would have been main iOS competitor instead of Android. But J2ME did not deliver much and the idea to grab some bullshit patents revenue, which Oracle tried, failed.

In copyright case Oracle may still get some money but after belatedly joining CNCF Oracle would not like to be on warpath with Google.

Re:How generics were added to .NET by pjmlp on Tuesday March 06, 2018 @09:39AM (#16529089)
J2ME was doing perfectly fine in Nokia and Sony-Ericson devices, and we already had SavaJe OS when Android happened.

Android fragmentation, OEM customizations, lack of enforced updates and cheapo unresponsive 100 € devices are no better than the devices that gave bad name to J2ME.

Re:How generics were added to .NET by lloydatkinson on Friday March 09, 2018 @11:50AM (#16552992)
> so if Microsoft and the .NET Foundation can get .NET Core to be feature compatible with .NET Standard

What? It literally already is, all the time. If anything it's full .NET that lags behind standard often.

Re:How generics were added to .NET by btschaegg on Tuesday March 06, 2018 @02:08AM (#16527374)
Regarding LINQ: I really like certain parts of it, dislike others (mainly inline Select-statements and the EntityFramework built on top of it), but I'd be hard-pressed to call it the greatest invention of any time. PEP 255 laid the ground work for similar language features in 2001, and I doubt that the python guys "invented" all of that out of thin air (cf. Reference #4 in the PEP).

What you can argue is that LINQ made this stuff available to more developers (with useful syntax and in a statically typed language, which also must have taken a lot of work), but filter/map/reduce have been around for quite a while.

That obviously doesn't make it less useful or the underlying tech less impressive though.

Re:How generics were added to .NET by tehlike on Tuesday March 06, 2018 @02:40AM (#16527484)
The magic behind LINQ is that it's a query layer on top of a backing data store. When it first came out, you'd see data providers written against twitter, file system and everything like that. Then entity framework & nhibernate linq provider came out. It was great, hid a lot of details from user, brought static type checking to otherwise very hard to "verify" sql. You'd now think in terms of objects, and not tables.

Linq compiler compiled the whole query into a AST, which you could then convert to a backing query your data store could understand.

To date, I still think Linq was great. I was indifferent to the "sqlized linq", but i liked the lambda quite a lot. It was a nice abstraction and a pretty good language to write queries on.

Disclaimer: I worked on NHibernate Linq integration ~10 years ago.

Re:How generics were added to .NET by brusch64 on Tuesday March 06, 2018 @02:59AM (#16527559)
What is your opinion on the state of NHibernate ?

I've started using it in 2009. I am still using it in my projects, but I am still not sure if NHibernate is functional complete or if the project is nearly dead.

It works fine for me (if it is not worth the effort I am using Dapper.net), but it doesn't seem that there is much active development going on.

Re:How generics were added to .NET by eldavido on Tuesday March 06, 2018 @11:24AM (#16529800)
On the way out (daily user here).

I started a project about 4yrs ago, it was EF vs NH. Went with NH because EF was still pretty immature.

The momentum is pretty clearly toward EF IMO. NH is missing a lot, including proper migration tooling and deep async support. But I don't think that's the real issue. The more foundational problem in my view, is that NH deeply assumes blocking/synchronous database access. I have no idea how NH lazy loading will ever work with async. I imagine you'll have a bunch of FK refs all marked Task<T> that will have to be awaited? In any case, my bet is that EF will get there a lot more quickly than NH.

Re:How generics were added to .NET by tehlike on Tuesday March 06, 2018 @03:06AM (#16527581)
To my surprise, it seems fairly active: https://github.com/nhibernate/nhibernate-core

I stopped working on nhibernate around 2010-2011, when i started masters. I did only keep in touch with one friend - i am not very sociable person. So I guess short answer is, i am not sure to be honest.

Back in 2008ish, I was thinking it was going to die because Entity framework provided a great support for linq, and it had a great hype. A bunch of enterprises moved away from NHibernate (we also had a lot of legacy from XML configuration - a bunch of internal data structures were referencing xml), so it was clunky. Fabio, Oren (Ayende) did a bunch of improvements, I worked a bunch of shortening initialization times and so on. I think Ayende did a very good job with Linq initially, but there were plenty of edge cases that i remember having to fix :) It was my first opensource project as a core member (second and last was castle project) - so it has a very special place for me :)

Re:How generics were added to .NET by brusch64 on Tuesday March 06, 2018 @03:59AM (#16527729)
Okay - it really seems to be quite active right now. Thank you for your insight.

I've used the Linq queries in one of my projects, but I like the QueryOver statements more (a little bit too much black magic in the Linq queries).

But I believe that it was a great effort - so let me thank you for that !

Re:How generics were added to .NET by mattmanser on Tuesday March 06, 2018 @05:14AM (#16527966)
In my expereince you shouldn't even touch the black magic stuff unless you're a small org or it's a throwaway app.

Linq with the EF is great for simple queries and updates, anything else and you're in for serious performance problems as soon as the app scales. Better to drop to normal SQL for complicated data loading.

Even MS can't write decent LINQ queries, their ASP.Net identity provider is now the most 'expensive' bit of our app now because they used expensive LINQ queries instead of using raw SQL queries. Admittedly our use-case is abnormal as the specific problem we have is that because of the way users are added their password gets reset almost immediately, as they're invited by an organiser. It also means new users are constantly being added. When the password reset is saved it completely unnecessarily "verifies" the update by making sure the username and email are unique, which means two UPPER()s and CONTAINS()s on string fields. Unlike the old provider there's no usernamelowered field already in the db to avoid this.

We can fix it by over-riding these queries, but it's annoying that the ASP.Net team took a core framework piece that was very performant with fast performing SQL and made it substandard. At least I can look at the code now ;).

Re:How generics were added to .NET by WorldMaker on Tuesday March 06, 2018 @10:51AM (#16529530)
I've never thought of LINQ as black magic and have scaled some astoundingly complex LINQ queries in a past life. I've even done some things in LINQ optimization that you couldn't do in just "normal" SQL (clever joins of databases on different servers without linked servers; complex client-side caching and statistics work).

I think LINQ gets a lot of flak it doesn't necessarily deserve in complex queries due to people stopping at the black box and assuming black magic. It's a very functional programming paradigm embedded in an otherwise procedural world, and so the skills to debug complex LINQ should be unsurprisingly just a bit different than debugging most else in C#. I don't blame people for stopping at the black box. I just think more people should know that you can do more than stop at the black box.

(Also, it amuses me that your example from ASP.NET identity's changes have nothing to with that it should be using raw SQL queries versus LINQ, and everything to do with denormalization versus the query execution engine. It shouldn't be a huge surprise that Microsoft might trust SQL Server to be able to UPPER() and CONTAINS() fast enough, and the queries rare enough that it isn't necessary to denormalize that information.)

Re:How generics were added to .NET by tehlike on Tuesday March 06, 2018 @01:01PM (#16530605)
Check ravendb and see how linq can be a first class citizen in a database.
Re:How generics were added to .NET by mrits on Tuesday March 06, 2018 @09:07AM (#16528908)
Most of the points you brought up existed even in .NET before LINQ with DataTables/DataSets
Re:How generics were added to .NET by _r_o_y_ on Tuesday March 06, 2018 @09:38AM (#16529082)
For me DataTables where magic objects with no type safety at compile time.
Re:How generics were added to .NET by WorldMaker on Tuesday March 06, 2018 @10:57AM (#16529576)
After LINQ, I entirely refused to work on DataTables code without refactoring it to something more sane, even if just ugly DBReader junk and its version of casting hell. I was briefly sad that .NET Standard 2.0 had to bring in DataTables and preserve that ugliness for the rest of foreseeable time.
Re:How generics were added to .NET by tehlike on Tuesday March 06, 2018 @03:49PM (#16531988)
Type-safety is a blessing.
Re:How generics were added to .NET by tehlike on Tuesday March 06, 2018 @03:49PM (#16531985)
datatables are pretty much how regular SQL behaves, there are no magic behind them, right?

I would have prefered using DataReader, most often.

Re:How generics were added to .NET by wenc on Tuesday March 06, 2018 @10:32AM (#16529406)
Filter/map/reduce are ubiquitous ideas from the functional world, which in turn are ideas drawn from mathematics. Math has pre-existed many of our programming constructs, so in that sense, nothing was really invented as such.

To me, what LINQ offers is a very nice orthogonal DSL that allows programmers to express these thoughts. The underlying constructs are universal, but one could argue that LINQ itself was invented. LINQ was apparently guided by category thinking [0], which makes it fairly elegant, but in terms of expressiveness it is probably similar to SQL. It's all set theory underneath anyway. Unlike SQL however, LINQ does force the SELECT statement to the very end of the query expression, which makes IDE auto-complete work better due to avaiable context. :)

I first had the realization that most data manipulation operations on list-like or table-like objects were actually just glorified set operations (and there was a certain universality to them regardless of query language syntax) when I read this quote [1]: "The turning point was a conversation with Erik Meijer. He told me how categorical thinking guided him in designing LINQ, and explained how category theory brings out a simple relationship between various kinds of databases. The diagram below comes from a paper he wrote on this. It turns out that so-called No-SQL databases are in a categorical sense co-SQL databases."

[0] https://queue.acm.org/detail.cfm?id=2024658

[1] https://www.johndcook.com/blog/applied-category-theory/

Re:How generics were added to .NET by golergka on Tuesday March 06, 2018 @02:43AM (#16527497)
I always saw Linq as the iPhone of functional programming: it didn't really invent anything, but put existing things into such an appealing package for mass-market that it really finally made all those things popular and usable by people (developers) at large.
Re:How generics were added to .NET by eldavido on Tuesday March 06, 2018 @11:27AM (#16529827)
This is a broader theme in how technology develops.

When I look at technologies like bitcoin, it's just proof of work/puzzles (a well-understood defense to sybil attacks) + basic crypto primitives like signatures + some of the p2p stuff from bittorrent, etc.

There's real genius in combining the pieces, though. I also spent a few years in serious CS academia so not clear how widely these things (especially puzzles) were known beyond universities.

Re:How generics were added to .NET by btschaegg on Tuesday March 06, 2018 @03:06AM (#16527579)
Yes, I think you sum it up pretty nicely.
Re:How generics were added to .NET by Guillaume86 on Tuesday March 06, 2018 @04:34AM (#16527850)
It seems you're just thinking of the IEnumerable API and not LINQ at large, which includes the Expression and IQueryable API and enable things like LINQ-to-SQL.
Re:How generics were added to .NET by btschaegg on Tuesday March 06, 2018 @07:05AM (#16528305)
...which I'm also not a big fan of after having seen their implications in older products (i.e. ones that had to be maintained for a while). In most cases, they made the problem worse.

Plus, while they are enabled by other techniques, those weren't invented in LINQ, either.

Re:How generics were added to .NET by coldtea on Tuesday March 06, 2018 @06:04AM (#16528111)
>PEP 255 laid the ground work for similar language features in 2001, and I doubt that the python guys "invented" all of that out of thin air (cf. Reference #4 in the PEP).

LINQ is not about generators...

Re:How generics were added to .NET by btschaegg on Tuesday March 06, 2018 @07:00AM (#16528292)
The IEnumerable parts are mainly enabled by coroutines, which for this case more or less equate to generators. The other parts are pretty much what I've already seen so much problems with that I wouldn't touch them with a 10 foot pole (see the "black magic" comment by others, that sums it up nicely for me).

But those are also more or less just about building ASTs and transforming them, something Lisp has done for decades.

Re:How generics were added to .NET by matthewwarren on Tuesday March 06, 2018 @04:49AM (#16527891)
> I started looking at the source diffs and it triggers a panic attack. That's a ton of work.

Don't forget it took several people a few years to do all that! But yeah, I agree, it was an impressive achievement!