Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
What are the ways to identify Syntactic Sugar? For example, if someone is unaware of the version 1.0 of C# and gets involved in learning version 4.0, how should he/she go about detecting Syntactic Sugar? Is looking into the disassembled code the only way?
OR
Should a guy learning C# 4.0 go all the way down to 1.0, peeling one layer of abstraction after the other, to see the inner details?
An example:
When dealing with Events in C#, the following comes to my mind (courtesy Hans Passant)
the += operator calls add(), -= calls remove()
P.S.
The questions I ask may be just too hilarious for the extremely knowledgeable crowd here. But making sense of the ever evolving software world is no "walk in the park". It is like finding your way out of the Amazon (I mean the Brazilian jungle. The website is easy to navigate.).
Everything atop electric current is syntactic sugar for us humans. The computer doesn't need that nor does the alphabet or words as we know them mean anything to him.
Your job as a programmer is to use whatever feature makes you job easier. There is no bad feature if it makes you faster or better. Preferably both.
You'll easily detect sugar going backwards from .NET 4.0 and noticing that simple "sugared" language structures from higher versions are getting more and more complicated.
Sugar is nothing bad, just need to know that there are many ways to accomplish certain task.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I bet this question has been asked before, but I can't really find out what i'm looking for, so excuse me in advance :)
is there a difference (programmatically speaking OR overhead speaking) between this:
var data = GetProducts();
GetAllData(data);
and this:
GetAllData(GetProducts());
what are the pros and cons of both methods if any? is there a more elegant/right way of achieving it (say Func<>)?
thanks in advance,
Rotem
Doing it in two lines makes it easier to debug, because you can break on the second line and observe the value assigned on the first line.
The compiler will optimize them both into the same CIL anyway, so it's not a matter of efficiency. It's all a matter of preference.
There is no functional difference and when the code is translated into machine language (or JVM byte code or whatever), it will result in more or less the same low level code.
The main difference is a matter of (a) aesthetics and (b) maintainability of the code. With respect to aesthetics, some may argue that the second form is prettier. It's largely personal choice but I would argue that if the expression wasn't as simple as GetProducts() but was very long (e.g. GetContext().GetProductService().GetProductsFor(GetContext().GetCurrentUser()) then breaking it up into two lines with an intermediate variable is more readable.
With respect to maintainability, I think you will find that having fewer variables is always better for future maintenance. You are less likely to encounter bugs relating to side effects or changing assumptions. In other languages you can use constructs like const or final to use the compiler to help protect against code rot, but I would still argue that it's cleaner to have fewer lines of code.
Hope this helps!
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I was just wondering where there any downsides to using in method argument from c# 7.2
I know this is recommended for dealing with Structs and they say it won't increase performance that much but from what I can tell this won't have any negative impact on the code and might help you with stack overflow exceptions when doing recursions.
Dose anyone know of a good reason why all methods should not be marked as in?
I found why people recommend to avoid ref and out but they don't work here.
As this is a performance related question, as a matter of discussion in was introduced for that reason, it's hard to find single, correct answer, without really measuring performance on concrete code sample.
But...
We know that in creates a reference which is 32bit on x86 OS, and 64bit on x64 OS.
Now consider a structure like
struct Token
{
char x;
}
on x64 OS, copy this structure on the stack, likely, will execute faster, than creating 64bit reference to the same data.
Plus, do not forget, that in implies "constantness" on an instance, which goes beyond performance reasoning, and targets directly your design. Hence, while from performance related matters, some of reasoning might be arguable, from design point of view, in has distinct and clear semantics to target specific design use cases.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm planning on gaining some insights into inheritance usage for .NET systems written in C#. I want to analyse Intermediate Language code instead of C# code to make it possible to also look at compiled code. Is there any information available on which optimizations the C# compiler may do when the optimize code flag is enabled?
I'm analysing call behavior related to inheritance graphs (e.g. using polymorphism, reuse methods from base class, etc).
Most questions and resources on the internet say 'minor optimizations' and other vague things. I need to specifically know the changes in semantics that might occur when compiling for release mode. I am not interested in the performance of code.
For example, Scott Hanselman posts in his blog that method inlining will occur in release mode. But that is just one example. This means that What is /optimize C# compiler key intended for? does not answer my question.
http://blogs.msdn.com/b/ericlippert/archive/2009/06/11/what-does-the-optimize-switch-do.aspx
Eric Lippert (a former principal developer on the C# compiler team) answered this on his blog. A few of the remarks:
Eliminate dead code (branches which are never reached, checks that always return true,...)
nullcheck optimization.
removal of intermittent calls (A(B(C(D))) is rewritten as A(D));
double return calls.
The entire blog has many more examples and I urge you to read it if you want to know about this.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I asked about this Q format on meta, and the they said that worded correctly, this should be appropriate. This being said, sorry if I still butchered the wording and just in case I'd like to get this across (as was recommended): I'm not looking for opinions on certain things or how they work, rather just the ways it's possible. I don't mean to sound ignorant and I'm truly sorry if I do, it was just suggested to me to say on Meta.
Now for the Q; What just general language at all would be capable of gathering information from public online websites, then putting it in the program where it could be further processed as just any old variable? I'm new to coding and wanted to do this as a little 'introductory' program, to teach myself some new stuff. Problem being, with my idea, I don't even know where to start. Again, I'm not asking for specific ways to do this, I was just curious what languages are capable of doing this at all? I'd prefer to do it in a Visual Studio's language (no preference of which ones), if that's possible.
In short: Are either Visual C#/C++ capable of gathering information online to be further handled within the program? If not, what languages are?
I agree with the comment that this is a complicated first programming task. However, you'll undoubtedly learn something trying it.
If you already had some experience programming in Python, I'd suggest you took a look at http://scrapy.org/doc/ which is a framework (that is, a bunch of classes and other useful tools) which let you write programs to extract information from web pages. Scrapy does let you concentrate on programming by taking care of some of the nasty details involved in parsing web pages.
Another option is to use a javascript framework, maybe something like node.js.
I've done a fair amount of web scraping, and I usually end up using a combination of utilities which clean up web pages and a variety of XSLT processors. I personally find that combination of technology to be easier to deal with; I don't try to use C-family languages until I've basically wrestled the data into shape. But everyone has their own style.
Good luck!
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Do you know any C# based "puzzles and answers" like book? Article? Resource?
Why I am asking this is to enlarge my vision with some interesting quiz-like scenarios; to force myself think in a different way and which I can maybe have an advantage on unexpected interview questions.
Thanks!
stackoverflow.com, of course :) - just reading the q and a on this site makes me think a different way.
Learning C# with exercises, questions and puzzles
Although it's not specific to C#, Project Euler is a lot of fun.
you can find a lot of solutions in c# to project Euler challenges. This is one resource: http://archive.msdn.microsoft.com/projecteuler
Also the benchmarks on The Computer Language
Benchmarks Game have solutions in c# (mono). They encourage people to contribute faster solutions and by looking at them you can learn good performance-tuning tips.
Finally, if you're coming from another programming language and want to compare ways of solving common tasks, sites like Rosetta Code or langref are precious. They are also good to just learn how to do common things in a new language or as a reference (or indeed as preparation to common interview questions)
A StackExchange site: Programming Puzzles & Code Golf