Hacker News new | ask | show | jobs
by bpicolo 3326 days ago
I think I'm pretty sensitive to even a minor typing delay. That's not necessarily true for everybody, but it irks me.

> I even trust it to do automatic refactors. Sometimes.

Function extract refactors and the like are definitely within the realm of possibility. Once you want to refactor code across many files it becomes a lot harder in dynamically typed code, for sure.

I guess for a long time I sort of had this view of "ooh I have this awesome expressive language that won't get in my way and I can just power through it all". Don't get me wrong, I totally love python as a language. But I think languages like C# have started to make typing feel like it's more out of your way with type inference, etc.

I mean, this is the sort of code you can write in C# these days (to take a super trivial example):

  var somestuff = someList.Where(x => x.Id > 7)
    .Select(x => x.Name)
Typing in this case is 100% out of your way, but you get all the benefits regardless, and you get all those sort of nice functional-style list operations you expect in other languages.
1 comments

More often snippets like this can be even more straightforward:

  var somestuff = from x in someList
                  where x.Id > 7
                  select x.Name
Except when you have to wrap it in parentheses and tack a .ToList() onto the end of it, or use something outside the subset that the query syntax supports, it starts looking considerably more ugly than chaining the functions together.
The obvious answer is don't wrap a good query in parentheses, use a second line:

    var somestuff = from x in someList
                    where x.Id > 7
                    select x.Name;

    var somestuffList = somestuff.ToList();
For what it is worth, I personally consider ToList() harmful. I've done a lot of LINQ performance work and the first place I start is with a project-wide search for ToList and start to delete and/or replace calls to ToList to things more appropriate. List is more often than not the wrong data structure for a query result and I've seen too many people use ToList as a debugging crutch without understanding its performance impact.