Difference between revisions of "Coding Standards"

From NSV13
Jump to navigationJump to search
imported>Rockdtben
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
=Specification=
 
=Specification=
  
As mentioned before, you are expected to follow these specifications in order to make everyone's lives easier, it will also save you and us time, with having to make the changes and us having to tell you what to change. Thank you for reading this section.
+
You are expected to follow these specifications in order to make everyone's lives easier, it will also save you and us time, with having to make the changes and us having to tell you what to change. Thank you for reading this section.
  
 
* As BYOND's Dream Maker is an object oriented language, code must be object oriented when possible in order to be more flexible when adding content to it. If you are unfamiliar with this concept, it is highly recommended you look it up.
 
* As BYOND's Dream Maker is an object oriented language, code must be object oriented when possible in order to be more flexible when adding content to it. If you are unfamiliar with this concept, it is highly recommended you look it up.
  
* You must write BYOND code with absolute pathing, like so:
+
* You must not use colons to override safety checks on an object's variable/function, instead of using proper type casting, unless the code in question is a known resource hog.
 
 
<pre>
 
 
 
/obj/item/weapon/baseball_bat
 
    name = "baseball bat"
 
    desc = "A baseball bat."
 
    var/wooden = 1
 
 
 
/obj/item/weapon/baseball_bat/examine()
 
    if(wooden)
 
        desc = "A wooden baseball bat."
 
    else
 
        desc = "A metal baseball bat."
 
    ..()
 
 
 
</pre>
 
 
 
* You must not use colons to override safety checks on an object's variable/function, instead of using proper type casting.
 
  
 
* It is rarely allowed to put type paths in a text format, as there are no compile errors if the type path no longer exists. Here is an example:
 
* It is rarely allowed to put type paths in a text format, as there are no compile errors if the type path no longer exists. Here is an example:
Line 39: Line 21:
 
* Hacky code, such as adding specific checks, is highly discouraged and only allowed when there is no other option. You can avoid hacky code by using object oriented methodologies, such as overriding a function (called procs in DM) or sectioning code into functions and then overriding them as required.
 
* Hacky code, such as adding specific checks, is highly discouraged and only allowed when there is no other option. You can avoid hacky code by using object oriented methodologies, such as overriding a function (called procs in DM) or sectioning code into functions and then overriding them as required.
  
* Duplicated code is 99% of the time never allowed. Copying code from one place to another maybe suitable for small short time projects but /tg/station focuses on the long term and thus discourages this. Instead you can use object orientation, or simply placing repeated code in a function, to obey this specification easily.
+
* Duplicated code is 99% of the time never allowed. Copying code from one place to another maybe suitable for small short time projects but NSV13 focuses on the long term and thus discourages this. Instead you can use object orientation, or simply placing repeated code in a function, to obey this specification easily.
  
 
* Code should be modular where possible, if you are working on a new class then it is best if you put it in a new file.
 
* Code should be modular where possible, if you are working on a new class then it is best if you put it in a new file.
 +
 +
* Changes in their own files that are only on NSV must be placed in the "NSV13" folder, not the core "code" folder. The structure inside the nsv13 folder is similar that in the "code" folder. Large blocks of code or extra definitions should also go here when possible.
 +
 +
* Changes to core files (files in the "code" folder) that are not also on BeeStation must have a comment indicating they are NSV13 code. This is to help preserve them when we rebase.
 +
<pre>
 +
if(isovermap(A)) // NSV13 - special overmap handling
 +
    bar()
 +
 +
Alternatively
 +
// NSV13 - special overmap handling - Start
 +
if(isovermap(A))
 +
    bar()
 +
// NSV13 - special overmap handling - End/Stop
 +
</pre>
  
 
* Bloated code may be necessary to add a certain feature, which means there has to be a judgement over whether the feature is worth having or not. You can help make this decision easier by making sure your code is modular.
 
* Bloated code may be necessary to add a certain feature, which means there has to be a judgement over whether the feature is worth having or not. You can help make this decision easier by making sure your code is modular.
Line 47: Line 43:
 
* You are expected to help maintain the code that you add, meaning if there is a problem then you are likely to be approached in order to fix any issues, runtimes or bugs.
 
* You are expected to help maintain the code that you add, meaning if there is a problem then you are likely to be approached in order to fix any issues, runtimes or bugs.
  
* Follow the stylesheet. Changing formatting with \red or other tags is not allowed. You must use span classes, which are defined in interface/stylesheet.dm.
+
* Follow the stylesheet. Changing formatting with \red or other tags is not allowed. You must use [[Text Formatting|span classes]], which are defined in interface/stylesheet.dm.
 +
 
  
 
[[Category:Game Resources]] [[Category:Guides]]
 
[[Category:Game Resources]] [[Category:Guides]]
 
{{Contribution guides}}
 
{{Contribution guides}}

Latest revision as of 23:58, 30 March 2023

Specification[edit | edit source]

You are expected to follow these specifications in order to make everyone's lives easier, it will also save you and us time, with having to make the changes and us having to tell you what to change. Thank you for reading this section.

  • As BYOND's Dream Maker is an object oriented language, code must be object oriented when possible in order to be more flexible when adding content to it. If you are unfamiliar with this concept, it is highly recommended you look it up.
  • You must not use colons to override safety checks on an object's variable/function, instead of using proper type casting, unless the code in question is a known resource hog.
  • It is rarely allowed to put type paths in a text format, as there are no compile errors if the type path no longer exists. Here is an example:
//Good
var/path_type = /obj/item/weapon/baseball_bat

//Bad
var/path_type = "/obj/item/weapon/baseball_bat"
  • You must use tabs to indent your code, NOT SPACES.
  • Hacky code, such as adding specific checks, is highly discouraged and only allowed when there is no other option. You can avoid hacky code by using object oriented methodologies, such as overriding a function (called procs in DM) or sectioning code into functions and then overriding them as required.
  • Duplicated code is 99% of the time never allowed. Copying code from one place to another maybe suitable for small short time projects but NSV13 focuses on the long term and thus discourages this. Instead you can use object orientation, or simply placing repeated code in a function, to obey this specification easily.
  • Code should be modular where possible, if you are working on a new class then it is best if you put it in a new file.
  • Changes in their own files that are only on NSV must be placed in the "NSV13" folder, not the core "code" folder. The structure inside the nsv13 folder is similar that in the "code" folder. Large blocks of code or extra definitions should also go here when possible.
  • Changes to core files (files in the "code" folder) that are not also on BeeStation must have a comment indicating they are NSV13 code. This is to help preserve them when we rebase.
if(isovermap(A)) // NSV13 - special overmap handling
    bar()

Alternatively
// NSV13 - special overmap handling - Start
if(isovermap(A))
    bar()
// NSV13 - special overmap handling - End/Stop
  • Bloated code may be necessary to add a certain feature, which means there has to be a judgement over whether the feature is worth having or not. You can help make this decision easier by making sure your code is modular.
  • You are expected to help maintain the code that you add, meaning if there is a problem then you are likely to be approached in order to fix any issues, runtimes or bugs.
  • Follow the stylesheet. Changing formatting with \red or other tags is not allowed. You must use span classes, which are defined in interface/stylesheet.dm.
Contribution guides
General Hosting a server, Setting up git, Guide to working with tgstation as an upstream repository, Downloading the source code, Guide to contributing to the game, Reporting issues, Game resources category, Guide to changelogs
Database (MySQL) Setting up the database, MySQL
Coding Coding standards, Understanding SS13 code, SS13 for experienced programmers, Binary flags‎, Getting Your Pull Accepted, Text Formatting
Mapping Guide to mapping, Map merger
Spriting Guide to spriting
Wiki Guide to contributing to the wiki, Wikicode, Maintainer Assignments