I'm writing down some documentation on file naming of configuration files, and I don't know whether this question belongs here as it's not code-related, but here it goes.
So I want to describe how to name files and I have something along the lines of:
{client_name}-{product_name}-{season}-{id}.yaml
Now my question is since client_name, product_name, season, and id are not necessarily variable names, just used to describe what string goes where, should there be underscores in multiple word descriptions, or should I keep them separated with space, like:
{client name}-{product name}-{season}-{id}.yaml
My concern is that because of the underscores, someone may think they are variables and look for them somewhere in the code of the projects, instead of in other linked documentation.
Indeed if your naming system do not vary too much, it is evidently failing on its purpose.
I hardly can find an standard on this, but some widespread use is to have the following structure, with more or less modifications
[Project Name]-[Department]-[Doc.Type]-[Number]-[Revision]
The last kind of structure works well for definite, unchangeable work structures. Check the CERN LHC Document Name Structure as an example for this.
From other side, for more dynamic but flat environments, with documents generated day by day, and even, auto generated by systems like cameras or dataloggers, something exposing the specific timestamp are more useful, in the date format YYYYMMDD or YYYY-MM-DD, or even with timestamps extending to hours, minutes or seconds for more automated processes YYYYMMDDhhmmss based on the ISO Date:
[Date]-[Document Name]
Unfortunately there is not any Standard Naming Convention nor under the ISO-7001 or under any other Standard related to Naming Systems, and it is much left to the Quality Management System to specify the structure to use.
Related
Although this topic has been touched many times I write about it again to share my experiences. Before starting the project I was looking for a naming convention for database and read the advice that I found on this website. I used the convention Pascal or Camel if you prefer.
MyTable
MyColumnName
Firstly, it turned out that the project is unportable as databases write data in the directories with names coming from the names of the tables, and a variety of operating systems have different interpretation of lowercase and capital letters in the names of files and directories.
I changed convention to lowercase underscore naming convention.
my_table
my_column_name
It seemed that the problem is solved, but not quite.
There is another problem: the keywords.
Here is an excerpt discussing which I came across when I recognized the problem in my project. In short Frameworks don't quote keywords because it reduces database performance.
So another convention change.
_my_table
_my_column_name
_reserved_keyword
My question is: How many changes to the naming convention was waiting for me?
I hope this post will help others overcome the problems with which I had to face.
Naming convention isn't a must, its only an recommendation. You should wisely specify the table, column, etc. names, thinking about them as there were no naming conventions.
Do not use reserved words, non-alphabetical chars, etc. and your problem is gone.
I have a databases class in which the prof wants us to create domains for every type, even when these just end up being aliases to other types. For example, instead of using the default DATE type, we would create out own type depending on what kind of day it is (eg, OrderDate).
I'm wondering if this is common or a best practice.
I can think of some pros and cons to this approach. A pro is that it makes it clear exactly what the domain is intended for, and typically we'd only compare fields if they have the same domain and any other comparison is something to watch for (since it could be comparing apples to oranges). But as a con, this also makes it more confusing to work with the types, as we'd have to refer to the domain declaration to figure out what kind of type a column really is (not that we need to do this too often).
This is not a particularly common practice. For instance, I have worked on many databases over the years and I have never used such substitutions for base types.
In your example, for instance, an order date may be an order date. But, I might want to know the how long ago that was in the past -- this requires "mixing" types because the current date (sysdate? now()? getdate()? CURRENT_TIMESTAMP?) is not an OrderDate. Or I might want to know how long after the order the first complaint or first return was made. Even if the conversion is invisible and automatic, why introduce incompatible types?
Another issue is that different databases differ in their support for user-defined data types. So, code using user defined types would likely make code more difficult to port to a different database. Why limit future options?
There are some occasional uses for user defined types do have a place for particular new types that might be needed -- complex numbers and points perhaps. There may even be some situations in some databases where a user defined type on a base type is useful -- for instance, to get represent a telephone number consistently. Using them liberally as substitutes for built-in types? It seems like overkill, complicating the code, hampering some important queries, and limiting future portability options.
What is a scenario that exemplifies a good reason to use prefixes, such as fn_GetName, on function names in SQL Server? It would seem that it would be unnecessary since usually the context of its usage would make it clear that it's a function. I have not used any other language that has ever needed prefixes on functions, and I can't think of a good scenario that would show why SQL is any different.
My only thinking is that perhaps in older IDE's it was useful for grouping functions together when the database objects were all listed together, but modern IDE's already make it clear what is a function.
You are correct about older IDEs
As a DBA, trying to fix permissions using SQL Server Enterprise Manager (SQL Server 2000 and 7.0), it was complete bugger trying to view permissions. If you had ufn or usp or vw it became easier to group things together because of how the GUI presented the data.
Saying that, if you have SELECT * FROM Thing, what is Thing? A view or a table? It may work for you as a developer but it will crash when deployed because you don't grant permissions on the table itself: only views or procs. Surely a vwThing will keep your blood pressure down...?
If you use schemas, it becomes irrelevant. You can "namespace" your objects. For example, tables in "Data" and other objects per client in other schemas eg WebGUI
Edit:
Function. You have table valued and scalar functions. If you stick with the code "VerbNoun" concept, how do you know which is which without some other clue. (of course, this can't happen because object names are unique)
SELECT dbo.GetName() FROM MyTable
SELECT * FROM dbo.GetName()
If you use a plural to signify a table valued function, this is arguably worse
SELECT dbo.GetName() FROM MyTable
SELECT * FROM dbo.GetNames()
Whereas this is less ambiguous, albeit offensive to some folk ;-)
SELECT dbo.sfnGetName() FROM MyTable
SELECT * FROM dbo.tfnGetName()
With schemas. And no name ambiguity.
SELECT ScalarFN.GetName() FROM MyTable
SELECT * FROM TableFN.GetName()
Your "any other language" comment doesn't apply. SQL isn't structured like c#, Java, f#, Ada (OK, PL/SQL might be), VBA, whatever: there is no object or namespace hierarchy. No Object.DoStuff method stuff.
A prefix may be just the thing to keep you sane...
There's no need to prefix function names with fn_ any more than there's a need to prefix table names with t_ (a convention I have seen). This sort of systematic prefix tends to be used by people who are not yet comfortable with the language and who need the convention as an extra help to understanding the code.
Like all naming conventions, it hardly matters what the convention actually is. What really matter is to be consistent. So even if the convention is wrong, it is still important to stick to it for consistency. Yes, it may be argued that if the naming convention is wrong then it should be changed, but the effort implies a lot: rename all objects, change source code, all maintenance procedures, get the dev team committed to follow the new convention, have all the support and ops personnel follow the new rules etc etc. On a large org, the effort to change a well established naming convention is just simply overwhelming.
I don't know what your situation is, but you should consider carefully before proposing a naming convention change just for sake of 'pretty'. No matter how bad the existing naming convention in your org is, is far better to stick to it and keep the naming consistency than to ignore it and start your own.
Of course, more often than not, the naming convention is not only bad, is also not followed and names are inconsistent. In that case, sucks to be you...
What is a scenario that exemplifies a
good reason to use prefixes
THere is none. People do all kind of stuff because they always did so, and quite a number of bad habits are explained with ancient knowledge that is wrong for many years.
I'm not a fan of prefixes, but perhaps one advantage could be that these fn_ prefixes might make it easier to identify that a particular function is user-defined, rather than in-built.
We had many painful meetings at our company about this. IMO, we don't need prefixes on any object names. However, you could make an argument for putting them on views, if the name of the view might conflict with the underlying table name.
In any case, there is no SQL requirement that prefixes be used, and frankly, IMO, they have no real value.
As others have noticed, any scenario you define can easily be challenged, so there's no rule defining it as necessary; however, there's equally no rule saying it's unnecessary, either. Like all naming conventions, it's more important to have consistent usage rather than justification.
One (and the only) advantage I can think of is that it a consequently applied prefixing scheme could make using intellisense / autocomplete easier since related functionality is automagically grouped together.
Since I recently stumbled over this question, I'd like to add the following point in favour of prefixes: Imagine, you have some object id from some system table and you want to determine whether it's a function, proc, view etc. You could of course run a test for each type, it's much easier though to extract the prefix from the object name and then act upon that. This gets even easier when you use an underscore to separate the prefix from the name, e.g. usp_Foo instead of uspFoo. IMHO it's not just about stupid IDEs.
Our CMS accepts files with national characters in their names and stores them on the server without a problem. But how bad is such approach in perspective? For example is it possible to store files with filenames in Hebrew, or Arabic or in any other language with non-latin alphabet? Is there a standard established way to handle these?
A standard way would be to generate unique names yourself and store the original file name somewhere else. Typically, even if your underlying OS and file system allow arbitrary Unicode characters in the file name, you don't want users to decide about file names on your server. Doing so may impose certain risks and lead to problems, e.g. caused by too long names or file system collisions. Examples of sites that do that would be Facebook, flickr and many other.
For generating the unique file name Guid values would be a good choice.
Store the original filename in a database of some sort, in case you ever need to use it.
Then, rename the filename using a unique alphanumeric id, keeping the original file extension.
If you expect many files then you should create directories to group the files. Using the year, month, day, hour and minute is usually enough for most. For example:
.../2010/12/02/10/28/1a2b3c4d5e.mp3
Yes, I've had experience with massive mp3 collections which are notorious for being named in the language of the country where the song originates which can cause trouble in several places.
It's fine as long as you detect the charset it's in from the headers in the request, and use a consistent charset (such as UTF-8) internally.
On a Unix server, it's technically feasible and easy to accept any Unicode character in the filename, and then convert filenames to UTF-8 before saving them. However, there might be bugs in the conversion (in the HTML templating engine or web framework you are using, or the user's web browser), so it might be possible that some users will complain that some files they have uploaded disappeared. The root cause might be buggy filename conversion. If all characters in the filename or non-latin, and you (as a software developer) don't speak that foreign language, then good luck figuring out what has happened to the file.
It is an excellent idea. Being Hungarian, I'm pretty annoyed when I'm not allowed to use characters like áÉŰÖÜúÓÚŰÉÍí :)
There is a lot of software out there that has bugs regarding dealing with such file names, especially on Windows.
Udpate:
Example: I couldn't use the Android SDK (without creating a new user), because I had an é in my user name. I also ran into a similar problem with the Intel C++ compiler.
Software usually isn't tested properly with such file names. The Windows API still offers "ANSI" encoded versions of functions, and many developers don't seem to understand its potential problems. I also keep on coming across webpages that mess up my name.
I don't say don't allow such file names, in fact in the 21st century I would expect to be able to use such characters everywhere. But be prepared that you may run into problems.
Exists any naming guideline for naming columns at Sql Server? I searched at MSDN, but dont found anything, just for .Net
There are lots of different conventions out there (and I'm sure other answers may make some specific suggestions) but I think that the most important thing is that you be consistent. If you are going to use a prefix for something, use it everywhere. If you are going to have a foreign key to another table, use the same column name everywhere. If you are going to separate words with underscores, do that everywhere.
In other words, if someone looks at a few tables, they should be able to extrapolate out and guess the names of other tables and columns. It will require less mental processing to remember what things are called.
There are many resources out there, but nothing that I have been able to truly pin down as a SQL Server specific set or anything published by Microsoft.
However, I really like this list.
Also, very important to NOT start out stored procedures with sp_
To be 100% honest though, the first part of my posted link is the most important. It must make sense for your organization, application, and implementation.
As always, google is your friend...
I find the following short list helpful:
Name tables as pluralnouns (or singular, but as a previous response stated, be consistent) for example "Customers", "Orders", "LineItems"
Stored procedures should be named without any prefixes such as "sp_" since SQL Server uses the "sp_" prefix to denote special meaning for system procedures.
Name columns as though as you would name attributes on a class (without using underscores)
Try not to use space characters in naming columns or database entities since you would have to escape all names with "[...]"
Many-to-many tables: for example "CustomerOrders"