Re: Clean and clear code

From: Date: Sat, 28 Oct 2000 12:31:10 +0000
Subject: Re: Clean and clear code
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-22439@lists.php.net to get a copy of this message
Hi Siim! On Tue, 24 Oct 2000, Siim Einfeldt aka Itpunk wrote: > > I just discovered...or actually I`ve always known it, but now I saw it as > a problem for me, my codes are terrible. Right now I`m mainly talking > about the programming stuff like php, not so much about html...or..still > php&html together. I have quite much to do and sometimes even simple > things seem hard. My codes are terrible - indents, too few linebreaks, > etc. And the structure of all it is pretty bad as well. Hard to understand > where and what have been done. So if anyone knows any good sites that talk > longer about organizing/stuctructures/indents/etc, I`d like to see > them. Maybe there`s some courses or maybe someone has time and will to > write down a few pages him-/herself. I would appreciate it. Best starting point is to get some code from other programmers and take a look at the code. For example, take a peek into the PEAR. I for one like how it looks and is organized (javadoc influences as well.) Also, there are lots of coding guidelines : the GNU style, the Java Style de C++ (Qt for example) style. So on. Take a look at few of them, then choose one and stick to it. One good rule of readability is "be generous with spaces". instead of if($var=='foo') for($i=0;$i<$n;++$i){do_stuff($i,$var);} write: if ($var == 'foo') { for ($i = 0 ; $i < $n ; ++$i) { do_stuff ($i, $var); } } also use braces everywhere, even if you only have one statement, and think there's no use like in: if ($a == 'First') echo "first name"; else echo "n/a"; should be: if ($a == 'First') { echo "first name"; } else { echo "n/a"; } so on, so on. These written above are not at all most important nor relevant, just a simple example. Further more, there was a list of `PHP common pitfalls' or something written by somebody on this list. I hope to see it's way into the manual sooner or later, as there are lots of non-programming-bg ppl getting to code in PHP, and it can save lots of teared hair,and white nights :) > And second thing...if anyone knows javascript well, I`m still looking for > a code, which would: > * take the value of a input field before submitting the > form > * pass the value of it on with some link <form onSubmit="return onSubmitHook(this)"> with: function onSubmitHook(f) { var url="http://newpage.url/skript.php?name="+f.thename.value; top.win=window.open(url,'win',''); return true; } > Eg:<INPUT TYPE="text" name="thename"> > <a href="javascript:openwin()">Open</A> > I need to get the value of the input field to send it to a page,which will > be opened throught the javascript function openwin() (this just opens a > little window). BTW, I know JS is spicy but try to ask only PHP Qs on this list, to avoid grumbles ;) -- teodor

« previous php.general (#22439) next »