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
0
votes
0 answers

why use setup and draw functions?

I hope this isn't too abstract of a question, but I've been trying to figure this out when programming generative/interactive animations ( in many languages ) it's common to see the following structure: global variables a setup function a draw…
Nick Briz
  • 1,917
  • 3
  • 20
  • 34
0
votes
2 answers

ruby what is best way to condition: bar if foo vs foo and bar

what is the best way to check condition and run method in Ruby? which one is most readable? bar if foo or foo and bar
ajahongir
  • 469
  • 5
  • 11
0
votes
1 answer

What is the convention value for a Date to set as default?

I am parsing some json data that has a date element, and sometimes its value can be null. My application needs to be able to handle nulls, therefore I have to set the date value to a default value, so I am not sure if there is a convention / rule…
0
votes
2 answers

Reusable relationships

What is the best/standard way to create a relationship you can add to multiple dataobjects? using a DataExtension you can create a has_many like so public static $has_many = array('Links' => 'Link'); but then in the mirrored has_one relation in…
drawde83
  • 129
  • 2
  • 13
0
votes
2 answers

When is it right to use javascript over CSS3 and vice-versa?

I'm not trying to compare CSS3 features over Javascript,I'm trying to know how to decide when stuck on a situation like this. I know three ways to achieve a single interactive effect, in this example, When a user hover on a div, the inner element…
Pennf0lio
  • 3,888
  • 8
  • 46
  • 70
0
votes
1 answer

Why do so many programmers put curly braces on the same line as related keywords?

Note: I'm not sure if this is the right place for this. If another site suits this question better, please point me there. I was going to place it on cs.SE, but there was no tag about formatting, so I figured it didn't belong there, and this isn't…
Ky -
  • 30,724
  • 51
  • 192
  • 308
0
votes
2 answers

when should i initialize javascript properties?

I am new to javascript and I've been wondering about something. Is there an accepted way I should be listing my object properties? To be specific, I have been writing code where an object is created without any initial properties and adding them on…
jahmezz
  • 416
  • 1
  • 5
  • 15
0
votes
1 answer

CakePHP using foreign keys with different names as the associated primary keys

I set up more than one models, which i want to associate with a master-model like this: class CommonType extends AppModel { public $useDbConfig = 'common'; public $hasOne = array( 'CommonTypeDescription' => array( …
0
votes
2 answers

Any convention for "given an empty list return an empty list" when matching patterns?

When pattern matching a list, it seems common to return an empty list when given an empty list. We can match an empty list to Nil or List(), but we can return empty as Nil, List() or by returning the given list argument itself. What's the convention…
doughgle
  • 827
  • 1
  • 9
  • 18
0
votes
2 answers

Convention on breaking up large chunks of PHP code

I'm writing a database driven admin tool (really, its basically just a GUI to manage the db). I have quite a bit of PHP, most of it mixed in with pure HTML, in use and have started breaking everything up into much smaller pieces to increase…
0
votes
1 answer

MEF open generic problems with 4.5 convention api

MEF in .NET Framework 4.5 support generic types exports, it works in attribute way: [InheritedExport(typeof(Interface1<>))] public interface Interface1 { } public class Type1 : Interface1 { } The export object can be…
0
votes
3 answers

Should a property's value be calculated within a class or left to the caller?

Lets say I have an immutable class with a few properties, some of which can be calculated from with in the class, now, I could let the caller calculate the value of each property, or, I could let the class calculate each the properties itself. For…
Sam
  • 7,252
  • 16
  • 46
  • 65
0
votes
1 answer

Not declaring a loop counter up front in Fortran

As part of an assignment, I've been given (old) code for a FORTRAN program. I only have experience with C++ (and Oberon) and what knowledge I do have of Fortran, I've obtained through various (parts of) tutorials, which aren't always consistent with…
Wouter
  • 161
  • 1
  • 6
0
votes
1 answer

Why do so many people use me.projectname.main as package paths?

I have seen this so often and it confuses the hell out of me. I always title the packages directly after what they are. For example the path to my Main class is never "me.myproject.main.Main.class" but only "main.Main.class" and so far I have never…
Jonas Bartkowski
  • 357
  • 1
  • 6
  • 15
0
votes
0 answers

Using macro guards with file names that have underscores?

I was just wondering, I normally don't use underscores in files. I know that for "camelback" files (exampleHeader.h) you do EXAMPLEHEADER_H. Is it the same for file names with words separated by underscores? So example_header.h would still be…
user3062299
  • 55
  • 2
  • 5
  • 10