How are attached properties useful in LINQ? - linq

I got this question during an interview in the past and never really dug into in, but I've put some thought into it lately and I can't come up with a good answer. When I think of attached properties my mind goes straight to UI related concepts - what benefits could be had in using attached properties with LINQ? I'm starting to think the answer is "they're not" unless I find out otherwise!

Linq and attached properties are not related. I think this question is asked to confuse you.

Related

Processing Movie background change

I had another question about processing and a project i'm making. I would like to play a movie in a loop on the background. I managed to do this by initializing a Movie and putting it in an image the size of my app. But now I would like to load in multiple movies and add a button to change the background when pressed with the leap motion. Is this possible ? Or should I use a different library for this ?
Thanks in advance!
Kind regards,
DarthSwedo
It's really hard to answer general "how do I do this" type questions. Stack Overflow is designed more for specific "I tried X, expected Y, but got Z instead" type questions. You'll have much better luck if you just try something and post an MCVE if you get stuck.
That being said, I'm going to try to clear up some of the general confusion you seem to have.
Step 1: You need to figure out what library or libraries you're using. In all of your questions, you seem to not be sure which library you're using. Which Leap Motion library are you using? How did you set it up? Where is its documentation? You say you're using a Movie class. Where is that coming from? Are you sure it's not from the Video library?
If you have more specific questions in the future, please provide this information. We can't really help you without it. But more importantly, you need to know the answers to these questions if any of this is ever going to make any sense.
Step 2: Read the documentation for those libraries. Processing comes with the reference. The Video library comes with its own documentation page. I'm sure whatever Leap Motion library you're using has something similar. You need to read about the functions available to you. That's a huge part of programming. Right now your question is just asking whether something possible, and the honest answer to that is, well, what happened when you googled it?
Step 3: Try something. After you read through the documentation, just try something. Write some code based on the examples in the documentation. Even if that code doesn't work, that's okay, because then you can use it as an MCVE and ask a more specific question.
Good luck.

What are examples of comments that tell you WHY instead of HOW or WHAT?

First of all, in this question I'd like to stay away from the polemic on whether source code commenting is good or bad. I'm just trying to understand more clearly what people mean when they talk about comments that tell you WHY, WHAT or HOW.
We often see guidelines like "Comments should tell you WHY; code itself should tell you HOW". It is easy to agree with the statement on an abstract level. However, people usually drop this like a dogma, and leave the room without further explanation. I've seen this used in so many different places and contexts, that it looks like people can agree on the catchphrase, but they seem to be talking about different things entirely.
So, back to the question: if comments should tell you WHY, what is this WHY we are talking about? Is this the reason why that piece of code exists in the first place? Is this what that piece code should be doing? I would really appreciate if someone could give a clear explanation, and then add some good examples (bad examples are not really needed, but fell free to add them for contrast).
Please do not immediately close this question as duplicate or polemic. I have tried hard to make it very objective. There are many questions on whether comments are good or bad, but no one that addresses the specific question of what are good examples of comments that tell you WHY.
Thanks,
Comments serve two main purposes:
to summarise. Many would say "why document this method when we can just read the code?", but one line of text that describes what a method is for/what it does, can often be much faster to read and easier to understand than 30 lines of code, especially if that code calls other methods that you may need to read as well...
to explain the things that are not obvious from the code - the WHY, or more detail on the how. Simple examples include "we must add the new XmlElement and then remove the old one, as the ReplaceChild method in .net does not work!", or "Uses an iterative Newton-Raphson approach to solve for X ", or "we must not close the port here because the reading thread may still be running", or "use this method where performance is critical, but beware that this method may provide a result that is in error by up to 5%"

How Polymorphic Association with TPC Inheritance Mapping is Treated in Professional Projects?

While designing & developing a data-centered project using Entity Framework, I have spent too much time to find a way to accomplish one of the following but have come across nothing practical.
To find an alternative to implement "Polymorphic Association" which cannot be implemented along with "TPC Inheritance Mapping" in EF - since this kind of inheritance mapping fits well with the logical design of my model, or
To find a way to improve the poor performance of "TPT Inheritance mapping" which seems to me is the only practical alternative to TPC.
"TPH Inheritance Mapping", in my opinion, does not make sense from the "database design" and "data validation" point of view.
Besides, since other parts of the project rely almost totally on Microsoft products, I do not tend to switch to other ORM frameworks such as NHibernate.
Now I would like to ask those of you who are professional software developers and have possibly faced this problem, to please advise me about any other available options/solutions. How is this issue usually solved in professional design/development tasks?
Appreciate any guidance in advance
Just playing around I seem to be able to achieve all manner of polymorphic associations. One thing I found helped is to make sure all your foreign keys and relationships are explicitly defined, this will avoid any ambiguity that Code First may encounter. Julie Lerman in her book Code First does mention that foreign keys should be defined otherwise unexpected things with the association mappings may occur.
Hope that helps, if not let us have some code and say what you can't get to work.
Cheers

When are comments "too much", and when are they not enough? [closed]

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
There is an on-going minor debate where I work about the efficacy of comments within code. One of the leads instructed his developers not to use comments as they are too "old fashioned", and a couple of other developers indicated that they never use comments because they feel all they do is clutter up the code.
I have always pretty much adhered to the practice that I comment the top of every file with a basic comment block, comment each method/class/etc definition, and then I comment any place in the code where I think I might come back in 6 months and think to myself, "WTF".
Clearly this is subjective, but I'm curious to know if anyone has any really good arguments or experiences for one way or the other.
I'll just point you to Jeff Atwood's wonderful post on the subject, which hits the nail right on the head.
In all my career, I have never come across that wonderful beast "self-documenting code". Maybe I've just been unlucky, but I'm beginning to suspect it doesn't actually exist.
Every once in a while I run across code that is so elegantly partitioned, has such compellingly obvious method, field and variable names that everything I need to know is obvious from the code.
In the general case, only really great code gurus write such code. The rest of us cobble together something that works.
If you're a really great code guru, don't bother sullying your divine code with superfluous comments.
If you barely know what you're doing, be careful to document your blundering attempts so others can try to salvage the mess.
If you're average (and most of us are, sort of by definition) then leave some hints in comments for yourself and others to make things easier at maintenance time, but don't insult anyone's intelligence and waste space by documenting the REALLY obvious. Ideally, your comments should describe your code at a meta-level, indicating not what you're doing but why. Also how, if you're doing something unusual or tricky.
"One of the leads instructed his developers not to use comments as they are too "old fashioned", and a couple of other developers indicated that they never use comments because they feel all they do is clutter up the code."
If I ever heard a developer I was working with talk like this, I would correct them. If I didn't have the necessary rank to correct them, I would leave the job.
Very clearly written code, with good identifiers -- the stuff sometimes referred to as 'self-documenting' -- does a fine job of illustrating what the code is doing. That's fine as far as it goes. The job of the comments is to explain why.
This topic tends to be discussed a lot, but here are my US$0.02 on the subject:
I would rather see too many comments than not enough. Failing at anything, you can always delete superfluous comments from the code; however, you can not derive meaning from them if there are none there to begin with.
I've heard some developers argue that other developers that "over document" (definitions of this vary by person) their code are not good developers. While saying that you are updating a counter might be a sign that you don't know what you are doing, having a clear guide to some of the business logic sitting there in the middle of the method you are working on can be quite useful.
While there are some excellent developers out there that can write extremely clear code that doesn't require comments, most developers aren't that good or they spend more time writing the code to be self documenting than they would if they had just included a couple comments.
You don't know the skill level of the next person to read your code and if the language constructs you are using might be confusing it is usually a good idea to include a comment that someone can use to Google a tutorial with.
The problem with comments is that they tend to stay long after the code that was commented has changed or even been deleted.
As a rule of thumb I'd only comment public API and difficult to understand algorithms.
Don't use comments to explain what you did - that's what the code is for, use comments to explain why you did it.
Diomidis Spinellis just wrote a nice column for IEEE column (quoted on his blog), outlining the problem, and a few solutions:
When commenting, we’re always a couple
of keystrokes away from disaster:
restating the code’s function in
English. And that’s when problems
start.
One should write comment before the code or before the function so that next time looking at the function he/she can know immediately what was the purpose of that code.
It is happened to me many times that I write the code and then forgot the purpose of that. so, I make habit of writing comment before code.
What I'd like to see in the comments is an explanation why a method that is obvious and much simpler than the method used in the code doesn't work.

Custom LINQ implementations

There are many LINQ implementations such as LINQ-to-Flickr. To make something like this, do I make my own custom LINQ provider?
Thanks
Have a look at this tutorial
Aha. That's the only way.
Hit in google 'write LINQ provider'. There are many tutorials out there.
Start with understanding what exactly Expression is, how it differs from lambdas and how to work with them.
I find this book quite helpful too (at least - beginning).
Yes, to get started, the best place is looking at the IQToolkit on Codeplex. You'll learn a lot about how it works.
If you do find you need to build your own then look at IQToolKit and the The Wayward Weblog for a full series on how to do it.

Resources