Code comments and execution time

I’m sure the Amish would agree - all progress is bad.

You are right about programming practices degrading - but it’s not a grand conspiracy. With more people doing programming, there’s going to be more bad programming done. That’s just life.

I don’t expect programming to straighten its act up until it has too - like when Moore’s law slams headfirst into the laws of physics and silicone lithography can’t get any smaller. Then the improvements will have to come in code or hardware structure. But right now the situation is that a programmer’s time is more expensive than the faster hardware.

But yeah, I’m amazed at what was pulled off in the old days. The Atari 2600 only has 128 BYTES of memory, and yet look at what was done. But that doesn’t make modern games and programs any less impressive. They’re just different.

I agree with you, but I should point out that this is actually a Backronym - it originally stood for Personal Home Pages Toolkit (PHP Toolkit) I think, this acronym came in a later version.

In fact MOST of what you listed are what I consider sloppy over-reliance on goofy tools that frankly often just get in my way… though if your color highlighting is worth a damn (and doesn’t break just because you put <!-- in your .php file like 99% of editors out there) it should pick up the difference between strings and operators/delimiters and color code them appropriately…

Firstly, [citation needed]? How many editors break? Lets do a poll to find out how many people find syntax highlitghting useful for productivity. I’m sure you are in a tiny minority.

My point was enclosing HTML in PHP strings will lose the HTML tag matching and highlighting. If you can’t see the benefit in being able to quickly find the start tag for an end tag, or letting the editor immediately tell you when you’re missing a </div> then you really are just stuck in your ways. Or are you perfect? Let me guess, you never make mistakes…

Though it could just be I’ve been at this stuff for WAY too long… part of why I said screw this and took some time away from “modern” to write a DOS game with a CGA equipped 128k IBM 5150 as the minimum target. Go back to when programming made sense and people actually took a little pride in their work instead of just sleazing it out any old way.

I see. Nostalgia is your argument here. Great, can we actually discuss things which have a practical benefit? And no, code formatting preferences are not practical.

But I’m 1TBS and find Allman/Whitesmith to be total illegible garbage too, and even want to backhand people for unnecessary spaces around operators. (making my eyes instantly think it’s multiple operations and not one).

I have no idea what this means. It’s a series of correctly-spelled English words and it parses as a grammatically correct sentence, but beyond that “it sounds like ********”.

It just annoys me to see so much of what’s called “progress” seem like massive steps backwards; the answer to said bad sleazy/lazy practices being to “just throw more hardware at it” or to just throw more layers of abstraction atop it – see X11, which if it didn’t suck so bad there would be no Motif, GTK, QT, etc, etc, etc…

If sending electric pulses to one another didn’t suck so bad there’d be no reason to use a CPU to process them. That silly level of abstraction is pointless isn’t it? Lets not get started on HTTP being layered on top of TCP/IP. We should just make it so web servers communicate directly with the NIC and tell it exactly what bits to send in what order, how to package and route them.

Seriously, I am starting to wonder whether you are just trolling. If as a programmer, you don’t see the benefits of abstraction, I think you’re in the wrong job.

This entire discussion has gone off course because PHP is NOT an interpreted language - it is a compiled language.

It isn’t comiled just once though with all subsequent accesses using the compiled version. It is compiled every time someone accesses the web page and the compiled version is run just for that one access and is then discarded with the script being compiled all over again when the page is next referenced.

This is known as a Just in Time compile process (or JIT).

You can tell that PHP is compiled and not interpreted because if there are any syntax errors in the code at all you get a syntax error message and none of the code gets run. If you consider an interpreted language such as JavaScript all of the code that can be run will be run up to the point where a syntax error occurs because the interpreter runs each statement separately before looking at the next.

Now the compile step is going to run longer in order to skip over the comments in the code but the run step following will not have any comments to skip over.

This will make a difference to the amount of impact that comment placement will have within the code. With an interpreted language such as JavaScript a comment inside a function or loop will need to be skipped over and slow down the processing each time that the function or loop runs and so moving the comment outside of the function or loop will speed up the processing. With PHP though while the comments will slow the compiler down they should all have the same effect regardless of where in the code that they are placed since the functions and loops will not be run until after the compiler finishes compiling the code and the version that actually gets run will not have any comments in it anywhere.

So while each comment you place in PHP will slow down the processing it will not make any difference where you put the comments and comments inside a loop that runs millions of times will have the same effect as if the comment were outside the loop rather than being treated as a million separate comments the way it would in an interpreted language.

Crimson, Notepad++, the M$ one for .net, gEdit… Of course since acid trip is one of the first things I turn off…

Which I don’t need because I know how to use the TAB and ENTER keys, and generally don’t have block level containers long enough for them not to line up on screen.

I do, that’s why I’m rabid about hitting enter, tab, or shift-tab, or letting the auto-deindent do it’s job.

Which just gets in the way when it’s in two separate functions, or two separate files… and practice the 76 column rule for code but not content.

No, but I do practice decade old tried and true methods for preventing me from making the simpler mistakes in the first place…

No offense, but spoken like someone not only over-reliant on their tools, but vomiting up code any old way. Lemme guess, classes on H1’s, style tags in the markup for static values like width:auto; vague/meaningless three letter classnames and presentational classes like “right”? PRobably have some nice pointless IE conditionals on a layout that shouldn’t even need real hacks to work properly all the way back to IE 5.x?

So… been programming all of six months to a year and never taken a single course or read a book on the subject? Or are the fundementals of elementary programming practices just not taught anymore?

Indent style - Wikipedia, the free encyclopedia

Abstraction isn’t pointless – abstraction without improvement or abstraction to avoid fixing something inherently wrong with what’s underneath IS. The latter of those among programmers it’s often called the “black box” syndrome – rather than fix something directly, you just treat the core as invoilate and slap something else on top of it to handle the problem… Which in engineering parlance is basically duct tape, spit and bailing wire. It’ll get the job done for a bit, but it usually comes back to bite you further down the road.

The former is just bloat for nothing – and is why Smarty to me is pointless; it offers no real improvements despite adding the overhead of an extra preprocessor atop a… preprocessor… I say much the same about jquery as I see no real improvements over just writing the code directly, and for the most part it’s useless bloat ruining just about every website it’s on from both a maintenance standpoint and from a user standpoint…

WRONG… and right… Wait, what? Lemme explain.

PHP does NOT compile to native machine language, the precompiler is to bytecode to run on a bytecode interpreter… so while it is “compiled” it is not TRULY compiled. Microsoft Gee-Whiz Basic did the same thing, we still call that an interpreted language! It may catch syntax errors before runtime; but that doesn’t mean it’s an actual compiled language. GW-Basic and most Microsoft ROM basics didn’t let you enter lines of code with syntax errors on them or load ASCII copies of programs that had syntax errors – nor did they store the code in memory as ASCII – did that make them compiled languages? OF COURSE NOT! Hell, on pretty much every ROM basic and soft-basic interpreter “syntax error” is a EDITOR message, not a runtime error.

The code still runs on an INTERPRETER instead of as MACHINE LANGUAGE. See the difference? It’s not like it runs it through GAS to make a executable binary.

It most certainly is NOT JIT compiled since the compile target is NOT machine language! It’s bytecode compiled – oh, and if you run a caching director like eAccellerator or APC, that bytecoded version of the page IS cached and not thrown away – assuming there’s room in the cache and it’s frequently accessed enough! (I like to provide 256 megs of space to APC, which is more than the bytecode version of every .php file on my server combined)

If we call PHP a compiled language, we’d have to call the BASIC interpreter on a ZX80 compiled, and that’s just silly… much akin to the people who call XML a “machine readable format” or XML based “languages” machine readable – Said people needing to go back and learn something about computers! If you have to run it through a parser to turn those integers from ascii into integers, reals from ascii into single,double or extended and strings into machine format null terminating or length prefixed strings, they’re NOT any more machine readable than C or Pascal code… or Assembly language source; until it’s turned into machine code or formats that the registers and opcodes can handle directly, it’s NOT “Machine readable”. Might be SOFTWARE readable…

Bottom line – compiling to bytecode to run on an INTERPRETER is NOT true compilation… and it sure as shine-ola isn’t JIT compilation in any sense of the term.

While everything Felgal says here is true - I still would consider PHP a hybrid. In my opinion, any language which has run time evaluation – an eval() statement – is almost certainly interpreted and can be called an ‘interpreted’ language because for all practical purposes it is.

Also, while simple parse errors are caught at the compile pass - symbol table mismatches, such as calls to non-existent functions aren’t caught until the line tries to actually execute. In this manner PHP behaves more like an interpreted language than a compiled one. Java after all also uses JIT compiling from the bytecode to the final executable, but it catches many errors at compile time PHP does not. Java also does not have any eval capacity.

Finally, as far as optimization goes, if APC cache or similar mechanism is present PHP can hold the bytecode between page requests and that code can persist for the lifetime of the cache, which has enormous returns in execution speed.

Crimson, Notepad++, the M$ one for .net, gEdit… Of course since acid trip is one of the first things I turn off…

So a few text editors? Not even real IDEs? Helpful.

I do, that’s why I’m rabid about hitting enter, tab, or shift-tab, or letting the auto-deindent do it’s job.

And when the start tag is more than a screen’s height above the end tag? When you have multiple tags at the same level? Tag matching is useful I don’t see how you’re arguing that it’s bad??

Which just gets in the way when it’s in two separate functions, or two separate files… and practice the 76 column rule for code but not content.

Don’t get me started on arbitrarily imposed “rules”…

No, but I do practice decade old tried and true methods for preventing me from making the simpler mistakes in the first place…

So you still make them. Wouldn’t it be better to detect them more easily?

No offense, but spoken like someone not only over-reliant on their tools, but vomiting up code any old way. Lemme guess, classes on H1’s, style tags in the markup for static values like width:auto; vague/meaningless three letter classnames and presentational classes like “right”? PRobably have some nice pointless IE conditionals on a layout that shouldn’t even need real hacks to work properly all the way back to IE 5.x?

Wow where did that come from? Now I know you’re just trolling. Nobody who actually wants a discussion jumps around topics this much, surely?

So… been programming all of six months to a year and never taken a single course or read a book on the subject? Or are the fundementals of elementary programming practices just not taught anymore?

Assumptions, very wrong too. I’m not going to list my academic qualifications because I refuse to be dragged into a pointless “mine is bigger” competition and stoop to your level of arrogance. However, feel free to read some of my posts in the PHP Application Design forum to get a feel for my knowledge in the subject. And as I recently said in another topic, experience on it’s own lends no weight to the validity of someone’s argument.

I was inferring that it was utterly meaningless in the context of the discussion especially as you were somehow trying to use it to back up a previous point. Why bring up indent styles when a) it’s down to personal preference and B) it’s completley irrelevant to the discussion at hand?

I’m 95% sure you can’t be serious and are just here for the sake of being argumentative.

r.je - Tom Butler on programming

I’ve seen far, far worse, but if the markup is that full of bad coding practices, not sure I want to see the PHP behind it.

Deadly serious. It’s why I’m pretty much through “working with others” on projects as I can’t put up with the “who cares” attitude of most up and coming developers.

Tu quoque.

Deadly serious. It’s why I’m pretty much through “working with others” on projects as I can’t put up with the “who cares” attitude of most up and coming developers.

I can see why people don’t like working with you.

This thread is discussing comments. Regardless of what the compile step outputs for PHP the comments will have already been stripped out. The overhead of having the comments only impacts on that compile step - what happens to it after that is the same as if the comments were not there at all.

This is totally different from a purely interpreted language where the comments need to be skipped over every time you get to one.

I agree that PHP is a hybrid but in so far as comments are concerned it behaves close to how compiled programs and nothing like interpreted ones.

Except that on first-run or if you aren’t running a caching accelerator that byte-code compile step happens whenever you call it. What you called the JIT still has to deal with it, even if the bytecode interpreter does not.

… and compilation is one of the slowest operations there is on a computer since its’ basically a lexical parser; even though bytecode is nowhere near as bad as an ACTUAL compiler, especially if we were to talk a multi-target one. See why APM and it’s kin offer such miraculous speedups – they allow you to skip the plaintext to bytecode step IF the program is still in the cache.

Which is why GW-B 4 was faster than 2.x – comments were stored outside the byte-code and interpolated in realtime by the editor and list functions – IF they were on their own line. NOT that 4 was around long enough to matter since quickBasic (an ACTUAL compiler) was released at almost the exact same time.

Which I can agree to IF you are running a caching program like APC and IF have already run the code once and IF it’s still in your cache and hasn’t been flushed by something else… That’s a lot of IF, and if none of those are true and it works as how you said in your post saying it’s not interpreted – instead of the comment taking time during bytecode interpretation it’s just taking time during compiling the source into bytecode…

Net change zero… though at least YES, there is relief in the form of eAccellerator, APC, etc, etc… It’s just not bulletproof relief.

Much of the time, comments are used because the code is not clear enough to explain what happens on its own.

The best way to resolve that problem is not to add comments, but to refactor the code so that it becomes clear enough to explain what is happening.

Can you tell that I’ve been reading the Clean Code book lately?

EXACTLY… and why I laugh whenever I hear the pathetic cop-outs of calling it “arbitrary formatting”, “wastefully long variable or function names” or “rigid rules that aren’t worth following” – 27 years later and I’m STILL quoting the catholic nun who taught me to do something more than hobbyist level ASM/Basic on that subject – “Vomiting up code any old way”

Off Topic:

(Funny that, a Jew taking coding lessons from a Catholic Nun. We get a protestant in there and we’d have a decent “walked into a bar” joke)

It’s also why I laugh and go “what are you thinking” whenever I see code like this:

// Go and get our next record
function ggi() {

If it was named something proper, like say “getNextRecord” it wouldn’t need the comment. Of course I REALLY love it when you point this out, and they say “oh, it’s less to type” … DUH… (because of course the comment is so much less text) It’s why I’m alway pointing people at that article on the IBM linux dev site.

Six ways to write more comprehensible code

But you’ll always have the people who ignore the better coding practices – their loss… and their clients loss… and the loss of whatever poor slob has to clean up their mess. JHVH forbid things like indenting styles, [url=http://en.wikipedia.org/wiki/Naming_convention_(programming)]naming conventions, [url=http://en.wikipedia.org/wiki/Style_guide]style guides or any of the dozen other methods for writing cleaner, clearer easier to maintain code be followed.

No, instead let’s rely on tools to handle all that when computers aren’t smart enough to do it; if they were we wouldn’t need programmers. Many of such tools (like say pretty print) having been invented NOT to clean up the code of competent programmers, but as a means for competent programmers to have a baseline to clean up code written by the inept.

Can’t say I’ve heard of that one, but it sounds good. Have to add that to my library.

You haven’t used vim I take it? : )

If you had spent hours dicking around on the command line, you’d have the functionality *typo! of the several clicks with one line. At least, that is what I propose : )

The problem with trying to teach people to use a command line, is that it involves a much hated aspect of learning, and that is that they have to remember things.

When using a mouse, they can be visually prompted along the way, which is a much lazier and slower way of doing things, but it’s easier than that remembering stuff that you have to do on the command line.

which is a much lazier and slower way of doing things, but it’s easier than that remembering stuff that you have to do on the command line.

Yeah, that’s why I forget all the cool vi commands I see on the golf course… I’m always like, oh I have to do X… I know I just saw a command to do that yesterday!
Luckily there are 30 other ways to do it… or I could even just use the mouse if I’m really under the weather : )

^ agrees with Stomme. I can type a few hundred characters in about the same time it takes me to take my hand off the keyboard, put my hand on the mouse, move the mouse, click the mouse, then reposition my hands on the keyboard.

As for the topic of this thread itself, I’m kind of on the fence.

I think that documentation is very important, especially for developers coming in that aren’t necessarily experienced with the project. If you’re coming in to a project with 10,000 lines of code, even if every line of code is written in a clearer-than-crystal way, it still takes time to wrap your head around how various things interact with each other.

At the same time, I also agree that if you have to write a few lines of comments to explain your few lines of code… there is something wrong with those few lines of code.

Now, as far as the performance of comments in code, I think they cause a minimal performance hit, at best. If I was on a real computer (and not on a laptop in a hotel in Vegas on business =p), I’d test this out. If this topic is still alive next week, I probably will. You could test this by writing two identical files, put a few hundred lines of comments in one, then include the files repeatedly by timing each one. Average the times and see if there is a statistically relevant time difference.

You’ll find that even when you get in to the extremes, such as several hundred lines of comments along with three lines of actual code, that performance testing shows an incredibly tiny difference of time that relates to this.

In reality, good comments more than outweigh the time it takes for the processor to ignore them.

Instead of focusing our personal attention on the minuscule impact of CPU time, our time may be more productively spent by focusing on the issue of writing good comments, or on improving code so that comments become less necessary.

I agree that code should be self documenting, good variable names etc, but this is all distracting from the original discussion of deathshadow’s claims that adding comments slows down the server too much - which is a load of rubbish!

Too much? I wanna see numbers for that kind of claim.