242

Quoting https://www.python.org/dev/peps/pep-0008/#package-and-module-names: Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged. For classes: Class names should normally use the ...


189

Whilst many, including "Uncle Bob", advise not to use I as a prefix for interfaces, doing so is a well-established tradition with C#. In general terms, it should be avoided. But if you are writing C#, you really should follow that language's conventions and use it. Not doing so will cause huge confusion with anyone else familiar with C# who tries to read ...


175

Michael Durrant's answer is IMHO not bad, but it is not literally answering the question (as he admitted by himself), so I'll try to give an answer which does: I also understand that comments should explain why the code does what it does, not how. Given all this is it even possible to write good coding standards that capture this idea? Obviously you can ...


153

Major anti-pattern leading to poor quality code with less clarity btw readers, the title was originally "comment every line of code?" and you can imagine the instinctive reaction of many of us, myself included. I later retitled to the longer more accurate title. At first, reading your question I thought, yuch duplicate stuff in comments , but ok, maybe if ...


118

Is vs. Can According to the Microsoft naming convention recommendations, both "Is" and "Can" are OK (and so is "Has") as a prefix for a Boolean. In plain English, "Is" would be used to identify something about the type itself, not what it can do. For example, IsFixed, IsDerivedFrom, IsNullable can all be found in CLR types and methods. In all of these ...


100

Swift has matured significantly in the years since this answer was written. The design guidelines now state: Protocols that describe what something is should read as nouns (e.g. Collection). Protocols that describe a capability should be named using the suffixes able, ible, or ing (e.g. Equatable, ProgressReporting). Thank you to David James for spotting ...


92

That naming convention is often used when people want to be able to give a variable the same name as its type. For example: Employee employee; Some languages even enforce that capitalization. This prevents having to use annoying variable names like MyEmployee, CurrentEmployee, EmployeeVar, etc. You can always tell if something is a type or a variable, ...


69

In .NET, you often have pairs of methods where one of them might throw an exception (DoStuff), and the other returns a Boolean status and, on successful execution, the actual result via an out parameter (TryDoStuff). (Microsoft calls this the "Try-Parse Pattern", since perhaps the most prominent example for it are the TryParse methods of various primitive ...


62

Win32 is the customary name for the Windows API. This API specifies how applications can interface with the operating system. It is roughly comparable with the POSIX standard on Unix, but Win32 also covers GUIs and many other features. The Win32 API is not limited to 32-bit Windows installations. From the Windows Dev Center: The Windows application ...


52

The only reason I can think of is that dates are immutable objects, so by calling plusDays you're not adding days to the original object but creating a new one with new properties, but that's very vary subtle. This is exactly the reason. Imagine you had some kind of api for manipulating ranges of dates for scheduling purposes. It might expose methods ...


45

They are typically referred to as concrete classes. ...A concrete class is a class that can be instantiated, as opposed to abstract classes, which cannot.


39

Here is a link for different types of Python name conventions. The style guide for Python is based on Guido’s naming convention recommendations.


39

The interface is the important logical concept, hence, the interface should carry the generic name. So, I'd rather have interface Something class DefaultSomething : Something class MockSomething : Something than interface ISomething class Something : ISomething class MockSomething : ISomething The latter has several isues: Something is only one ...


39

Why prefixes in the first place? The prefix for function names is a C practice that intends to avoid naming conflicts. This is especially suitable in big projects, where different teams could easily come with do_this() and do_that() in different subcomponents of a large codebase. Since C lacks of a namespace or a package feature, the prefix is the most ...


37

All-uppercase letters stand out and make the file easily visible which makes sense because it is probably the first thing a new user would want to look at. (Or, at least, should have looked at…) As others have already said, file names starting with a capital letter will be listed before lower-case names in ASCIIbetical sorting (LC_COLLATE=C) which helps ...


35

There isn't any. It is what most people do, so it has become the standard because that is what everyone does. A lot of literature follows this convention so people picked up the habit. The convention isn't as important as the consistency across the code. As long as everything is named in a consistent manner so that I can tell what things are from looking ...


29

Because the Windows API is 30+ years old and has been around when PC's were 16-bit, then 32-bit came along, then Win32s, then win64. There is platform dependence in windows development, and you need your code to match the OS libraries (dll's) in architecture. https://en.wikipedia.org/wiki/Windows_API#Versions A windows application that is built against ...


28

This isn't just about naming conventions. C# doesn't support multiple inheritance so this legacy use of Hungarian notation has a small albeit useful benefit where you're inheriting from a base class and implementing one or more interfaces. So this... class Foo : BarB, IBarA { // Better... } ...is preferable to this... class Foo : BarB, BarA { // ...


26

1. Why the standard exists? After all, wouldn't it be better to let everyone write the code according to personal preference, and stop talking about which standard is better? The fact is that when you're habituated to one style, it is more difficult to read code which uses a different style. Your brain spends more time trying to understand the convention (...


24

Scala is also inspired by Ocaml, which uses Option. Options are an Ocaml standard type that can be either None (undefined) or Some x where x can be any value. Options are widely used in Ocaml to represent undefined values (a little like NULL in C, but in a type and memory safe way)... I think the name chosen is a matter of taste.


24

No, there is no widely used naming conventions for this. Examples I have seen are Main, Application, XLauncher or X, where X is the name of the project/application. And yes, I think it's good for this class to contain only the minimum logic/code necessary to set up the application and start it. But I'm sure there are a lot of God Objects and Big Balls of ...


24

I don't think a coding standards document is the place to specify what is already common sense. The purpose of a coding standard is to guarantee consistence (and avoid arguments) about issues where reasonable people might disagree and there is no single obvious right answer, e.g. naming conventions, indentation etc. Such commenting as in your example is ...


23

When they were working on the API for Windows, Microsoft recommended the use of Hungarian Notation, using 'm_', as well as 'i', 'sz', etc. At the time, this was useful because the IDE wasn't robust enough to show this information to you. C#, on the other hand, has a very robust IDE from the outset. So they made the recommendation in Microsoft's Naming ...


21

Traditionally the file was called README in uppercase because command-line environments that use alphabetical ordering would then put the file at the top. This makes them easily visible in big directories. It's most likely a holdover from the Unix/Linux world where you would download sources and then build your software. Having files like README and ...


20

This is a special case with the name class, as that is a reserved keyword in some languages such as Java and thus cannot be used as the variable name. Using clazz or klass is a way to workaround that. Other options would include e.g. myClass. In Java it's pretty common, as even the JDK uses that convention. See also https://stackoverflow.com/a/2530174/...


20

It is not possible. What you are essentially trying to do is nearly to mechanize good judgment. When writing critical software such as for life supporting medical systems, huge amounts of checklists and whatnot are virtually inevitable. Not only do even smart people make mistakes, a lot of the software for these devices is written by people that aren't very ...


19

The REST spec (whatever level you want to go with) wasn't designed as database access. It is trying to bring standardization to API access. The SQL conventions mentioned (whether you want to use them or not) were not designed with API access in mind. They are for writing SQL queries. So the issue to unpack here is the conceptual understanding that an API ...


19

If it adds meaningful clarification or fits the "ethos" ... Yes. .NET's OrderBy() and ElementAt() might be good examples. Personally, I like code that reads pretty much like English. It takes a ton of guesswork, hovering and digging, and arcane knowledge out of reading someone's code when it tells me unambiguously what it does. And as far as I can tell, I'...


18

What if you simply threw the exception to the calling code? This way you are delegating the exception handling to who ever is using your code. What if, in the future you would like to do the following: If no exceptions are thrown, take action A If (for instance) a FileNotFoundException is thrown, take action B If any other exception is thrown, take action ...


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