ID:1042396
 
Keywords: dm, oop, php
Hey guys,
Last week i decided to get off my lazy butt and use my free time to learn PHP.(which in itself is quite the achievement XP).

So i went to the public library and checked out this book called "PHP 5 , everything you need to know". Looks good enough.

Now i promised myself i wont jump through chapters just because im a little bit familiar with DM and they seem to have many similarites due to being OOP's(or im just wrong and its due to a different reason xD), Although im happy i started with BYOND because many of the early chapters were very easy to understand thanks to what i learned about DM.

and now to the real issue, just finished the chapter about loops when i realized none of the loops in php need sleeping( i mean the proc we use to sleep() so loops wont crash).
Why is that and frankly how REALLY are the two similar/different. Im quite interested to know.

Sorry for rambling and for any claim i may have made without proper understanding , but then again, thats how you learn right? :)
A while() in PHP can crash :)
You don't need to pace a loop in PHP, because everything you code shouldn't run for a very long time. Unlike DM, you shouldn't really run infinite loops in PHP. The loops you'll code are likely -supposed- to finish as fast as possible, so pacing them would slow down the webpage a lot. Imagine looping through posts on a page and outputting them in the form of a post template, and using sleep(1). That would take an entire second to finish 10 posts. Try to load 50 posts, and thats 5 seconds.. -just- for posts. Not counting all the other stuff going on for the webpage.

In DM, you don't need to use sleep() either, as long as your loops aren't infinite, nor do they run for extended periods which would hog up the CPU.

In summary, PHP doesn't pace loops because they're designed to run and finish ASAP.
Umm i see your point Kitsueki, that would be a pain...

well thanks for both of you for the enlightenment :)


p.s.: Who is the idiot that thought putting ; after every god damn line was a good idea???, every time i find out that my script isnt working just because of that after debugging the damn thing for 30 minutes i feel like setting a box of kittens on fire.
Semicolon allows compiler to parse code more easily, as well as allowing multi-line statements.
In response to Gi Money
It can be the difference between
$var1 = "blah"; $var2 = "blah"; $var3 = "blah";

and...

$var1 = "blah"
$var2 = "blah"
$var3 = "blah"


The first allows you to put multiple things on one line, so there isn't such a heavy scroll through the code.
Everything happens one tick at a time. In an infinite loop without sleep, it will use one tick to try to"complete" itself. This causes the game to freeze because other procedures are either done for the tick or can't be reached.
In response to Kitsueki
Although DM can use semicolons and curly brackets, they really only make code look dirty to me. I like having more whitespace, because it makes code look more like writing than putting sets of symbols together.
//  I'd get rid of this slash if I could.
// the one after "proc"
proc/say_hello()
var message = "Hello, world!"
world << message

// vs

proc {
sayHello() {
var/message="Hello, world!";
world<<message;
}
}
In response to Kaiochao
I agree, I love that DM doesn't force us to use curly brackets nor semicolons. I do like shoving simple assignments into one line if I can though, so I don't have to scroll so much to see everything.

I'm all for whitespace, aside from that. Readability is a must.
The off-side rule is mostly about readability, hence it's usually favoured among web-languages that need to be a bit more "non-technical" user facing, or focus on how easy or not they are to pick up in an afternoon. The semi-colon syntax is mostly about ease of compilation, it's just a lot easier to make a lexer / parser where "lines" are terminated by something, and give people flexibility in terms of their own whitespace use.
Hey thanks to everybody for taking an interest in my education :P, and I agree with what some of you said, I understand the apparent need of the evil ; but thank god byond doesnt force us to use it :).