Tag Info

Hot answers tagged

42

The reason C# (and Java and essentially every other OO language developed after C++) did not copy C++'s model in this aspect is because the way C++ does it is a horrendous mess. You correctly identified the relevant points above: struct: value type, no inheritance. class: reference type, has inheritance. Inheritance and value types (or more specifically, ...


10

By analogy, C# is basically like a set of mechanic's tools where somebody has read that you should generally avoid pliers and adjustable wrenches, so it doesn't include adjustable wrenches at all, and the pliers are locked in a special drawer marked "unsafe", and can only be used with approval from a supervisor, after signing a disclaimer absolving your ...


6

This is from "C#: Why Do We Need Another Language?" - Gunnerson, Eric: Simplicity was an important design goal for C#. It's possible to go overboard on simplicity and language purity but purity for purity's sake is of little use to the professional programmer. We therefore tried to balance our desire to have a simple and concise language with ...


5

My problem is that the code that I have inherited is, in my opinion, absurdly over-engineered. I have enormous problems following the program flow and finding any concrete implementations of anything. The amount of abstractions are totally mind-boggling and there is no documentation whatsoever. Its not you, I find that a lot of C# and Java (and ...


4

The best code standard is the one that looks exactly like the code you currently have. And the first rule of coding standards is 'new code must follow the convention used in any existing code file; (ie don't mess up existing styles, so if a document has curly brackets at the end of lines, write new code that also has curly brackets at the end of line, ...


4

As a relative new trainee in my company, I've been asked to write a code convention since the project is 6 years old and nothing have been done. I think that this should have been done at least 6 years ago by some senior developer (maybe choosing something which already exists (thus being a known standard, which better suits the needs of the team), ...


4

You'll find with existing C# collections, attempting to mutate the collection while iterating causes exceptions. It would be idiomatic to throw an exception in that scenario in your collection. The problem that you'll face is that this doesn't matter if you're iterating. If someone changes person.Name, your RBT is already out of order - iteration or no.


4

Try keeping your unit test atomic. Remember that automated testing code is also part of your code base, but is itself not under test, so keep it as simple and obvious as possible. To answer your question more directly, there is no guarantee of the order of executing of the tests so there is also no way to guarantee that your utility test succeeds before ...


3

Rather than thinking of value types deriving from Object, it would be more helpful to think of storage-location types existing in an entirely separate universe from class instance types, but for every value type to have a corresponding heap-object type. A storage location of structure type simply holds a concatenation of the type's public and private ...


2

It depends, is the state you're locking private or protected? If it's protected, I recommend you reconsider. Once you've reconsidered, make the lock object as public as the most public shared state. If you trust derived types to use the state properly, then you should trust them to handle the locking properly. If you don't provide the lock, they'll be ...


2

Yes, encapsulation and immutability are good, but it's important to understand why, because you're sort of hitting just the wrong spot as Erik Meijer describes in his paper subtitled "Mostly functional" programming does not work. Encapsulation is good when it works to decouple an interface from its implementation. It stops being good when you look at it to ...


1

It actually depends. I would only create a Class which contains instance attributes if more than one of its methods uses it. On the other hand, if an attribute (or variable) is only used inside the method, then it should be defined local to the method it uses. In the example you describe, I think that you are using functions instead of methods, which to me ...


1

I'm not a huge fan of strict, written code conventions, but they actually can avoid a lot of fussing and fighting in a team. Off the top of my head, a few other things that may be important : Formatting Indentation Line break rules Max acceptable lines per file Regions Project-level Namespaces / subfolders Project naming Tests Test class naming ...


1

The simple truth rarely acknowledged is that if a class contains a compiler-visible dependency on another class, it cannot be tested in isolation from that class. You can fake up something that looks like a test, and will appear on a report as if it was a test. But it will not have the key defining properties of a test; failing when things are wrong, ...



Only top voted, non community-wiki answers of a minimum length are eligible