programing habits

Custom Title Activated
Loyal Member
Joined
Nov 28, 2004
Messages
2,236
Reaction score
0
Well, this is a discussion thread.

I just wanted to ask coders how they write their code, etc.
(of any programing language)

First of all I found that experienced devs tries to void curly brackets.
I mean I find it more easy to read when the code is
PHP:
if ($something)
{
	if ($anything)
	{
		if ($whatsoever)
		{
			$var = "sumthing";
		**
		else
		{
			$var = "nothing1";
		**
	**
	else
	{
		$var = "nothing2";
	**
**
else
{
	$var = "nothing3";
**
not
PHP:
if ($something)
	if ($anything)
		if ($whatsoever)
			$var = "sumthing";
		else
			$var = "nothing1";
	else
		$var = "nothing2";
else
	$var = "nothing3";
even if the statement does 1 thing, but it's far more easier to read and to extend the clauses in the future.

Is there any reason for that? I mean maybe devs try to make the code compatible with legacy versions of particular language or so.. Or is it just personal preference?

The next thing is that I am quite criticized among my course mates in the univ. that I use long variables. But I found it quite helpful to make sense of vars with the scheme
$root_branch_attribute.
e.g.
PHP:
$server_css_body = "<link rel='stylesheet' href='body.css' />";
$server_css_global = "<link rel='stylesheet' href='global.css' />";
instead of using vars that does not make sense until you inspect all the code
PHP:
$css1 = "<link rel='stylesheet' href='body.css' />";
$css2 = "<link rel='stylesheet' href='global.css' />";

I would like to know what is your attitude towards such aspects of writing code?
 
I always prefer to use long var names since it is alot easier to remember when i come back to the next day, or a week or so when ive forgotten what it was.
And sometimes when im feeling lazy or sick, i will write code like the second example :P.
 
lol, I do things my own way.. so I have the habit of making code no one else can really understand well. Not to mention my bad var naming habits. As well as messy formatting. :)
 
I tend to prefer more compact code... I avoid blank lines unless necessary to delimit a block, use 1-space indent to minimise side-scrolling, and short identifiers (normally all lowercase). I find the blank lines a distraction... same with huge indents.

Example:
PHP:
if($something)
 if ($anything)
  if ($whatsoever) 
   $var = "sumthing"; 
  else 
   $var = "nothing1"; 
 else 
 $var = "nothing2"; 
else 
$var = "nothing3";
Second example:
PHP:
$scb = "<link rel='stylesheet' href='body.css' />"; 
$scg = "<link rel='stylesheet' href='global.css' />";
 
I like the long code, every step of the way, I always include all the brackets and stuff, and I don't always use long variable names, sometimes I just store them all in an array, when they're related of course. Makes everything so much easier.
 
Originally using the curly brace is for more than one line of code per block. If you have just 1 line you dont need to brace it. However some programming languages like lua just let you write everything anywhere regardless. (You could write everything on one line if you want....)
 
ssddss said:
Originally using the curly brace is for more than one line of code per block. If you have just 1 line you dont need to brace it. However some programming languages like lua just let you write everything anywhere regardless. (You could write everything on one line if you want....)


you can do that in any language...you think compilers/interpeters care about blank lines or spaces?

anyways

if i'm programing for my self i use rather criptyc variable names, i allways indent to make code blocks easyer to understand (normally i don't even need to ident ;P emacs does it)

if i'm programing for univ. projects or something else other then my use, i use easy to understand variable names.

in any case i allways include headers to functions saying what it does and how it does in a simple way (that is cause i'm an abstraction hoe) i don't really care much about how it does after making it, just what it does. so even if i use weird variable names it's easy to understand.

in regard to functions i like to use their returned values has boolean validation. i don't like to do something like

if blah == 1 then... i allways like to do if blah then ;P
 
Zajat said:
I do it straight down in notepad.


PHP:
if($something)
if ($anything)
if ($whatsoever)
$var = "sumthing";
else
$var = "nothing1";
else
$var = "nothing2";
else
$var = "nothing3";
that's what I was talking about...
unless the script is for personal use, cuz someone will have to indent it anyway ;)

of course, there are some who like to write a lot of statements/commands in one line, so that's even worse... :)
 
My brain had always been a complete mess.. that's why I prefer using long var names, or short significant names for my vars. I use the curly braces a lot, but only when it's necessary.

e.g.:
PHP:
if ($something) { 
    if ($anything) { 
       if ($whatsoever) $var = "sumthing"; 
       else $var = "nothing1"; 
    ** 
    else  $var = "nothing2"; 
** 
else $var = "nothing3";

I try to always indent my code, that's a big help when I forget to close some bracket and I have to check the entire code to find it :tp:
 
i use this program called notepad++

it helps me a lot with close and open brackets.. all i need to do is hilight a bracket ( close or open ) and the other bracket that is it suppose to be paired with will light up.. so that's basically a very good tool in recoding some of my old works or something
 
john_d said:
i use this program called notepad++

it helps me a lot with close and open brackets.. all i need to do is hilight a bracket ( close or open ) and the other bracket that is it suppose to be paired with will light up.. so that's basically a very good tool in recoding some of my old works or something
that's my favorite tool for any programing tasks
 
I always prefer to keep my code as neat as possible with indents..I don't leave alot of blank lines in the middle though.

Btw, john_d, if i'm not mistaken, the php plugin for MSVS has that feature as well, and I believe you can change the colors on that :P

[N]asser` ~ Out
 
[N]asser said:
I always prefer to keep my code as neat as possible with indents..I don't leave alot of blank lines in the middle though.

Btw, john_d, if i'm not mistaken, the php plugin for MSVS has that feature as well, and I believe you can change the colors on that :P

[N]asser` ~ Out
he was talking about notepad++...
it really lacks that feature... then usage of WYSIWYG editors for color picking would be really decreased for me..
 
[lexx] said:
he was talking about notepad++...
it really lacks that feature... then usage of WYSIWYG editors for color picking would be really decreased for me..
i have to go to other program to puts colors and stuff.. :p no worries though.. fireworks and photoshop always open on pc anyway.. hihih
 
Back