I'm working on a web project with PHP and jQuery, and need to make my own tiny scripting language within PHP.. My own scripting language should be able to call some PHP functions that I define, and of course have a simple way of defining variables and maybe even be able to use loops and such..
I found this site: "http://www.tuxradar.com/practicalphp/21/5/13" that explains some of it, but I don't think that is enough.
So i would like to hear you guys if you know a simple scripting language made in PHP, that I could take a look at? Or just more articles about the subject?
I hope you all have a nice weekend :)
You're looking for a scripting language that's based on another? You should rethink your project requirements.
I've written my own templating language in PHP. wasn't as hard as I thought it would've been. Keep it simple. Learn the fundamentals.
You need to learn how compilers work. Go away and read the dragon compiler book. It should tell you everything you need.
You'd need to familiarize yourself with the following topics:
- How to read text and define a sensible language. Look at BNF, context sensitive and regular languages.
- How text is tokenised. Giving meaning to bits of text.
- Semantics of the tokens. What does each token convert to in PHP?
Once you've done that, you can apply what you know to PHP.
Good luck. Never give up.
[IMG]http://oi41.tinypic.com/690vuh.jpg[/IMG]
Oh god why would you write any kind of language in PHP aaaa
You realise that PHP is lexed and parsed on page load? That it runs without optimisations? That it was designed as a templating language to begin with?
[QUOTE=Zemnmez;41486248]Oh god why would you write any kind of language in PHP aaaa
You realise that PHP is lexed and parsed on page load? That it runs without optimisations? That it was designed as a templating language to begin with?[/QUOTE]
Okay, maybe you wouldn't use PHP on a website that has over a million users every day.
This is real life, PHP isn't that bad.
[QUOTE=Floatation;41551537]This is real life, PHP isn't that bad.[/QUOTE]
Ehhhhh... [url=http://www.codinghorror.com/blog/2008/05/php-sucks-but-it-doesnt-matter.html]it kind of is pretty terrible[/url].
[QUOTE=andersonmat;41552198]Ehhhhh... [url=http://www.codinghorror.com/blog/2008/05/php-sucks-but-it-doesnt-matter.html]it kind of is pretty terrible[/url].[/QUOTE]
The quote's he's got in that article mention VB6 and how "OO is a foreign concept to PHP" which indicates this was way back when PHP was a bit messier. The quotes also only give anecdotal evidence:
[quote]So here's my problem, based on my limited experience with PHP (deploying a couple of free apps to do this and that, and debugging a site for a non-technical friend here and there): all the PHP code I've seen in that experience has been messy, unmaintainable crap. Spaghetti SQL wrapped in spaghetti PHP wrapped in spaghetti HTML, replicated in slightly-varying form in dozens of places.[/quote]
[quote]Every solution I've ever seen or developed in PHP feels clunky and bulky, there is no elegance or grace. Working with PHP is a bit like throwing a 10 pound concrete cube from a ten story building: You'll get where you're going fast, but it's not very elegant. ... I love PHP, and it's the right tool for some jobs. It's just an ugly, cumbersome tool that makes me cry and have nightmares. It's the new VB6 in a C dress.[/quote]
"Well every solution I've seen made in X is poorly written so therefore the language must be horrible!". No, you just must have met a lot of incompetent programmers!
PHP can be as maintainable and manageable as you want it to be - it just so happens that due to the flexible and rapid nature of the language you're much more inclined to fall into bad practices, like spewing all your page logic on the same page as your HTML, which very quickly leads to spaghetti. Keep your code to good standards, don't allow PHP to fill in the blanks for you, and generally use good practices and it's as reliable as you make your code. Yes, you may need a good IDE to guide you through the inconsistencies of PHP, but it's a small price to pay for such a powerful, flexible framework.
Generally this article has a few good points about good practices most people neglect: [url]http://www.odi.ch/prog/design/php/guide.php[/url]
I don't agree with everything he says on there, but the business logic, page controllers, and presentation layers all are generally accepted practices. He's also got some nice ideas for deploying your application and how to manage your code to make it location independent.
Overall, PHP isn't nearly as bad as people say it is. There's a reason it's used by 80% of the web (and growing). If it was anywhere near as terrible, would so many huge websites still use it? I can understand if huge websites DIDN'T use PHP and the statistic of high usage was made up of small websites made by beginner programmers who are led to use PHP because it's popular, but that's not the case (since many big websites DO still use PHP in conjunction with a lot of beginner programmers)
[QUOTE=Trumple;41564338]Overall, PHP isn't nearly as bad as people say it is. There's a reason it's used by 80% of the web (and growing). If it was anywhere near as terrible, would so many huge websites still use it? I can understand if huge websites DIDN'T use PHP and the statistic of high usage was made up of small websites made by beginner programmers who are led to use PHP because it's popular, but that's not the case (since many big websites DO still use PHP in conjunction with a lot of beginner programmers)[/QUOTE]
The "People wouldn't use it if it wasn't bad" thing is a horrible argument, huge websites that are tech conscious are moving away from it when they can. Existing huge websites are using PHP becuase it's legacy code. They aren't going to switch their whole codebase over to another language because it makes no sense to do that from a business perspective unless your codebase is such a heap of crap that you are better off rewriting the whole thing lol.
The fact that something is in widespread use does not mean it's even close to the best solution, it just means it's the one that is in widespread use, and with PHP I'd be willing to bet money on the fact that it's because it's really easy to find hosting for and really easy to get started with because all you have to do is find a shared host and an FTP client.
PHP is bad because it's sloppy and incredibly inconsistent. Read this if you want a better article about why PHP is so junky: [url]http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/[/url] (it's not just because it's 'easy' to make bad design decisions with PHP, the language itself is flawed)
If you read that whole article I linked and still want to use PHP over other available solutions you are either dense or a masochist.
[QUOTE=KmartSqrl;41566598]The "People wouldn't use it if it wasn't bad" thing is a horrible argument, huge websites that are tech conscious are moving away from it when they can. Existing huge websites are using PHP becuase it's legacy code. They aren't going to switch their whole codebase over to another language because it makes no sense to do that from a business perspective unless your codebase is such a heap of crap that you are better off rewriting the whole thing lol.
The fact that something is in widespread use does not mean it's even close to the best solution, it just means it's the one that is in widespread use, and with PHP I'd be willing to bet money on the fact that it's because it's really easy to find hosting for and really easy to get started with because all you have to do is find a shared host and an FTP client.
PHP is bad because it's sloppy and incredibly inconsistent. Read this if you want a better article about why PHP is so junky: [url]http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/[/url] (it's not just because it's 'easy' to make bad design decisions with PHP, the language itself is flawed)
If you read that whole article I linked and still want to use PHP over other available solutions you are either dense or a masochist.[/QUOTE]
That's also very one sided, PHP has changed a lot over the last year, and although does fall apart with some parts, it has massive positives, like as you said, easy to find hosting, easy to learn.
Although I love using Ruby currently as I have been using it for a few months now, I still use PHP a hell of a lot more, it's probably personal opinion, but PHP is not as bad as it was around a year ago like everyone thinks it is.
[QUOTE=KmartSqrl;41566598]The "People wouldn't use it if it wasn't bad" thing is a horrible argument, huge websites that are tech conscious are moving away from it when they can. Existing huge websites are using PHP becuase it's legacy code. They aren't going to switch their whole codebase over to another language because it makes no sense to do that from a business perspective unless your codebase is such a heap of crap that you are better off rewriting the whole thing lol.
The fact that something is in widespread use does not mean it's even close to the best solution, it just means it's the one that is in widespread use, and with PHP I'd be willing to bet money on the fact that it's because it's really easy to find hosting for and really easy to get started with because all you have to do is find a shared host and an FTP client.
PHP is bad because it's sloppy and incredibly inconsistent. Read this if you want a better article about why PHP is so junky: [url]http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/[/url] (it's not just because it's 'easy' to make bad design decisions with PHP, the language itself is flawed)
If you read that whole article I linked and still want to use PHP over other available solutions you are either dense or a masochist.[/QUOTE]
I've read it a few times in the past. It is sloppy and inconsistent, that's almost exactly the point I made in my first post.
[QUOTE=KmartSqrl;41566598]The "People wouldn't use it if it wasn't bad" thing is a horrible argument, huge websites that are tech conscious are moving away from it when they can. Existing huge websites are using PHP becuase it's legacy code. They aren't going to switch their whole codebase over to another language because it makes no sense to do that from a business perspective unless your codebase is such a heap of crap that you are better off rewriting the whole thing lol.[/QUOTE]
You're right, because PHP has a limit of scalability (though again, that's largely defined by the sloppiness or poor standards of the developer). I'd bet if Zuckerberg knew how large Facebook would grow, he wouldn't have chosen PHP. What'd I'd agree on is that for small applications, what most people make here, PHP is perfect and quick. Learning a new language just because PHP isn't scalable to the size of Facebook, however, is overly cautious. To a first time web dev, I'd probably still recommend PHP because it is headed in the right direction with future updates. Even then, you could use something like HipHop if you're concerned about speed rather than how PHP works for devs.
The problem is that you need to build a product and get it out there. Who gives a shit if it can scale to 100M+ users if you can't even get 100? Of course it should be a consideration, but it should not be a priority initially.
Unfortunately, PHP is a sloppy language with a very low barrier to entry which makes it an easy choice for people whom are new to web programming though I do agree it is moving in the right direction.
[QUOTE=Trumple;41567336]I've read it a few times in the past. It is sloppy and inconsistent, that's almost exactly the point I made in my first post. [/QUOTE]
Which makes it an inferior tool. I can write good PHP, I can write Ruby and write a third as much code and end up with cleaner, more concise code.
Let's say I want to get an array of the IDs from a collection of records.
Ruby:
[code]
ids_array = collection.map(&:id)
[/code]
PHP:
[code]
$ids_array = [];
foreach ($collection as $value) {
$ids_array[] = $value['id'];
}
[/code]
[QUOTE=Trumple;41567336]You're right, because PHP has a limit of scalability (though again, that's largely defined by the sloppiness or poor standards of the developer). I'd bet if Zuckerberg knew how large Facebook would grow, he wouldn't have chosen PHP. What'd I'd agree on is that for small applications, what most people make here, PHP is perfect and quick. Learning a new language just because PHP isn't scalable to the size of Facebook, however, is overly cautious. To a first time web dev, I'd probably still recommend PHP because it is headed in the right direction with future updates. Even then, you could use something like HipHop if you're concerned about speed rather than how PHP works for devs.[/QUOTE]
Scalability is something you worry about when you need to, you don't start a company trying to figure out how you're going to support 100 million users and then building an architecture to do that, you build something to help you get those users.
No one is saying that you shouldn't use PHP just because it doesn't scale well (which it can if you know what you are doing, when it comes down to it anything can scale, some stuff just scales better).
I am saying you should not use PHP because it is a bad, sloppy language. Continuing to use PHP when there are so many better alternatives out there is like using a hand saw to cut down a tree because you don't know how to turn on a chainsaw. If you are even remotely serious about web development you should be constantly trying to find better tools to accomplish your job.
You say PHP is perfect and quick for small applications. I guarantee you that whatever small thing you are doing in PHP could be completed faster in a more modern language/framework. I would stake my career on that.
PHP works, but that doesn't mean it's good.
-snip- misread
Sorry, you need to Log In to post a reply to this thread.