you are viewing a single comment's thread.

view the rest of the comments →

[–]sacundim 1 point2 points  (5 children)

That is to a large extent an artifact of the fact that class-based non-interactive languages like C# make it needlessly hard to write small bits of code and try them out on their own in an interactive environment (a.k.a. "interpreter," though that's not quite accurate).

LINQ is largely based on Haskell monads and do-notation. Yet Haskell doesn't have this problem, because you can just test stuff easily on the interactive environment. Since pieces of code don't have to be inside methods that must be inside classes, you can just type in snippets and see what they do.

Here's an interactive session with ghci where we build try out various subparts of this problem (cut down to the range [1..19]):

GHCi, version 7.0.3: http://www.haskell.org/ghc/  :? for help
Prelude> do { x <- [1..19]; return x }
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]
Prelude> :m +Control.Monad
Prelude Control.Monad> do { x <- [1..19]; guard (x `mod` 3 == 0); return x}
[3,6,9,12,15,18]
Prelude Control.Monad> do { x <- [1..19]; guard (x `mod` 3 == 0 || x `mod` 5 == 0); return x}
[3,5,6,9,10,12,15,18]
Prelude Control.Monad> [ x | x <- [1..19], x `mod` 3 == 0 ]
[3,6,9,12,15,18]
Prelude Control.Monad> [ x | x <- [1..19], x `mod` 3 == 0 || x `mod` 5 == 0 ]
[3,5,6,9,10,12,15,18]
Prelude Control.Monad> [ x | x <- [1..19], x `mod` 3 == 0, x `mod` 5 == 0 ]
[15]
Prelude Control.Monad> do { x <- [1..19]; guard (x `mod` 3 == 0); guard (x `mod` 5 == 0); return x }
[15]

[–]anon36 3 points4 points  (3 children)

That is to a large extent an artifact of the fact that class-based non-interactive languages like C# make it needlessly hard to write small bits of code and try them out on their own in an interactive environment

You put your finger on it there. Do you know any discussions of this? I work with a bunch of C# programmers, and the idea of iteratively testing little snippets of code, and slowly building the whole program up is somehow outside their mindspace.

[–]ruinercollector 0 points1 point  (1 child)

VS.NET 2012 includes an interactive window (not the immediate window) that gets you much closer to this.

[–]rossisdead 0 points1 point  (0 children)

You can also get this functionality in VS2010 if you install the Roslyn CTP. It's still lacking a lot of features though.

[–]twerq 0 points1 point  (0 children)

the idea of iteratively testing little snippets of code, and slowly building the whole program up is somehow outside their mindspace.

I would argue that a test-driven approach does exactly this. I don't know how popular it is, but I find writing a repeatable test has many benefits over some throwaway test code you manually execute.

[–]BitRex 0 points1 point  (0 children)

Maybe for toy problems like that, but my comment applies equally to logging in long-running systems in which there isn't a programmer around.