943,907 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Mar 22nd, 2007
1

Opinions? javascript/php/etc and programming standards

Expand Post »
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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. objDiv = document.getElementById( "thediv" );
or
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. $strName = $objUser->name();
but even examples on sun.com or php.net look like
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. o = document.getElementById("thediv");
or
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. $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?
Reputation Points: 17
Solved Threads: 0
Newbie Poster
chewbacca810 is offline Offline
17 posts
since Nov 2006
Mar 22nd, 2007
-1

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

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 4:40 pm.
Moderator
Featured Poster
Reputation Points: 1784
Solved Threads: 574
Moderator
jbennet is offline Offline
16,520 posts
since Apr 2005
Mar 22nd, 2007
0

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

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
Reputation Points: 17
Solved Threads: 0
Newbie Poster
chewbacca810 is offline Offline
17 posts
since Nov 2006
Mar 23rd, 2007
0

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

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 ;-)
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
rgtaylor is offline Offline
83 posts
since Mar 2007
Mar 23rd, 2007
0

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

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...
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
rgtaylor is offline Offline
83 posts
since Mar 2007
Mar 23rd, 2007
0

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

Click to Expand / Collapse  Quote originally posted by rgtaylor ...
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.

Click to Expand / Collapse  Quote originally posted by rgtaylor ...
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.

Click to Expand / Collapse  Quote originally posted by rgtaylor ...
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:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html><head><title><? somePHP( $a ); ?></title></head>
  2. <table attr=aleigjasie><tr><td>something</td><td>more something</td><td><? echo someMorePHP(); ?></td></tr></table></body></html>
... i am going insane ..
Reputation Points: 17
Solved Threads: 0
Newbie Poster
chewbacca810 is offline Offline
17 posts
since Nov 2006
Mar 23rd, 2007
0

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

Click to Expand / Collapse  Quote originally posted by rgtaylor ...
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
Reputation Points: 17
Solved Threads: 0
Newbie Poster
chewbacca810 is offline Offline
17 posts
since Nov 2006
Mar 24th, 2007
0

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

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...
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Mar 24th, 2007
0

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

Click to Expand / Collapse  Quote originally posted by rgtaylor ...
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.
Reputation Points: 17
Solved Threads: 0
Newbie Poster
chewbacca810 is offline Offline
17 posts
since Nov 2006
Mar 25th, 2007
0

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

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...
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
rgtaylor is offline Offline
83 posts
since Mar 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Right Align Option Element Text
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: javascript to play embedded applet!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC