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
15
votes
4 answers

Where does the TODO convention come from?

I suspect this question has been asked before, but it's not easy to Google for. I am a fairly new coder and I see a lot of code, in a lot of different languages, with comments beginning "TODO". Questions: Is there a practical reason why people…
Richard
  • 31,629
  • 29
  • 108
  • 145
15
votes
2 answers

Kotlin Data Class packaging

Kotlin introduces the wonderful concept of Data Classes. These classes will derive the equals()/hashCode(), toString(), getters()/setters(), and a copy() function based on the properties declared in the constructor: data class KotlinUser(val name:…
Mike Henke
  • 641
  • 2
  • 10
  • 24
15
votes
1 answer

Is there a naming convention for @ComponentScan basePackageClasses?

Spring's @ComponentScan offers a type-safe basePackageClasses attribute - seems a good thing to use especially as it isn't uncommon for packages to be renamed on the project I'm working on. The documentation says: Consider creating a special no-op…
Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
14
votes
7 answers

Java coding convention about static method

It is a very simple question, but I think it is a little bit controversial. When I code Java classes I use the following order. class Foo { // static fields // instance fields // constructors // methods (non-static and static…
Heejin
  • 4,463
  • 3
  • 26
  • 30
14
votes
4 answers

What is better android.R or custom R?

When I started developping android applications, I had a tendency to define custom R values wherever I need, in particular in layout files. For instance: findViewById(R.id.customerName).setText(customer.getName()) with layout:
rds
  • 26,253
  • 19
  • 107
  • 134
14
votes
2 answers

GoLang conventions - create custom type from slice

Is it a good idea to create own type from a slice in Golang? Example: type Trip struct { From string To string Length int } type Trips []Trip // <-- is this a good idea? func (trips *Trips) TotalLength() int { ret := 0 …
DHlavaty
  • 12,958
  • 4
  • 20
  • 25
13
votes
1 answer

How do I check the equality of three values elegantly?

Say I have values a, b and c. I want to find out if they are equal. If I do if a == b == c{...} Then I get a compile error invalid operation: a == b == c (mismatched types bool and TypeOfABandC) This is pretty obvious, because this parses to: (a…
timthelion
  • 2,636
  • 2
  • 21
  • 30
12
votes
5 answers

how lisp implemented in assembly language?

many (may be all?) programming language consist of assembly language how lisp implemented in assembly language? is there any good reference, manual, tutorial, or keyword for google? any official rule/convention for build your own lisp…
kim taeyun
  • 1,837
  • 2
  • 24
  • 49
12
votes
3 answers

Closing braces with Python

PEP 8 has conflicting code examples (in my opinion), and I'm curious what the convention is for positioning closing braces. Under the top of indentation they're on the same line as the parameters. Near the bottom it discusses positioning and instead…
Jacob Stein
  • 312
  • 3
  • 15
11
votes
2 answers

Table naming convention with Doctrine ORM

Is there a convention for naming tables when using Doctrine ORM? I like to name tables with the plural but if there's a convention I want to stick to it. So the table 'users' would be related to tables using the fk as the singular ('user_id'). Is…
calumbrodie
  • 4,722
  • 5
  • 35
  • 63
11
votes
1 answer

Why many people use "-%>" instead of "%>" in Rails?

Sorry for this question, i think its more offtopic, but i couldn't find anything on google! I saw now multiple times that a lot of people use -%> instead of just %>. Whats the sense? Example: <% @images.each_slice(6) do |slice| -%>
Philip Giuliani
  • 1,366
  • 3
  • 20
  • 37
10
votes
1 answer

Is the 'IT.java' filename Suffix (instead of 'Test.java') for JUnit Integration Tests a convention?

I was used to naming my JUnit Integration tests with a *Test.java on the end eg DatabaseConnectionTest.java and placing them in their own integration test directory: eg test/integration/com... On joining a new project I was directed No, all the…
hawkeye
  • 34,745
  • 30
  • 150
  • 304
10
votes
3 answers

Scala: Why use implicit on function argument?

I have a following function: def getIntValue(x: Int)(implicit y: Int ) : Int = {x + y} I see above declaration everywhere. I understand what above function is doing. It is a currying function which takes two arguments. If you omit the second…
user_1357
  • 7,766
  • 13
  • 63
  • 106
9
votes
2 answers

Correct "base path" terminology

Consider a website installed in the 'mysite' directory: /var/www/html/mysite/index.php document root = /var/www/html url = www.mysite.com/mysite/index.php What would you call the following: /var/www/html/mysite/ index.php (Base path? Root…
Yarin
  • 173,523
  • 149
  • 402
  • 512
9
votes
2 answers

What's the rationale/history for the # convention of identifying methods in Ruby?

For example, I've always seen methods referred to as String#split, but never String.split, which seems slightly more logical. Or maybe even String::split, because you could consider #split to be in the namespace of String. I've even seen the…
Justin L.
  • 13,510
  • 5
  • 48
  • 83
1
2
3
23 24