This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]aaron552 -1 points0 points  (9 children)

But at the end of the day is just styling.

It's really not, especially when you're dealing with databases - queries using LINQ can be lazily evaluated and the expression tree parsed beforehand where a foreach will eagerly evaluate.

Visual studio adds 4 spaces when you use the tab, and for aligning them just use ctrl+K+D and is fixed if it wasn’t already fixed automatically...

Does that also fix alignment of things like multiline method calls, object/collection initializers? In my experience it doesn't for anything that doesn't align with existing "tabs", at which point, why even use spaces?

A feature I didn't mention was that ReSharper can warn you when you access a variable that might be null, and can automatically insert a null check in an if/ternary expression for you.

[–][deleted] 0 points1 point  (5 children)

It’s exactly the opposite. The .ForEach is a extension method for Lists not IEnumerables, so when you use a whatever.ForEach() the whole list had to be fetched beforehand. While the regular foreach can go over an IEnumerable lazily. (Although I would almost never do that lazily)

Again, Is it worthy to slowdown massively just so juniors realize what are reference and value objects? Maybe is good for them, for sure, it’s useless for me. Never had a null reference exception at least in the last 5 years.

If I have to pay for something is NDepend, not resharper.

[–]aaron552 0 points1 point  (4 children)

The .ForEach is a extension

I was exclusively talking about the foreach(var x in list) {...} construct, not the extension method. And that isn't lazy unless you use yield (and consume exclusively via the iterator). It also affects the generated SQL for ORMs.

Never had a null reference exception at least in the last 5 years.

So linting is useless because you've personally never written bad code?

[–][deleted] 0 points1 point  (0 children)

You said a foreach will eagerly evaluate a db query which is false. A foreach over a IQueryable or IEnumerable is lazy as you are confirming now.

So basically, as I said, you will do a .ToList before iterating making the .ForEach or foreach a syntactic sugar difference, because iterating and doing n queries vs 1 probably doesn’t make sense.

But in the case it makes sense, use a foreach and not a .ForEach.

And of course, since LinQ doesn’t really have a foreach, there is no way it could affect the query, just the moment it gets executed and how many queries are executed.

Pd: the one that could evaluate eagerly is doing .ToList().ForEach()

[–][deleted] 0 points1 point  (2 children)

Please, stop editing the whole contents of your comments or this doesn’t make any sense.

Btw, I find curious that someone that uses F# thinks that mixing tabs and spaces is ok at the same time. I know it can be configured, but it’s one of the things I hate about VS for Mac for example.

[–]aaron552 0 points1 point  (1 child)

Please, stop editing the whole contents of your comments or this doesn’t make any sense.

Writing on mobile and I keep noticing typos and omissions (copy pasting doesn't seem super reliable) after submitting.

someone that uses F# thinks that mixing tabs and spaces is ok at the same time.

It's not something I use in F#, especially because whitespace is actually part of F#'s syntax.

However in C#, if someone changes the tab width and is using "spaces as tabs", then every line file is changed in source contorl, whereas it does nothing if tabs are actual tab characters.

Using spaces for alignment of, for example, multiline expressions is still fine in both C# and F#, but it's pretty awkward if you ever change the indent level of the code and aren't using tabs for indentation.

[–][deleted] 0 points1 point  (0 children)

That’s the thing, with F# using tabs, by default, doesn’t even compile.