User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 362,352 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,802 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 5188 | Replies: 35
Reply
Join Date: Nov 2006
Posts: 17
Reputation: chewbacca810 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
chewbacca810 chewbacca810 is offline Offline
Newbie Poster

Question Opinions? javascript/php/etc and programming standards

  #1  
Mar 22nd, 2007
i having been programming for 10+ years now, so I always try to adhere to good programming practices (variable naming, spacing, etc). Yet, almost every snippet of code for JS or PHP that you can pull up goes against those practices.

even when writing JS or PHP, where var type isn't nearly as strict as, say, Java, I'll write:
objDiv = document.getElementById( "thediv" );
or
$strName = $objUser->name();

but even examples on sun.com or php.net look like
 o = document.getElementById("thediv");
or
$name = $user->name();

I understand they're both scripting languages, but I don't feel that is any reason to deviate from good programming practices.

Anyone else feel this way still, or has the whole world gone insane and I'm just wasting precious keystrokes?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2005
Location: Old Hampshire, Old England (LOL)
Posts: 11,938
Reputation: jbennet is a jewel in the rough jbennet is a jewel in the rough jbennet is a jewel in the rough jbennet is a jewel in the rough 
Rep Power: 30
Solved Threads: 261
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Microsoft Fanboy

Re: Opinions? javascript/php/etc and programming standards

  #2  
Mar 22nd, 2007
it annoys me how some same code has some named like varBstr

i make my own coding paractises. Indenting annyoys me apart from when using IF / Case statements so i just leave a line

e.g my style of html

<html>

<head>
<title> "hello" </title>
</head>

<body>

<hr>

<?php
(Some PHP Code)
?>

</body>

</html>
Last edited by jbennet : Mar 22nd, 2007 at 3:40 pm.
TRY MY SUGGESTIONS AT YOUR OWN RISK!
james.bennet1@ntlworld.com
Reply With Quote  
Join Date: Nov 2006
Posts: 17
Reputation: chewbacca810 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
chewbacca810 chewbacca810 is offline Offline
Newbie Poster

Re: Opinions? javascript/php/etc and programming standards

  #3  
Mar 22nd, 2007
do you/have you programmed in languages like c/java/etc, or mostly just scripting languages?

and agreed, indenting html is a pain. i don't indent all of my tags, but i do for the majority, trying to figure out where something is nested is a pain/waste of time when dealing with huge projects
Reply With Quote  
Join Date: Mar 2007
Posts: 83
Reputation: rgtaylor is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
rgtaylor rgtaylor is offline Offline
Junior Poster in Training

Re: Opinions? javascript/php/etc and programming standards

  #4  
Mar 23rd, 2007
OK, I have been programming for near 30 years. I have touched every major programming language in those 30 years. Actually it is 27 years but near enough to 30 for this discussion...

Good coding practices are not written in stone, they have evolved over the years, changing as frequently as the programming langauges...

The fact is, what you consider "good" is considered "bad" by some people... as to whether you are wasting keystrokes, the question must be answered with a question, "do you work mostly solo or mostly in a team?" In a team, it is important to have a common programming style so that everyone can easily adapt to code snippets written be others in the team... When working alone, YES you are wasting keystrokes... unless you can't remember that "name" should be a string and not an int or a boolean...

I am not trying to berate you or your complaint, I have MANY issues online code samples...people are too lazy to do them right in many ways, but I think it is too general to say your way is "good" or "right" and someone else's is "bad" or "wrong"...


I suggest you learnto be more flexible, and just understand that one size does not fit all...

Incidentally, I hate touching html code that is not properly indented... but I ain't get steamed up at you guys ;-)
Reply With Quote  
Join Date: Mar 2007
Posts: 83
Reputation: rgtaylor is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
rgtaylor rgtaylor is offline Offline
Junior Poster in Training

Re: Opinions? javascript/php/etc and programming standards

  #5  
Mar 23rd, 2007
By the way, there is a valid argument in html code to loose the indents.... each return, space, tab, etc. is added bytes to send over the network... but to take that to the extreme, we would have an entire html page as one long line of text without any supurfluous characters...
Reply With Quote  
Join Date: Nov 2006
Posts: 17
Reputation: chewbacca810 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
chewbacca810 chewbacca810 is offline Offline
Newbie Poster

Re: Opinions? javascript/php/etc and programming standards

  #6  
Mar 23rd, 2007
Originally Posted by rgtaylor View Post
In a team, it is important to have a common programming style so that everyone can easily adapt to code snippets written be others in the team...

my position is coming from a programmers mindset, but, more importantly, an open source mindset. i always try to make code modular, and so, with that, it has to be readable. even with js i'll stick to the same naming conventions as i do in java/etc, so that I (or someone else) knows the arg for a function is an string/int/whatever just by looking at the name.

Originally Posted by rgtaylor View Post
I suggest you learnto be more flexible, and just understand that one size does not fit all...

it just confuses me that these simple principles are discarded even with languages like php, and php is a very complex scripting language.

Originally Posted by rgtaylor View Post
Incidentally, I hate touching html code that is not properly indented... but I ain't get steamed up at you guys ;-)

i feel there comes a point where html indenting is borderline insane. working in a table cell nested in a table (plus some php in there) and you're looking at 8+ tabs. I try to tab to the point that you can determine the layout by looking at it. right now i am going through 1000s of lines of code that look like:

<html><head><title><? somePHP( $a ); ?></title></head>
<table attr=aleigjasie><tr><td>something</td><td>more something</td><td><? echo someMorePHP(); ?></td></tr></table></body></html>

... i am going insane ..
Reply With Quote  
Join Date: Nov 2006
Posts: 17
Reputation: chewbacca810 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
chewbacca810 chewbacca810 is offline Offline
Newbie Poster

Re: Opinions? javascript/php/etc and programming standards

  #7  
Mar 23rd, 2007
Originally Posted by rgtaylor View Post
By the way, there is a valid argument in html code to loose the indents.... each return, space, tab, etc. is added bytes to send over the network...


i'd hate to work for the manager that enforced a no whitespace rule to save on bandwidth
Reply With Quote  
Join Date: Sep 2005
Posts: 591
Reputation: digital-ether will become famous soon enough digital-ether will become famous soon enough 
Rep Power: 5
Solved Threads: 37
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Posting Pro

Help Re: Opinions? javascript/php/etc and programming standards

  #8  
Mar 24th, 2007
Originally Posted by chewbacca810 View Post
i'd hate to work for the manager that enforced a no whitespace rule to save on bandwidth


I'd still indent all my code and include as much whitespace as I could. Then I'd have the server buffer HTTP output and remove all indents and whitespace. The manager will never know.. :cheesy:

I've used mostly PHP and JavaScript (4 years) which are not strict with their variable types.

I think the focus should be more on keeping your variable scope within a range where you can keep track of variable types? It tends to force you to be more OOP I think..
If you're the only one looking at the code, you can have a very wide scope and not care, but when someone else will work on it, it should be more modular..

Some IDE's understand the code you write better and give code hints when you put in variable types in their names - I like to use that when scripting some language I'm not familiar with... like actionscript..

One thing I've learned is that the more you obsess - the less work you actually achieve. Lol...
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote  
Join Date: Nov 2006
Posts: 17
Reputation: chewbacca810 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
chewbacca810 chewbacca810 is offline Offline
Newbie Poster

Re: Opinions? javascript/php/etc and programming standards

  #9  
Mar 24th, 2007
Originally Posted by rgtaylor View Post
By the way, there is a valid argument in html code to loose the indents.... each return, space, tab, etc. is added bytes to send over the network... but to take that to the extreme, we would have an entire html page as one long line of text without any supurfluous characters...

also, in the case of js, it will stop (sane) programmers from reusing your scripts. just look at the google maps api . kudos to anyone outside of google that can follow that.
Reply With Quote  
Join Date: Mar 2007
Posts: 83
Reputation: rgtaylor is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
rgtaylor rgtaylor is offline Offline
Junior Poster in Training

Re: Opinions? javascript/php/etc and programming standards

  #10  
Mar 25th, 2007
Well, looks my comments struck a few nerves. First, I want to say, that I worked on a very bandwidth sensitive project, and I wrote the code, then ran it through a filter which I made too, the filder just removed the superfluous whitespace and made the html 1 long line of code...the scripts too... but, again that was just an EXTREME example...

The problem with html indentation is NOT the indents, it the misuse of tables to control layout.

First, tables should never be used for anything other than tabular data, though I will admit there are times when a quick table to format a small area may be helpful and fast... I won't banter anyone for taking that way out... BUT since most "web developers" are really just macromedia "users" they don't really count as "developers" in my book... At least this is the situation in Japan, where I live and work...

Macromedia can be set to use tables or CSS to control layout, tables is the default... the problem with using macromedia is that it does NOT create clean code, so a developer needs to manually edit the code later... this can be rediculously time consumming... I would just rather recommend using a design tool to prototype a page or site and then doing the right way, yourself...

If people learned good coding habits, as you mention, I believe it must include design concepts as well, not just variable naming and code indentation...

I indent ALL my code, C, C++, vba, js, html, java, perl etc. I just make OOP easier to understand... things indented are "contained" within something else.... this is also a visual indication of scope, as mentioned above, and was the whole reason people started indenting in the first place...

When linear code predominated, no indentation was used, no one even thought of it... But we had line numbers to content with ....

<code>
10 ? rgtaylor rocks!
20 goto 10
</code>

Then we started to see OOP concepts, this made larger project MUCH easier, but it introduced scope, which didn't really exist in linear programing...

<code>
function rgtaylorMess(strMess){
document.write(strMess);
}

while(true){
rgtaylorMess("rgtaylor rocks! ");
}
</code>

Then as OOP matured we saw programming styles catchup to the design concepts, which were all about making the code easier to read and understand, since larger projects meant, usually, more people in a collaborative effort...

I am sure you all know and understand these concepts, but it just makes the current discuss have more meaning... thus my comments previously... If you are working alone or in small groups, you should be able to be more flexible, because not everyone codes the same way, and to suggest 1 way is right is simply arogant..

I live in Japan, where the physical similarities have led the culture, government and society in general to "act" like everyone is the same... not equal... just the same... So people with special needs, like handicap and mentally challenged are complete ignored in law and social services, etc. Schools teach to the lowest level of student ability, because to have basic, intermediate and advanced level course curriculum would mean admitting that some students are better at math, science, reading, etc. than others...

Japan, despite what people in the West generally think, has a horrible education system and the heart of the problem is their attitude that "one size fits all"... in all things...

I don't think the programming world would be a better place if we start trying to act similarly...
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 11:24 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC