- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Looks like it's cool again to bash PHP.
First of all, PHP should be used for webpages, and cronjobs related to webpages. That's about it.
Now then, please do suggest a good alternative to PHP that:
So now that we've ruled out the fanboy languages and ASP(.NET), what's left?
For the love of programming, I'd expect people on here to have a brain once in a while and not jump on the first bandwagon they see.
Admin
Wide support is a non-issue for this WTF. They were running a customized PHP with a customized HTTP server on the local machine.
Because of that, I would suggest Perl, Ruby, Python, or Lua. Hell, even C++ if the object oriented speed is absolutely essential.
Admin
Actually, I'm not a PHP-basher, and I would even take some exception to your restrictions above, having found PHP to be quite robust at doing simple systems programming... for example, running a socket daemon for an IPC protocol (not meant for scalability, only for a handful of processes to interact), and other such fun stuff.
Yes, I hear the gasps but the fact is it worked, and worked quite well, so stuff it. Basically, I just treated PHP like a scripting-language version of C and it worked.
PHP isn't bad as long as you A) don't program Java in PHP, B) keep it simple (see A), and don't try to be clever or cute with your programs (see A and B).
Admin
double post
Admin
Well Perl does that job just fine. I don't know the speed of Perl versus PHP (no PHP experience), but on all the other counts it does fit the bill.
Yours Yazeran
Plan: To go to Mars one day with a hammer
Admin
Let me guess, Promise SX**** ?
Admin
I like it - slag on someone for hating php. Seriously, it's you who has the problem; php is godawful, has little consistency, and is generally useful only because it's easy to use. It's the VB of the web world. But I guess you can't deal with someone pointing out the flaws of your baby.
Admin
But I use VB in the web world too, I like PHP also and C# and Perl and Python and C and C++ and Java etc...I like programming..why bash at all??
Admin
Perl, Ruby, and Python are well within the same performance range as PHP, and would require pretty much the same sort of solution (ignoring the specific idiocy of the PHP code quoted above). Actually, Ruby is considerably slower than PHP.
The question of running an HTTP server with then CGI, thus re-starting the scripting environment for each refresh (THUS re-invoking every system call you just made) makes the whole thing a joke, no matter what scripting language you use. Lua alone might be a winner here just because of its small start-up footprint.
More to the point, as I was saying, the overall architecture is the problem. Lua would solve this nicely if you just installed Kepler, thus having an HTTP daemon running continuously, with no need for external server or CGI. But even lighttpd with PHP running as a module would be much preferable to HTTP/CGI/Python, for example.
Admin
I'd say use java, ruby, or python. I don't really see the appeal of straight perl if php is out.
Admin
While I agree that VB and PHP are different languages they have 2 things in common:
PS. VB is kind of cross-platform. There is gambas and mono-basic.
Admin
I like it - slag on someone for liking php. Seriously....
That argument can go both ways, you know.
You can write bad code in any language. PHP has some flaws that make it easier to write bad code in it but it's still possible to write perfectly functioning, fast, code in PHP. You are free to insert your favorite language in place of PHP in this comment.
Admin
I love love LOVE the part where they unset() a global variable ($new_str), then start building a string with the same variable (now in the function's scope) and then return it. Or maybe it was never global. It just shows a lack of basic programming comprehension :(
Admin
You use VB6? I guess that would make VB the VB of the web world, along with PHP. VB.Net is a bit different, enough so that VB programmers were fairly unhappy with the switch.
As an addendum to my last comment, I'd write the raid i/f as a persistent process that accepted tcp connections from localhost or updated a text file as the situation required; all depends on the actual use case, but I bet it'd get rid of some of the slowness and overall braindamage.
Admin
I'm slagging on OG for his kneejerk reaction - I don't care if he likes php or not. if he does, he should be familiar with the warts.
anyone can write bad code in any language, but PHP makes it really easy.
Admin
PHP installed as an Apache module is really fast, and that's what you'll get with any stock server nowadays. Add one module, APC, which caches your compiled scripts, and you have an insanely fast site environment.
We all know that PHP shouldn't be used for devices, or desktops, or (insert-non-server enviroment here).
It started out as "Personal HomePage." It's obvious. It's for websites. And if you use it right, it's REALLY GOOD for them. It's a lot faster than any RoR or Java or .NET setup you can get, and it's a heck of a lot easier to setup than Python or Perl, where the speed is comparable.
But those of us who use it professionally don't need to defend it; we don't code to be trendy. We also don't mind that script kiddies make the language look bad. We just keep doing what we do.
Admin
What do you mean by 'slow'? For example GC in theory slows down programs. But since programers don't have to worry to track leaks (except logicall leaks) they have more time to optimalisation. In many cases caching can speed up the whole process and/or speed little matters (compared to transfers).
What do you mean 'widely'? Nearly all of languages (python, ruby, perl...) has it's own active community grouped around newsgroup or irc channel.
In short of long run?
Nearly all (except initial treining).
Nearly all
Admin
No, it is not a global. In PHP you need to define globals inside the function or the variable is local. Ergo, what they are doing is just plain idiotic: unsetting a variable that does not yet exist.
Maybe they thought it had something to do with concurrency, but that betrays an abysmal ignorance of PHP.
Admin
I for one, like PHP for small projects and budget-strapped web applications; if you're good enough you can even do MVC on PHP. But for beefier stuff, I will tend to jump into Java with its EE framework; it does a good job on managing DB transactions without much hassle.
Admin
Is it only me or does this feel like a re-run? I could have sworn that i have read about a raid controller that abuses exec and uses php a lot already.
Admin
Because bash is a much nicer scripting language than all the other ones.
Admin
If I dad wrote this piece of code, I would have written it in PHP too since C is too difficult to spell out for me.
Serious. PHP is able to do things like this, but still. I would prefer a more low-level language for critical applications.
Admin
This is a good thing. That gives it the potential to not suck someday.
Admin
So it unmounts and fscks for you...that's what they mean by software RAID. :P
Admin
No, it's a bad thing - it points to a lack of coherent design and that means it's probably simpler to toss it and go with something else.
Admin
hehehe...
Admin
Admin
It's not my baby, and that's where your rant falls flat. Maybe if you'd use more descriptive terms than "godawful" and "VB of the web world," you'd have some credibility.
If it's easy to use, it can't be too inconsistent, can it?
Admin
Who said i dismiss people for using PHP? I hate PHP, but it works for some stuff - so what? It is the VB of the web world - simple to use and responsible for a lot of nasty code riddled with security holes and slow sites.
And yes, it can be easy to use and inconsistent - anyone can make it do something, but there are three ways to do lots of different thing, and you have to go looking for the way that does what you want. There may be something in the api for your specific needs, but it's named funny, so you don't find it and use an exec hack. Woops, security hole.
Admin
Well, it's simply not true. I'd defy anybody to write bad code in Brainf*ck. Or indeed any code.
More to the point, it's a pretty bloody stupid statement. Yes, it's possible. It's possible to write Alexandrine verse in anything other than French -- but it's bloody difficult. I imagine that Hawaiian might work well, but not much else will. (Mr Pope might care to disagree, but I'll bet it caused him severe gout.)
Who cares about bad code? (Other than this site, obviously.) The objective is to write ... well, actually, good code is a fairly minimal step, but we'll leave it at that. Why don't we turn this perenially stupid argument on its head?
"Language X encourages you to write good code because ..."
Language X is clearly not PHP. That doesn't mean you don't use PHP where appropriate. It does mean that you don't use PHP where it's a synonym for tranquillising a horse.
My personal bread-basket of non-X includes, in no particular order: Java, Visual Basic (in any form), ASP, JSP, Ada, Fortran, and Ruby (although the internal jury's still out on that one).
80% of coding is maintenance. I've used and maintained PHP, but I wouldn't recommend it; needs must. It's a fine little language if you've got a small web-site and you don't mind castrating the MVC model.
Perl also fails on this basis, although it's more than fine for a quick hack.
For the job in the OP, I myself would probably pick Forth. I mean, jeez, it's a hardware controller. Who the fuck needs all the rest of this scripting/execing rubbish?
I did, however, enjoy the following:
%s %s: "%s" "%s" "%s" "%s" "%d" "%s" "%s" "%s" >/dev/null 2>&1
For some reason, this makes me want to sing 'Spam Spam: "Spam" "Spam" Spam" "Spam" "Beans" "Spam "Spam" "Spam" ...
... but I doubt that /dev/null is listening.
Admin
Admin
It's from the forums: http://forums.thedailywtf.com/forums/p/8748/165703.aspx
Admin
I meant for web development. I probably should've made that clearer. If you use Java for that, I WILL come over there and kill you.
And to those suggesting Perl: seriously? I'd much rather stick to using PHP, which atleast has a decent interface for Apache.
Admin
How many does PHP have? I've never used it so I'm curious.
IMO Python's not bad (yet): http://www.python.org/dev/peps/pep-0004/
But it seems like they do a decent job of pulling out them out after a while. Which makes me sort of wish they'd "deprecate" Tkinter.
Admin
My biggest issue with PHP is that part of its grammar is simple enough that even someone with no real understanding of programming, such as my father, could actually write significant amounts of code without too much difficulty.
Many people would tell you that's a good thing. However, I believe it allows people who are only able to code WTFs to extend them much farther. In a language like Perl, if you can't think like a computer, you will have a very difficult time making a royal WTF. You're much more likely to give up in frustration.
Also, while mod_perl may not be the greatest Apache interface, EmbPerlObject (written on top of mod_perl) seems to work fairly well to me.
Now, I wouldn't recommend Perl for all programmers. It works well for me because my mind works that way. There are many perfectly competent programmers whose minds do not work in the way of perl, and I'd recommend they don't try too hard - not only will they hurt themselves, but, when I look at their code, they'll hurt me, too.
Addendum (2008-11-03 19:27):
My biggest issue with PHP is that part of its grammar is simple enough that even someone with no real understanding of programming, such as my father, could actually write significant amounts of code without too much difficulty.
Many people would tell you that's a good thing. However, I believe it allows people who are only able to code WTFs to extend them much farther. In a language like Perl, if you can't think like a computer, you will have a very difficult time making a royal WTF. You're much more likely to give up in frustration.
Also, while mod_perl may not be the greatest Apache interface, EmbPerlObject (written on top of mod_perl) seems to work fairly well to me.
Now, I wouldn't recommend Perl for all programmers. It works well for me because my mind works that way. There are many perfectly competent programmers whose minds do not work in the way of perl, and I'd recommend they don't try too hard - not only will they hurt themselves, but, when I look at their code, they'll hurt me, too.
Addendum: All that having been said, the brief overview of what the PHP code was supposed to do sounds like something that PHP is very suited for. However, it also sounds like there's far too much code there. Furthermore, using Apache + PHP without using the Apache PHP module is a tremendous WTF. I do not see any benefit for this configuration.
I'm still confused why a logging daemon would need to mount, fsck, or mkfs. I'm suspecting it's a fundamental confusion regarding what a logging daemon is supposed to do.
Admin
I often hear this argument used in the opposite way. "We need GC languages" or "We need languages that are easier" because "developer cycles are more expensive than CPU cycles!"
Therefore, the argument goes, we need EASIER languages.
To me, it just sounds like an excuse for programmers to be lazy. "They've got 1 GB of RAM so who cares if I'm frugal with memory?"
Admin
No, it sounds like people do programming for money, not for bragging rights. Buying more RAM will often be cheaper than spending two weeks rewriting the damn thing from Java to C++. It is different with shrinkwrap software, but they're a different league from your typical in-house systems.
Admin
No it isn't - Mono can't run VB, only VB.Net. Gambas doesn't count either, because VB requires its legion of VB components in order to be what it is.
Admin
You could just spend a couple hours removing and redoing the worst of your code - java isn't that small, but there's no reason a decent java programmer can't make things play nicely in limited memory environments.
Admin
This isn't for the actual volume. It reserves 256MB from each drive, which it places into a hidden RAID-1, which it formats as ext3 and stores the event log. Until I figured out that the event log follows the drives and not the controller, I was very confused as to why a brand-new controller had logged errors when I used test drives.
Admin
Perl has automatic garbage collection. Unlike some languages, it actually does it as variables go out of scope, so you're not hit with big pauses when a GC cycle is run.
To me, Perl is about as easy as these newer 'easier' languages. It's harder to learn, but once you know the language, it's just as quick to code in it. Quicker, in many cases, thanks to the sheer quantity of stuff in CPAN.
The biggest difficulties with perl seem to be:
Regexes. Perl considers regexes to be a first-class programming technique, as part of its rubbish listing focus. Many people therefore use them, sometimes extensively. Simple regexes make code difficult to read for the uninitiated. Complex regexes (such as the heart of Email::Valid) make code difficult to read even for the likes of me.
Shell escapes are either a first or second class programming technique. As a result, people use them. This is rarely a good idea. (Hint: if you're ever tempted to do 'system("rm $file");', don't.)
Some people have problems understanding simple variable references such as ${$hashrefs->[$i]}{$hashkey1}[$elem]{$1}. Other people don't. (Personally, I try to not write code like the above - but I can read it just fine.) There are also some people who go for complex variable references.
Perl includes some easy array handling options, which should only be used under certain circumstances. It is left to the programmer to determine what those circumstances are.
Admin
When you say 'logging', are you saying 'something similar to what syslog does', or are you saying 'journaling'? 256MB seems to me to be a lot to reserve to 'something similar to what syslog does', at least for low-end systems. I can't^Wdon't want to imagine something like what you are describing being used for something which is not low-end...
Admin
Admin
Jeez, I really HATE this language. It's killing cells in my brain every time I see code written in PHP!
Why would somebody decide to use PHP in firmware unless he is brainless?
Admin
FIRST!
But my exec() abuse might have delayed the post a little bit.
Admin
Any language lets you write bad code. Some languages even encourage you.
But there are a few languages, very few, that go so far as to punish you for not writing bad code.
Admin
Damn straight. Choice of language is usually a follow-on problem caused by the first (as it certainly was in this case).
Admin
I'm sure I'm not the first person to say this, but do you think we could have syntax highlighting on the code snippets?
From a teaching perspective, it makes it a lot easier to see what the coder was thinking, and therefore where he went wrong.
Admin
Yes. It is just like syslog. In fact, it has an option to send log events to a remote syslog server. The log is stored as a plain text file with a binary index file.
Admin
When all you have is a pineapple, and you're stupid enough, every problem looks like a nail.