Is it good practice to use LINQ often? [closed] - linq

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
LINQ is extremely powerful and can be used highly in code. But is it best practice to use it?

It's a good idea to use it when it makes the code clearer and simpler to maintain, and when you're not in any of the situations where the performance of LINQ is too slow for your needs.
You haven't specified whether you're talking about LINQ to Objects or LINQ to SQL etc, but I know there are situations where the latter has proved too slow for some high traffic sites, and they've moved off it... but only after it's been shown to be an issue. LINQ to Objects will often have a very small performance hit compared with "hard-coding" the same logic, but that's even less likely to be a real problem.
Of course LINQ can certainly be overused, and I've seen people reaching for a LINQ solution when there are far more appropriate ways of achieving the same thing - so don't try to use it everywhere you possibly can. Just use it where it clearly helps.

the declarative nature of linq is one of its strongest features. Almost always this makes your code more readable and maintainable, so yes, unless there is a compelling performance reason not to, I'd say that it is best practice.

Related

I've been programing for six year and my homework in University gets marked down for coding style [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I've been programming for the last 6 years. I just recently started my first degree in computer science. My work seems to be constantly marked down for different reasons, amongst many of them:
Uncommented code
Writing too long identifier names and methods
Writing too many methods
After working as a programmer for six years for numerous startup companies, and absorbing best practices which include the requirement to write "self explanatory code" I find it very difficult to go back to bad practices.
What can I do?
Self documented code is not synonymous with comments.
I've argued with many senior devs around this point. Code can go a long way in communicating intent but there are some things which simply cannot (and should not) be documented through code.
For example if you have a highly optimised function/method or chunk of code which is heavily coupled to the underlying problem domain and requires very specific knowledge of the business or solution. Comments are needed in these scenarios.
Yes, yes, comments come with there fair share of problems but this doesn't mean they aren't helpful (or mandatory in certain cases).
I can't tell you how many times I've read a colleagues line of code and thought "what the hell?!?" only for them to explain that they needed to do that due to some quirk of some library or browser we were targeting etc.
Comments are a mechanism for a developer to justify a design decision.
As for your other problems, they are subjective. How long is too long? How many is too many?
Point them at Microsoft's guidelines if you are on the MS stack or there will be countless articles for whichever language you're using...
Hope that helps.

Is this defensive programming? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I've always thought defensive programming was evil (and I still do), because typically defensive programming in my experience has always involved some sort of unreasonable sacrifices based on unpredictable outcomes. For example, I've seen a lot of people try to code defensively against their own co-workers. They'll do things "just in case" the code changes in some way later on. They end up sacrificing performance in some way, or they'll resort to some silver bullet for all circumstances.
This specific coding practice, does it count as defensive programming? If not, what would this practice be called?
Wikipedia defines defensive programming as a guard for unpredictable usage of the software, but does not indicate defensive programming strategies for code integrity against other programmers, so I'm not sure if it applies, nor what this is called.
Basically I want to be able to argue with the people that do this and tell them what they are doing is wrong, in a professional way. I want to be able to objectively argue against this because it does more harm than good.
"Overengineering" is wrong.
"Defensive Programming" is Good.
It takes wisdom, experience ... and maybe a standing policy of frequent code reviews ... to tell the difference.
It all depends on the specifics. If you're developing software for other programmers to reuse, it makes sense to do at least a little defensive programming. For instance, you can document requirements about input all you want, but sometimes you need to test that the input actually conforms to the requirements to avoid disastrous behavior (e.g., destroying a data base). This usually involves a (trivial) performance hit.
On the other hand, defensiveness can be way overdone. Perhaps that is what's informing your view. A specific example or two would help distinguish what's going on.

Prerequisites for understanding algorithms? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
What areas of math are prerequisite for learning algorithms?
I guess it depends a lot about the kind of algorithm you want to use and how deeply you want to understand them.
The understand of the usual basic data structures needs almost no math background.
Most of the graphical algorithms requires knowledge of trigonometry and spatial geometry.
Algorithms about physics engine are easier to understand if you have some physics basis
If you want your program to help you to take decisions, you might need to study operational research which is a really huge sub-fields of math which includes graph theory, game theory, optimisation (which then includes analysis and linera albegra)
In any case, having a logic/mathematical mind obviously helps a lot for the understanding and to check/prove that your code can/cannot work.
If you're talking about simple programming you don't really need a lot of math. At this level, your problem solving and logic abilities are more important, but it's necessary that you get instructed in the basics of problem solving by using flow charts and process planing.
In the other side, math is known to improve your abilities and in some areas you would need to know math to achieve the expected results. For example, to create an animation engine knowing linear algebra is more than useful, so its physics.

LINQ practice exercises or puzzles? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I'm still trying to learn LINQ, though it's going more smoothly now that I've started to use it daily at work. I still don't feel good at it, though. Does anyone have any challenging practice exercises or puzzles I can use as a code-kata to improve my skills?
I'll leave this as community wiki, so maybe it can grow to a community list.
If you have not discovered http://www.linqpad.net/ it lets you practice linq in a lightweight way, as well as having some inbuilt examples from C# 5.0 in a nutshell and C# in Depth books.
101 Linq Samples is a good one for reference. Not a puzzle though
I know the 1st 2 questions at Project Euler is 'LINQ' friendly, I never did any more, but it should be fun either way :)
Puzzle:
Do a full outer join in LINQ.
I've been finding "foreach's" in existing code and attempting to linq'ify them. Many times things have been different enough for me to learn new concepts or at least if they're similar I get to feel more confident that my Linq skills are getting better.

Is business logic subjective? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have a team lead who seems to think that business logic is very subjective, to the point that if my stored procedure has a WHERE ID = #ID — he would call this “business logic”
What approach should I take to define “business logic” in a very objective way without offending my team lead?
I really think you just need to agree on a clear definition of what you mean when you say "business logic". If you need to be "politically sensitive", you could even craft the definition around your team lead's understanding, then come up with another term ("domain rules"?) that defines what you want to talk about.
Words and terms are relatively subjective -- of course, once you leave that company you will need to 're-learn' industry standards, so it's always better to stick with them if you can, but the main goal is to communicate clearly and get work done.
One way to differentiate is that "business logic" is something the customer would care about and that could be explained to a customer without referring to computer-specific words.
You could try to argue your point with a timed example, run a sql select against an indexed table and then run a loop to find exactly the same item in the same set but this time in code. The code will be much slower.
Let the database do what it was designed to do, select sets and subsets of data :) I think realistically though, all you can do is get your team together to build a set of standards which you will all code to, democracy rules!

Resources