 |
|
|
|
12-26-2007, 11:34 PM
|
Why ;?
|
Posts: 322
|
This doesnt really relate to anything Im just curious.
Why does php still use ';'? It seems slightly archaic. Is it really necessary? Does it work faster having that at the end of each line as opposed to the server having to figure out when the line is up? Or is it more to keep in line with C and the ways people are use to programming.
Again, not complaining, just curious.
|
|
|
|
12-27-2007, 03:15 AM
|
Re: Why ;?
|
Posts: 238
Location: United States
|
I think it's just one of those things where the language started with using line-ending semi-colons since it was originally inspired by C and Perl. At this point it would be too dramatic of a change to remove.
|
|
|
|
12-27-2007, 03:19 AM
|
Re: Why ;?
|
Posts: 310
|
I think it is required if you want to allow a single statement to span multiple lines, otherwise we would have ambiguous cases just like javascript.
|
|
|
|
12-27-2007, 07:52 AM
|
Re: Why ;?
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
I don't see why it bothers you?
PHP as this syntax, others too.
Python doesn't, and use indentation to separate blocks, rather than { and }
plsql require the ; at the end, and to declare every variables, their types and their capacity before you use them, like c.
Different languages, different constraints.
Personally, I like the way PHP put constraints. Enough to not have something too messy, but not too much to still being easy.
In my memory, perl and visual basic are the most messy codes to read.
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
12-27-2007, 08:14 AM
|
Re: Why ;?
|
Posts: 843
Name: Mike
Location: United Kingdom
|
Quote:
Originally Posted by frost
I think it's just one of those things where the language started with using line-ending semi-colons since it was originally inspired by C and Perl. At this point it would be too dramatic of a change to remove.
|
I think frost has it about right. Personally I think I would get confused if it was done by lines.
__________________
My Blog/Site: Please login or register to view this content. Registration is FREE
|
|
|
|
12-27-2007, 09:14 AM
|
Re: Why ;?
|
Posts: 6,521
Name: Dan
Location: Swindon
|
i agree, PHP is my only real programming languagae,i have a little experience of VB and it does look confusing sometimes
it all comes down to coding styles, and how the authorer prefers to read and write code,
i absolutly HATE it when people use indentations.
and for if/else statments and things hate it when i see:
PHP Code:
if(Condition) { echo 'TEXZT' } else { echo 'text' }
i find it so messy and annouying!
i much prefer it when its spread out a little:
PHP Code:
if(condition) { echo "text"; } else { echo "vfd"; }
and the ; are helpful for finding when functions and "actions" etc end.
anyway i like em i just wish php could easily be used to make desktop apps!
Dan
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|
|
|
|
12-27-2007, 09:45 AM
|
Re: Why ;?
|
Posts: 6,442
Name: James
Location: In the ocean.
|
I like the semicolon as a statement terminator.
I will disagree with Dan, I can't stand it when people don't indent their code. With indentation, it is so much easier to find where blocks and sections begin and end.
|
|
|
|
12-27-2007, 10:57 AM
|
Re: Why ;?
|
Posts: 6,521
Name: Dan
Location: Swindon
|
it depends, it just annouying me when i see it when you have like
CODE
CODE
Code
when its huge and you have to scrol veritcally i have nothing gainst small or reaosnable indentations in code, its just when its uge and messy i hate it 
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|
|
|
|
12-27-2007, 11:04 AM
|
Re: Why ;?
|
Posts: 807
Name: Mattias Nordahl
Location: Sweden
|
I also disagree with Dan. This
PHP Code:
if(condition) { if(condition) { if(condition) { some code here... } else { something else } } } else { if(condition) { some code here... } }
is much easier to read than this
PHP Code:
if(condition) { if(condition) { if(condition) { some code here... } else { something else } } } else { if(condition) { some code here... } }
And semi colons are great! 
|
|
|
|
12-27-2007, 11:10 AM
|
Re: Why ;?
|
Posts: 6,442
Name: James
Location: In the ocean.
|
Quote:
Originally Posted by dansgalaxy
it depends, it just annouying me when i see it when you have like
CODE
CODE
Code
when its huge and you have to scrol veritcally i have nothing gainst small or reaosnable indentations in code, its just when its uge and messy i hate it 
|
I use 4 spaces of indentation. I can't stand to look at code with at least 8 and one section ends up starting on the right side of the screen. Too much indentation is unreadable and can be just as bad as none.
|
|
|
|
12-27-2007, 11:43 AM
|
Re: Why ;?
|
Posts: 6,521
Name: Dan
Location: Swindon
|
^ Thats what i ment...
btw i didnt mean the code thing to be like that the middle one was suposed to have a ton of spaces
@ lizciz
i sort of agree but i think i would still prefer it all right align but with line breaks between each statment,
its just my pref i find your first example messy.
Also i tend to add comments to tell myslef (and others) what the curly brackets are closing if i have a few.
so i would have // END for IF CONDITION jsut makes it easier to line up and when i have too many or not enought closing brackets to track down the offending one!
WOOT GO COMMENTS!! scripts dont have enough of them!
Dan
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
Last edited by dansgalaxy; 12-27-2007 at 11:45 AM..
|
|
|
|
12-27-2007, 01:23 PM
|
Re: Why ;?
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
Quote:
|
Also i tend to add comments to tell myslef (and others) what the curly brackets are closing if i have a few.
|
I agree for that.
Especially when you have several if or case stuffed inside loops, in that case, both the indentation and the end-curl brace comments are useful.
And as for the indentation part, I keep it on 2 spaces (real spaces, not tabs).
I found that 4 are usually too much. You end up needing a 22" wide screen to display everything without line breaks...
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
12-27-2007, 01:34 PM
|
Re: Why ;?
|
Posts: 6,521
Name: Dan
Location: Swindon
|
^ DITTO!
Lol
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|
|
|
|
12-28-2007, 02:49 AM
|
Re: Why ;?
|
Posts: 807
Name: Mattias Nordahl
Location: Sweden
|
Thru some programming courses etc. in school (not php actually, but I figured it should be the same) I've learned that lines should be 70-80 letters wide, for a good readability. So you don't really need a big screen, just keep the lines short. Make use of the semi colon :P
I also agree about commenting your own code, where itis nessesarry. That is, where it can make understanding the code easier.
And I use 4 spaces for indention btw.
|
|
|
|
12-28-2007, 03:26 PM
|
Re: Why ;?
|
Posts: 843
Name: Mike
Location: United Kingdom
|
Commenting is useful as it reminds you of what your doing (Useful if you code while drunk/tried/high like me) the next day. I'm more of a functions based person mind (like if something is used more than once, make it a function).
I never really care about line length, Dreamweaver automatically makes the code fit my screen (and tells me where the line ends).
Laying out code nicely is really useful (*Rogem tells you coding nightmare storys*). Though if I'm selling the code to someone I do not trust I may make the code nasty to read, with no comments...But not generally.
__________________
My Blog/Site: Please login or register to view this content. Registration is FREE
|
|
|
|
12-28-2007, 03:59 PM
|
Re: Why ;?
|
Posts: 6,442
Name: James
Location: In the ocean.
|
Quote:
Originally Posted by rogem002
Laying out code nicely is really useful (*Rogem tells you coding nightmare storys*). Though if I'm selling the code to someone I do not trust I may make the code nasty to read, with no comments...But not generally.
|
Hehe. Here is my name in perl
Code:
''=~('(?{'.('-[@@^]'^'])).*}').'"'.('*]-__}'^'`<@:,_').',$/})')
I love unreadable code 
|
|
|
|
12-28-2007, 04:35 PM
|
Re: Why ;?
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
Quote:
Originally Posted by joder
Hehe. Here is my name in perl
Code:
''=~('(?{'.('-[@@^]'^'])).*}').'"'.('*]-__}'^'`<@:,_').',$/})')
|
You see why I stated that perl was messy by design !?
When I see something like that, I feel the urge to shoot someone....
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
12-28-2007, 05:01 PM
|
Re: Why ;?
|
Posts: 6,521
Name: Dan
Location: Swindon
|
just a question why the hell do you need to write something using symbols like that?
i mean why is it needed?
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|
|
|
|
12-28-2007, 07:44 PM
|
Re: Why ;?
|
Posts: 807
Name: Mattias Nordahl
Location: Sweden
|
While we're speaking of messy, unreadable and non understandable code, have you guys ever heard of brain****? It is a programming language consisting of only 8 commands and characters (every command is 1 character).
http://en.wikipedia.org/wiki/Brain****
Theres just one question to ask; Why!?
|
|
|
|
12-28-2007, 11:26 PM
|
Re: Why ;?
|
Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
|
Quote:
PHP Code:
if(condition) { if(condition) { if(condition) { some code here... } else { something else } } } else { if(condition) { some code here... } }
|
Is how I write all of my code. I don't worry about line length qua line length because I use Crimson Editor which wraps things nicely and allows me to jump back and forth between an opening and closing brace. I focus on line length where readability may be an issue. For example,
PHP Code:
$my_array = array ("first_index" => "first_value", "second_index" => "second_value", "third_index" => "third_value", "fourth_index" => "fourth_value" );
is much more readable than
PHP Code:
$my_array = array ("first_index" => "first_value","second_index" => "second_value","third_index" => "third_value","fourth_index" => "fourth_value");
I only indent by 2 spaces because that's all I need to be able to see that an indentation exists and tabs cause problems when I move between systems. Not indenting is something that drives me insane when I come across it.
I prefer the above quoted style of curly brace placement because I can immediately see that the closing brace closes a specific if condition making comments indicating closure unnecessary whereas it is not as immediately obvious if the curly brace is just hanging there on its own line. For example, check this code out:
PHP Code:
if ($boolean_condition) echo "Yes!"; { echo "I get here no matter what!"; }
Rather silly to use the extra braces, I admit, but I have seen scenarios where something like that arises by way of accident and debugging is confusing when you're sifting through a 2,000 line script. That is also why I never use conditionals without their curly braces.
I sometime wonder if some coders put curly braces on a newline just to brag about the number of lines of code they write (that short 14 lines of code in the quote above grows 50% to 21 lines when the extra newlines are added). I'm sure that's not everyone's reason for doing that, but I wonder...
I rarely add comments. Instead, I write variable names and functions so that I know what they're doing and I use camel case for functions & class names and use underscores in variable names for quick identification. I'll add copious comments where the logic may not be immediately easy to follow (e.g. when I go mathematical) or when using the ternary operator in a confusing fashion. I like Rogem's signature as an example of well-named variables & functions.
Semicolons are something I've learned to appreciate -- I did not at first. I now see them like the period at the end of a sentence -- most of the time I know it's the end of the sentence, but a clear indicator makes reading it go faster.
I think the most important point here is that everyone in this thread hasn't just left decent formatting to the academics! I see way too many kids get out of college and forego formatting because of a lack of appreciation (or sheer rebellion against a professor who had decided that his/her way was the way). I'd say that so long as you put thought into your formatting, develop a style that is easy for you to work with and not impossible for others to work within, and are consistent in your implementation then you are on your way to becoming an author of beautiful code. One should also be a sufficiently competent coder that many different styles may be read with a fair degree of ease as you will undoubtedly find yourself reading many different styles of code throughout your career.
One thing, though: don't expect regular expressions to be easily readable until you've got quite a few of them under your belt. Their purpose is function, not readability.
__________________
Jeremy Miller
Please login or register to view this content. Registration is FREE
|
|
|
|
|
« Reply to Why ;?
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|