SolutionYogi

New York, United States

solutionyogi.com

Age: 33

I am a developer, not a programmer. More on my website.

2d
awarded Supporter
2d
awarded Autobiographer
Mar
20
comment Too many 'if' statements?
@EricLippert I like JAB's solution too. IMHO, enum type in C# leaves much to be desired. It doesn't follow the pit of success philosophy which rest of the features do. E.g. stackoverflow.com/a/847353/92414 Does c# team have any plan to create a new enum type (so as to avoid breaking existing code) which is designed better?
Mar
18
awarded Necromancer
Feb
28
comment jQuery and $ questions
@Bere Please refer to my answer 'Why function aliasing doesn't work'? stackoverflow.com/questions/1007340/… to understand why this approach is not working for you.
Feb
11
awarded Caucus
Feb
11
awarded Great Answer
Jan
30
comment Is there a difference between an intermediate variable and return'ing a function call directly?
Yes, contracts to enforce semantics would be amazing. E.g. I should be able to design a ASP.NET templating engine where I can enforce that all strings have been escaped properly before outputting it to browser. I know Scala allows you to implement something like that. Are there any other languages you know which are very powerful in their capabilities but not that mainstream?
Jan
30
comment Is there a difference between an intermediate variable and return'ing a function call directly?
Exactly. I haven't written a finalizer even once and I have been using C# for last 8 years. And I am a believer in refactoring and I have definitely refactored code to simplify an overly complicated expression and I never worried that it would change the semantics, relying on the fantastic type system provided by C# and CLR. On this note, I often wonder where can C# go from here. The only thing I can think of is built in immutability support in the language and runtime. You should write about some of the big theme ideas (like LINQ/ async/await) which you wish C# could have.
Jan
29
comment Is there a difference between an intermediate variable and return'ing a function call directly?
that's insane. Were you the one who did troubleshooting and found the bug? I would never even think that simplifying an expression can change the behavior. I must say, I have a lot of respect who has to use C++ as their main language everyday. It's like they are working in Afghanistan, trying to avoid minefields everywhere and here I am, sitting in NYC, doing the best work of my life using C#. Thank you and the whole developer tools division for making our lives so much better.
Jan
29
comment Is there a difference between an intermediate variable and return'ing a function call directly?
Wow. I never looked at it that way. I am guessing that this is immaterial for language like C# as it is memory managed, correct?
Jan
28
comment Why do dynamic languages make it more difficult to maintain large codebases?
@BenjaminGruenbaum I completely agree that the type system can only capture structure and not the behavior (for now). We disagree on how much value one can get by enforced structure. Also, I feel that static type system tools will be getting smarter and help us enforce behavior as well. E.g. look at Code Contracts and Pex. Please look at this: pexforfun.com Pex will not be possible without static type system.
Jan
28
comment Fastest way to search in a string collection
Not in million years I would have guessed that LINQ SUM method is slowing us down. Please listen to experts and do not even attempt to guess which part is slow. Profile the code, look at the hot spot, eliminate it. Keep repeating till you achieve desired performance. I have used both ANTS profiler and dotTrace profiler in production and I highly recommend dotTrace profiler for the 'subsystems' feature (youtube.com/watch?v=iEU_SU6oV1c). It makes it very easy to identify bottlenecks in your system.
Jan
28
comment Fastest way to search in a string collection
+100 for profiling. In my current product, we were doing millions of calculations over a list. It was not fast enough and we thought that we need to implement some sort of caching mechanism for our calculations. When we profiled the code, we found that the LINQ Sum method was a hot spot. Diving deeper, we learned that SUM method was getting called millions of times and was generating GC pressure to dispose off all the enumerators. We added ListSum method which indexed over the list using for loop and we saw 50% speed bump with reduced memory usage.
Jan
28
comment Why do dynamic languages make it more difficult to maintain large codebases?
I can not give you a direct C# equivalent for the code I linked, but if I expected all set of 'Meta' classes to have property called 'proto', I will design an interface called 'IMetaProvider' and let compiler ensure that every implementation provides definition for 'proto'.
Jan
28
comment Why do dynamic languages make it more difficult to maintain large codebases?
@BenjaminGruenbaum It depends on your definition of 'prohibitive defaults'. At the end of the day, purpose of any type system is to let you write set of rules/constraints to solve your business problem. You are suggesting that unit testing and tools like static analysis, CI should be used to enforce these rules. I am suggesting that one should use every available tool at their disposal (including static type system). I personally find that static type system provides me with more tools to design/enforce rules. Yes, I do give up some flexibility but the trade off is worth for me and my team.
Jan
28
comment Why do dynamic languages make it more difficult to maintain large codebases?
And you wanted an example, check this commit: github.com/emberjs/ember.js/commit/… The developer forgot to follow certain rule and had to go back and fix it. In statically typed language, you can enforce certain set of rules so that a developer never 'forgets'. Mind you, I am not trying to knock this developer. Developers are humans at the end and sometimes we will 'forget' to do certain things. But if you have huge set of rules and a decent sized team, it's simply better to have a compiler/static analyzer enforce those rules.
Jan
28
comment Why do dynamic languages make it more difficult to maintain large codebases?
Benjamin, if you are talking about a mature development team who uses IDE, static analysis tool and CI server, you can definitely workaround the limitations of a dynamically typed language. But in a world where there are teams who haven't moved to DVCS and CI server tools, having the language enforce the rules while you are writing code is tremendously useful. And jslint is useful, but it can NEVER be as powerful as a static analysis tool targeting a statically typed language simply because there is not enough type information to analyze.
Jan
27
comment C# - using Thread.Sleep() to get my cycle run several hundred times per second
+1 for BlockingCollection. Write code so that all the streaming APIs put data in a BlockingCollection. BlockingCollection will synchronize data input from multiple threads. Your computation code should use GetConsumingEnumerable to read work items from this BlockingCollection and produce relevant snapshot. Have a look at this: geekswithblogs.net/BlackRabbitCoder/archive/2011/03/03/…
Jan
24
comment Array.Sort with Custom IComparer Interface
Any particular reason you decided not to return result variable directly instead of checking it for 1/-1?
1 2 3 4 5