Questions tagged [convention]

A convention is a set of agreed, stipulated, or generally accepted norms. It typically helps common efficiency or understanding but is not required, as opposed to a strict standard or protocol. In programming, a typical kind of convention is the coding convention which stipulates how programmers should format and style their programs.

Here are some examples of conventions that affect programming:

  • Coding style: how the source code is formatted (indentation & spacing, location of braces, ordering of methods/functions, etc.). This helps programmers to read and understand the code more quickly, find bugs more easily.
  • File naming: some programs expect the files they process to be named a certain way. For example, the ant command assumes by default that the build file is names build.xml, which allow developers to omit the file name in the command line.
  • File structure: programmers are often used to particular way to organize the files, that depends on the language / technology. This allows to read / browse through an unknown code base more easily. Even compilers of some language may expect files to be organized by default in a conventional way. For example, maven expects source files to be in a src directory and binary files in a target directory.
  • Variable naming: some variables with given semantics are conventionally named. For example, for loop variable are usually named i, j, k, etc.; and Cartesian coordinates are usually named x, y and z.
353 questions
110
votes
8 answers

How long should SQL email fields be?

I recognize that an email address can basically be indefinitely long so any size I impose on my varchar email address field is going to be arbitrary. However, I was wondering what the "standard" is? How long do you guys make it? (same question for…
Mala
  • 14,178
  • 25
  • 88
  • 119
66
votes
10 answers

PSR-2 standard for long if-conditions

I did not find any standard for this case: if ($a == $b && $b == $c && $c == $d && $g == $d) { } or if (($a == $b && $b == $c) && ($c == $d && $g == $d)) { } Imagine the var-names are longer and 80 letters are exceeded. How should I handle…
user3631654
  • 1,735
  • 6
  • 22
  • 38
60
votes
2 answers

rails boolean fields: `is_foo` or just `foo`?

Possible Duplicate: Naming Boolean columns in Rails What is the rails convention regarding names of boolean fields? For example, if I have a User model that needs a flag for its "activeness", should I call the db field is_active or active ? Note:…
kikito
  • 51,734
  • 32
  • 149
  • 189
48
votes
5 answers

What does it mean when a variable equals a function?

Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} In JavaScript, what's the purpose of defining a variable as a function? I've seen this convention before and don't fully understand it. For example, at…
daGUY
  • 27,055
  • 29
  • 75
  • 119
38
votes
2 answers

How to set Emacs tabs to spaces in every new file?

I would like to have an .emacs setting so that tabs are always formed by consecutive spaces. Preferably in each possible mode. In other editors it never seemed a problem, but in .emacs I'm a bit stuck with the tabs I'm afraid.
Peter
  • 47,963
  • 46
  • 132
  • 181
30
votes
2 answers

Always prefer set> to set since C++14?

#include #include #include using namespace std; int main() { string_view key = "hello"; set coll1; coll1.find(key); // error set> coll2; coll2.find(key); // ok since…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
29
votes
1 answer

What is the difference between [ ] and ( ) brackets in Racket (lisp programming language)?

It seems to me that technically both are interchangeable but have different conventional meanings.
Mahathi Vempati
  • 1,238
  • 1
  • 12
  • 33
25
votes
4 answers

Is It A Bad Practice to List Ruby Version in Both Gemfile and .ruby-version Dotfile?

My latest Rails project is more or less and experiment for me to break lots of things and learn in the process. I have the latest version of Ruby specified in my gemfile: ruby '2.2.3' And I also have a .ruby-version dotfile in the project, with the…
Todd
  • 2,824
  • 2
  • 29
  • 39
24
votes
10 answers

Java Coding standard / best practices - naming convention for break/continue labels

Sometimes a labeled break or continue can make code a lot more readable. OUTERLOOP: for ( ;/*stuff*/; ) { //...lots of code if ( isEnough() ) break OUTERLOOP; //...more code } I was wondering what the common convention for the labels…
Mo.
  • 15,033
  • 14
  • 47
  • 57
23
votes
10 answers

Naming convention for VB.NET private fields

Is there an official convention for naming private fields in VB.NET? For example, if I have a property called 'Foo', I normally call the private field '_Foo'. This seems to be frowned upon in the Offical Guidelines: "Do not use a prefix for field…
Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
18
votes
5 answers

Why does Objective-C use YES/NO macro convention instead of true/false?

Most languages use the true/false keywords for boolean values. I found that even Smalltalk is using true/false. I know Objective-C is just borrowing concepts from Smalltalk, not the language itself, but I'm curious why it's using YES/NO instead of…
eonil
  • 83,476
  • 81
  • 317
  • 516
18
votes
5 answers

Should I use relative include paths for my project, or place the include-directory on the include path?

In my project, I currently use relative paths to include my files, which admittedly doesn't change often. However, it yields pretty weird include patterns, because I usually nest my files in alot of folders. For example, in my current project I have…
Max
  • 4,345
  • 8
  • 38
  • 64
18
votes
3 answers

What are Best Practices for Maven Modules Naming?

Assuming that we have a project named project and modules module1 and module2, earlier I tend to use the following naming strategy: -- project -- projectModule1 -- projectModule2 Now I use another: -- project -- project-module1 --…
Maksim Sorokin
  • 2,334
  • 3
  • 34
  • 61
17
votes
4 answers

Jackson and that dreaded IOException

Jackson's ObjectMapper#readValue member throws three checked exceptions: IOException JsonParseException JsonMappingException JsonParseException and JsonMappingException extend IOException. I want to wrap the two aforementioned child classes and…
wulfgarpro
  • 6,666
  • 12
  • 69
  • 110
16
votes
3 answers

Python: one single module (file .py) for each class?

I've started programming in python 2 weeks ago. I'm making a separate file (module) for each class as I've done before in languages like Java or C#. But now, seeing tutorials and code from other people, I've realized that many people use the same…
Drumnbass
  • 867
  • 1
  • 14
  • 35
1
2 3
23 24