This is by no means an attack on you guys for less then good coding, but I have noticed alot of conventions being broken in much of the codes on codeshare and the wiki.
I see alot of
String someString = "";
where this should be
string someString = string.Empty;
Well there are 2 misuses here.
String with big S yes, the is a complex type representing a string with small s, which will wrap the string in a String thus consuming more ram and take up more cpu cycles to create.
By using “” you create a new string instance pointing to its own string representation of “” (empty string), where by using string.Empty your string will point to the same representation of an empty string which will take up much less memory allocation.
The other thing I have noticed is many uses of complex types such as Int16 or Int32 or the like, An Int16 IS an short so use a short not an Int16 because the same problem as with the string (part 1) applies here.
I would always recomment the use of Resharper which will help in this regard aswell as StyleCop (which is compatible with resharper), these tools helps out with naming conventions and less then good code.
I know many uses _ for class or instance variables, where as this is well seen in C++ IT IS NOT good code in C#, read the code conventions for Camel Casing Camel case - Wikipedia.
I urge you guys to please adhere to those conventions as this will make it a 100 times easier for other developers to continue the work.
My best wishes.
Once again this is not ment to attack anyone, I only wish to drag this out in the light and make us ALL better coders
Please lets talk about this and tell us what you think and why you think this.
Pop in the TinyCLR community IRC channel and ask/chat
Keep in mind that many users here have an embedded system background in C programming where short and INT16 meant exactly the same thing (#define INT16 short) so the feedback is helpful to aid others in know what is better and why.
I am well aware of this, but that is exactly why this is needed, because C# is most certainly not C or C++, because the simple types are named the same in both c/c++ and c# the complex types in C# is always a sort of wrapping on the simple type, so therefor it is very much nessecary to know where the differences are, and comply with them.
That is one of the reasons why I started this post.
PS: Gus could you move this post to General Discussions, as I just realized it is in the wrong category.
We had a really big discussion on this subject and my university teacher, explained this in debths, I dont remember the exact tale, but you can actually see differences by timing the creation of a short and the creation of a Int16 (well you wont ever notice it).
C# will wrap short in an Int16 object when created as an Int16 but ofcourse C# is cleaver enough to know that a Int16 can be casted directly to a short.
I’ve been using c# for as long as it has existed, and before that it was C++ and Java, so have a fairly good knowledge with programming and C# especially.
Well Okay, I did go and read about it and it seems I am misinformed in this regard, but never the less, I am correct in my oppinion about people need to know more about the differences between the languages (Including me).
Conventions are there for a reason.
I just wanted to make people away that there are conventions, and differences that should be keept.
Ohh but I have codes in the code share, and yes I understand that I could have provided some source code for showing what I was refering to, but I provided a link to the conventions Microsoft is recommending.
I always try my very best to code adhere to the conventions given for the language in question.
An example could be
var someInt = 10;
C# (Same code snippet)
var someInt = 10;
Yes it is the almost exact same code except for the casing.
Code not withstanding I believe he was more specifically referencing your statement
"I urge you guys to please adhere to those conventions as this will make it a 100 times easier for other developers to continue the work."
Either way, conventions are [em]good[/em] but shouldn’t been seen as the end all be all of coding. I personally don’t think many hobbyists are going to get confused seeing Int16 instead of short, nor care too much if it costs them an extra 3 cycles in their code.
Remember this is a learning community, not a corporation looking to squeeze every last cycle for a mission critical software.
I explicitly used the word “urge” to say you should use the conventions, however its still up to you to do so, but the Idear here was not to go into religion, just to drag the “missing conventions” into the light.
This was never about confusion it has always been about trying to highten everybody’s codeing abilities and quality even my own.
“I pledge to always abide by the given code conventions to the best of my abilities.”
As Tom said, this is a learning community. Rather than starting a rant on the use of conventions, a better approach would
be to post a series of good coding practice posting so everyone could learn from your experience. You gave some good
Learning by example seems to be the favorite approach here.