Yes, it's resharper that is used.
miner49er
@miner49er
Best posts made by miner49er
Latest posts made by miner49er
-
RE: Simple question: Should I be bothered by...
Thanks for the replies guys. A nice balanced mix of opinion - that's all I can ask for :-)
-
RE: Simple question: Should I be bothered by...
"the time spent on these posts might have been better spent on useful code, so let's not get lost in useless details."
I thought the point of this forum/site was to debate, amongst other things, good/bad coding-practise?
-
Simple question: Should I be bothered by...
...this C# code:
var showComment = false;
It annoys me. Especially as it's code that I have produced that gets changed.
Please can someone give me a reason why this is good practise? I don't think anyone can but if you can that would be helpful as I shall bring this (and other) cases up in my appraisal.
My thoughts are 'var' should only be used where neccesary OR when Class-names are really long and it aids readabilit eg.
ReallyLongClassName reallyLongClassName = new ReallyLongClassName();
would become:
var reallyLongClassName = new ReallyLongClassName()
...and even then, it's pushing it.
-
RE: Opinions required on 'code tidying'
@dogbrags said:
What's wrong here is not the actual code, but what you're doing. The intention is to mark "information" as either complete or incomplete. So why don't you say that. What you get is separation of concerns (what, vs how). A single method call that clearly indicates what the intention is (tell the user that their profile is complete, or not); and a method that encapsulates all the presentation logic (how you tell the user that their profile is complete), making it easier to modify the code if/when the presentation requirements change.
I fully agree. To be fair though, I used these snippets merely as an example of the kind of refactoring that goes on. In actual fact, I quickly refactored that code into my version and presented it to my boss asking him directly which was neater/easier-to-read. You know his response and I think this is the real problem: Egos. Nobody likes being told that what they have done isn't very good or could be done better.
I don't mind being informed of an alternative and superior approach to a problem - in fact I'm glad if it actually improves the situation, for a start it could stop me looking like an idiot later but mainly because it improves my knowledge and makes me a better coder.
But some people take all criticism personally and THIS is what we need to avoid in our line of work.Take ideas on-board, discuss alternatives with colleagues and above al: Dont Be Stubborn.
-
RE: Opinions required on 'code tidying'
@Zecc said:
While I was indeed joking, the truth is it isn't that bad as it is written.
Without knowing the surrounding code, we can't suggest a better variable name, except maybe "info".
Interesting. So you do not see a problem with having an object named exactly the same as the class it's created from?
I suppose it's just a different style, it's just a style I do not like.
I know a lot of coding styles have fallen by the wayside due to IDE technology advancing the way it has done, hungarian notion for example and this example is the same I suppose. A quick look at the colour of the text in the IDE will tell you it's not a Class but an object (see what I did there?)...I still think it's a poor way of naming objects.
-
RE: Opinions required on 'code tidying'
@Zecc said:
@miner49er said:
Information Information = new Information(); //WTF!
Why is this wrong? I need more information..Just in case you're not joking then I will answer. The compiler won't complain as it's syntactly correct, it simply looks wrong IMHO. The standard way of doing it AFAIK is to simply name the object the same as the class but remove the initial captilisation.
-
RE: Opinions required on 'code tidying'
@pbean said:
What I would like to know, though, is why the hell your boss is fiddling with your code, and thinks he has enough time to correct style issues within the code. Does he think you're not good enough to write code? Is he the one who has to maintain it later, so he just rewrites to suit his style? And if he never has to maintain it, then why does he interfere with it?
When I started about a year ago, there were no coding standards of any kind and the codebase was a lot worse than it is now. There were NO comments in the code AT ALL. All class member variables were capitilised and had a preceding underscore. There was no change control system in place, there was source-control but there was no change-request/bug-tracking system, so tracking why a source-file had been edited was next to impossible.
So, I came along and suggested we implemented a coding-standard, bug-tracking etc. Some people just don't like being told what they do is sub-optimal (understandable but not good in an engineering discipline). Eventually we now have bug-tracking but still no coding standards - well, the coding standards my boss decided to implement (due to "everyone ignoring coding-standards") was to use an automated tool to re-factor code. I believe this to be unnecesary, just write neat/readable code for god's sake! Plus I don't get a say in how the tool is configured, so we end up with crap like in my original post.
The funny thing is one of the coding-styles that I really didn't like was nameing local objects the same as the class-nam, so we would end up with crap like this:
Information Information = new Information(); //WTF!
When questioned, my boss said "there's nothing wrong with that", so I had to bite my lip and ignore it. Months later when the 'tool' was used, it's default configuration was to dissallow such a style...so he listened to a dumb tool but not to me! Perhaps you can imagine that might just annoy me...just a little bit.
So, to answer the question: he fiddles with the code because he runs that damn automatic tool blindly in an effort to employ a coding-standard!
Eventually, I'll move on...
-
RE: Opinions required on 'code tidying'
@too_many_usernames said:
This is actually a very good example of two functionally equivalent ways to do things with emphasis on different aspects of the problem.
In the code from your boss, the emphasis is on the control property rather than the condition. That is, for each of the properties you might want to do something (which in both cases depends on the user.CompleteRecord flag).
Your code, however, places emphasis on "do something if user.CompleteRecord is true, and do something else is user.CompleteRecord is false".
These are both valid ways to look at a problem, and I don't think there's actually a programming style that is easily flexible between the two different viewpoints. I think at the end of the day you just have to be aware of the differences in emphasis.
You might consider which is more likely to occur in the future: additional control properties (in which case emphasis on the properties makes sense) or if you're going to add more action conditions (in which case emphasis on the conditions make sense).
If you have a case where both the conditions and properties change, then I'd suggest picking one that is the most comfortable to all the maintainers.
Very good answer, thank you.
-
RE: Opinions required on 'code tidying'
@Rick said:
They both seem readable to me. If your manager actually asked you to change your style to his, then you have a perfect right to be annoyed. But if you want your manager to switch to your style, then you are definitely making a mountain out of a molehill. (Has anyone actually seen a molehill? Pictures anyone?)
He goes through my code and 'tidies' it up, this is just one example (I think he uses an automated tool to do changes like this). I understand that he is the boss and ultimatly it's up to him how the code looks - I don't have to agree with it though. Or be happy about it.