What is the recommended or "generally agreed upon" coding convention in DM?
My two guesses would be Java per Oracle, or standard practice C.
ID:1114955
![]() Jan 6 2013, 4:38 am
|
|
There isn't one. Everyone pretty much uses their own convention, from some_proc, someProc, to using braces and semi-colons, to not doing so.
I personally follow Oracle's code conventions. |
Unfortunately, there are no conventions set by the developers or 'gurus'. Though, (LordAndrew and) I were planning to write a guide discussing the different ways of formatting your code and the benefits of one way over others.
|
I am a camelCaser. I'm a little more liberal with my whitespace than Magnum2k is in his example.
|
I just prefer consistency as a sort of "code".
If I do one proc lowercase, i prefer to do them all that way, likewise if I capitalize the beginning of a var, I tend to capitalize the first letter of all vars. Consistency can provide small hints where there really isn't any other type of pattern to pick up on. |
Everything I do is lowercase, variables, procedures, file names. I might want to change that as it seems camelCase is much more common.
|
I mainly do everything in lowercase, I do however capitalize my procs just so they stand out a bit more from everything else.
|
There is already a naming convention, sort of. All built-in methods are Pascal case (eg world.ClearMedal()) while global procs are usually lowercase with words separated by an underscore (step_to()). There are a bunch of exceptions, though: text manipulation procs (cmptext/cmptextEx), conversion procs (num2text), interface procs (winshow), and type procs (typesof, istype).
|
Yep, the convention for BYOND's built-in procedures have been discussed, but, I'm pretty sure most (real) programmers would conform to lower camelCase.
Garthor wrote: There are already good naming conventions: lowercase for functions, UpperCase for methods. That is: any proc belonging to an object is in UpperCase, whereas any proc that is global is in lowercase. Functions also must use underscores to separate words, because they don't use case to indicate where a new one begins. The 2 for the conversion functions is a bit iffy but at least is consistent among them. Tom wrote: Uppercase names are hard-coded procs. Lowercase ones are functions. |
Some of my code conventions are less common. I don't really do anything too wonky with my source, though.
#define CONSTANTVARSINALLCAPS 10 I'm also a bit weird when it comes to whitespace. I keep works in progress very spaced out, but once I'm finished with it and satisfied, I condense everything down. proc I also try not to use brackets and semicolons to keep the code from getting cluttered with unneeded characters. Though being a C++ guy, I catch myself doing it anyways :P |
/mob/proc/procedure() |
Your verb convention seems way too overdone for my tastes. You could easily make the verb's name be "Say" by capitalizing the "S" in the definition. Plus, capitalizing the definition makes verbs stand out more from procedures. All in all using Cap_Case for verbs is the way I tend to go.
I can go either lower_case or camelCase with procedures. It all depends on how I feel when I start. Once I choose one though, I stick with it. My variables are always lower_case. |
In case anyone is curious, mine is:
Start procedures or variables that aren't meant to be called or overridden by the user (or your self) with an underscore library For functions that provide something the user can use, start with a capital letter, and each subsequent word capitalized. projectile For variables intended to access within class, we use lower case separated by underscores mob/var And to the outside world, all of these variables have get and set functions, for maximum control of the values. mob/proc Optionally, tag _ref on the end of anything that will cause an object to persist, preventing garbage collection... mob/var For short mathematical or utility type functions, all lowercase with underscores proc/get_speed_delay(n) I try to keep indentation down to a minimum by using slashes whenever possible, and if something is simple, I like to keep it inline. I'd say that's about it with me! Thanks to everyone for sharing your habits. |
That's what I use, not sure about others.