How to name namespaces with composed names? [closed] - c#

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 8 years ago.
Improve this question
Let's say I own a domain called www.john-doe.com. How would I write an appropriate namespace in C#?
Is it Com.John_Doe.<product-name> ?
All I read about C# namespace convetions is that it should use PascalCase. But what about the minus sign? Is it appropriate to write an underscore for it?

According to .NET namespace conventions, you should use pascal casing in namespaces (unless that goes against non-standard casing your company/brand/product uses). And according to capitalization conventions, pascal casing should not include underscores. General naming conventions also tell you to not use hyphen (which will actually produce compiler errors in C# anyway).
Unless Com is intended to be replaced with your company name (from the context, "John Doe" sounds like the company) You should just go with:
JohnDoe.<ProductName>

I think it is personal preference. E.g. my preference is JohnDoe.

Related

Why are C#'s format specifiers strings? [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 2 years ago.
Improve this question
Why are format specifiers to base types in C# of type string instead of a less error-prone and more readable type, like enum? While I know many of the specifiers by now, I almost always have to double-check the documentation to avoid bugs or weird edge-cases. enum types and values could've easily provided that information in their comments.
C#'s version 1.0 was released in 2002, and object.ToString() has been a feature since C# 1.1. It is an old feature and I understand that the development process and goals doesn't necessarily look the same now as then. However, I cannot understand the reason for not using a type-safe, well-defined and easy-to-document behavior by using language features such as enums or classes instead of strings.
Of course, most older langauges such as C use string type format specifiers, so perhaps it's just by convention? If so, why do they feel the need to follow that convention? (and besides, C use the % character for specifiers, so C# already made up their own conventions)
It's because they expect the format will vary a lot in different cultures, countries, systems, users (some systems allow users to choose their own prefer format). And we will end up a very big enum for all possibilities. And also, .net framework can't just maintain a huge amount of formats.

c# namespace naming conventions [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 6 years ago.
Improve this question
Another developer at my company created a new class library using the following namespace:
MyCompany.Repositories.Users
Based on my experience over the years I would expect this namespace to be named as:
MyCompany.Repository.User
Which style do you normally use for your namespaces? I was thinking my style was somewhat standard. It looks cleaner to me. Can you provide any authoritative urls which recommend namespace naming conventions?
Interesting question. I've never seen any advice beyond "use plurals where appropriate" for C#.
Let's assume that the namespace is MyCompany.Repositories
Borrowing from a similar question posed in the Java world I would suggest that plural is valid. The components that live within the Repositories namespace will be homogeneous in the sense that they are all repositories (UserRepository, StudentRepository, LocationRepository, etc).
Conversely, a namespace like MyCompany.ReportingEngine would be valid as a singularly-named namespace, as this namespace may contain heterogeneous classes that do very different things (IE a query generator class, a report model, a field model, a filtering model). MyCompany.ReportingEngines would suggest that this namespace contains different types of classes that are reporting engines.

Is using non standard English characters in c# names a bad practice? [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 6 years ago.
Improve this question
English is not my native language. I would like to use non-English characters in my code, for instance: "ç, ã, é ..."
Is it a bad practice to use those characters for classes, variable or method declarations?
I'm not asking what characters are technically available in c#, My question is whether or not it is a good idea.
There's no technical issues with using non-English characters. C# allows a very large number of Unicode symbols in variable names. The real question is whether or not it is a good idea.
To answer that, you really have to ask yourself a question of "who is my audience?" If your code will only be looked at by French speakers typing on a French layout keyboard, ç is probably a very valid character. However, if you intend your code to be modified by others whose keyboard layout is not French, you may find that that symbol is very hard for them to type. This will mean that, if they want to use your variable name, they'll have to cut/paste it in place because they can't type it directly. This would be a death sentence for any development.
So figure out who your audience is, and limit yourself to their keyboard layout.
It's supported. See here: http://rosettacode.org/wiki/Unicode_variable_names#C.23
Whether it's bad practice or not, it's hard to tell. If it works, it works. Personally, I'd just choose a language all the possible contributors understand.
I just tried the 3 characters you listed there and it compiled when I used them as variable names, so I assume that means they won't cause issues in your code.

Should I avoid using Unicode characters in variable names? [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 8 years ago.
Improve this question
The C# language specification says we can use Unicode characters in specifiers (class and variable names, etc.)
I went a long way doing this in my code. Since I live in Brazil, this includes lots of accented characters, with variable names such as rotação, ângulo, máximo, etc.
Every time a more "experienced" developers catches this, I am strongly advised to avoid it and change everything back. Otherwise a lot of kittens will die.
I went then a quite long way undoing it, but today I found some variables still named with accents, in methods written long ago, and no kitten died so far (at least not because of that).
Since my language (Portuguese) is accented, it would make a lot of sense if our codebase has those characters, since C# explicitly allows it.
Are there any sound technical reason not to use Unicode characters in C#/Visual Studio codebases?
What if you had to take over code written in Cyrillic? Most developers are comfortable with standard Latin character sets. They're easy to type on any keyboard.
I would recommend sticking to the simple set.
A few reasons why not to use Unicode variable names:
It makes it hard for people to type them
Some Unicode characters look very similar to non-native speaker (see the case of the Turkish I)
Some editors might not display them correctly
https://twitter.com/Stephan007/status/481001490463866880/photo/1

C# classes interoperate with other .NET languages [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Is there a way to ensure that other .NET languages will interoperate with my C# classes ?
The most important thing would be for you to use the CLSCompliantAttribute. This prevents you from inadvertently using non CLS compliant features in C#.
There are a few pretty obvious rules that I can mention here. Note, this list is not exhaustive. I just wanted to point our some of the rules to give you a feel of what CLS compliance is all about.
Do not use unsafe types (pointers) in the public interface.
Do not mix member name casing in the public interface.
Do not use unsigned types in the public interface.
Read the article Cross Language Interoperability for more information.
Yes, decorate your assembly with CLSCompliant attribute.
Making your code CLS Compliant

Categories