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 374,025 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 2,888 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: 5356 | 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,937
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: 263
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: 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

  #5  
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: 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

  #6  
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

  #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: 611
Reputation: digital-ether will become famous soon enough digital-ether will become famous soon enough 
Rep Power: 5
Solved Threads: 38
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

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: Mar 2007
Posts: 17
Reputation: justinm is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
justinm justinm is offline Offline
Newbie Poster

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

  #9  
Mar 28th, 2007
Originally Posted by digital-ether View Post
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...


I absolutely agree with this.

I have worked in PHP now for several months, Java about a year, C++ a few months, and I have found that apart from the awful mess of HTML indenting (3 nested tables, and half ur working space is gaps ;x), that proper indentation, casting, variable types, indentation and uses of classes is critical to the further enhancement of software development projects.

It is critical that when software is designed, it is not designed using short sightedness of a sole programmer who's coding standard and structure is a royal mess.
As I myself having taken a PHP development position (my first actually ), I have come to realisation, first of all which I already believed, that proper code flow, structure and indentation is at the outmost, critical for reusability, improvement and modification in time.
On top of that, proper documentation is vital, it cannot be said enough how important having documentation of a system is.

Modular programming practises imo, should be enforced in every teaching institution as a first programming method, and stress its importance. Each individual will develop their own methods and structures, but it is critical in team environments, and open source, that the same structure, and declarations etc. be consistent, the same throughout and properly documented/commented.

I myself am only 21, but I do know a thing or two about working in projects with other coders/developers/designers who can't design or code cleanly.
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

  #10  
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  
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:33 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC