As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
A few years ago I started working on a few ideas about a programming language and as I was so excited about them I just wanted to see how they would works, so I decide to write a very simple compiler for that. As I'm more comfortable and more experienced in PHP, I just took a look at to see if it's possible to write a compiler in PHP and very soon after that I found that yes, it's possible. So I start making that and fortunately everything was okay and now it's working fine.
Those days I just wanted a place to start working on my ideas, and as PHP was fast in development (no need to compile), I had MySQL on my hands also, and debugging was really easy, etc.
Now I want to extend this simple compiler, and that's where I need your advise. My main question is "Is PHP a right tool for a compiler project?". Just suppose that I'm not gonna release it publicly, so just think about the PHP abilities to handle the task, not further problems like distribution.
I believe that it has some advantages. It's fast in development, I just edit the code and press the F5 on browser and I had my binary output right after that. I also made a text box there where I could write my simple codes, press the submit and then I had my binary output again. It was also fast to keeping and working on the parsed data in MySQL. But now I'm more worried about the script timeout for example. If it's gonna compile 10,000 lines of source code, it would timeout I guess. I know I can increase the timeout, but still worried about that. Also I know that PHP as a scripting language is (as I heard) 10 times slower rather a compiled-application.
So, do you think I have to switch-off to the C? (which I'm also okay with that also) ... or do you have any ideas if I could continue with my PHP back-end, but to handle more serious things and without facing critical mistakes?
Update:
Yes! the project is personal and for fun. You may consider that also!
Regarding application for a PHP-based compiler, yes, it's not a real-world compiler, but imagine if you want to share your ideas with others, it would be great if you gave them a web form to write their code, press the button and download the binary code. It's not my goal, however, I just wondering about that.
Regarding Lex/Yacc, my ideas was more about optimizing the final binary code, so I needed something more than just generating a binary code via Lex/Yacc.
PHP is not the ideal environment for writing compilers. Is it doable? Sure. Should you do it? I am vehemently opposed to writing a compiler in a high-level language like PHP. I'm also opposed to unnecessarily reinventing the wheel.
If it's for fun, I say go for it, but I don't see any practical uses for a PHP-driven compiler at this time.
It is possible to write a compiler in any language (even some non-Turing-complete languages can be used). But in order to make life easier you'll need certain language features which are missing from PHP, and since it is a pretty low-level language, it is not quite possible to add such features to the language.
A decent language for implementing compilers must contain:
Some form of algebraic data types, it is relevant even for a fully dynamic languages (like Lisp)
Pattern matching, the more powerful and expressive - the better. Writing AST transformations without pattern matching is a pain.
This is a bare minimum. Having some decent native support for graphs is an advantage. Having an embedded support for parsing is quite useful (but parsing is not that important in general). Having an access to Prolog or Datalog in runtime is extremely useful (but it should be easy to implement your own Prolog in PHP).
Webjawns say: but I don't see any practical uses for a PHP-driven compiler at this time.
So????
Smarty - is a compiller!!!
If your compiller is just for fun, or specific, php-related use - it is good idea took the php as environment.
But if your compiller has a performance requirements or memory restrictions - it is very bad idea to use PHP for it.
There's a computer programmers gag that sounds something like:
Rookie: Why is C considered to "run faster"/"use less memory"/"insert other optimization comparison here" than Java?
Mentor: Because the Java compiler is written in C while the C compiler is written in C (with traces of assembly for optimization).
Almost all compilers are written in C. The same thing goes for operating systems which are also almost all written in C. Almost all of the main prepacked libraries that any high level language uses are written in C. Almost all high-load servers (Apache & MySQL included) are written in C. Basically almost every mission critical piece of software is written in C.
With that in mind id's say:
I'd write a Tokenizer -> Parser -> Transcoder chain in PHP for fun - maybe even one with database storage what the heck; but i would be outputting text (source code for another language).
I wouldn't write a Compiler in PHP because i wouldn't want to be outputting binary files from PHP - not because it can't but because I don't like using strings for binary arithmetics.
The Compiler I'd write in C.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I need to valorate what technology use for a web project, the team is composed by 4 developers and the time of the project is 1 year.
I'm more familiarized with php but the client is asking me to do it with JAVA EE.
I always have the same perception with Java and its frameworks:
So much xml and class in order to do simple things. In codeigniter I've to use 3 files (model, view and controller) with hibernate + spring + JSF I need more than 10 files!!!
An abusive use of the server. The javascript code lose importance and it's not good nowadays. Of course we can add javascript code but It seems "java web guys" prefer do the stuff on the server instead of the client.
Not good-looking application. Richfaces seems like a web of several years ago.
When I see a java application like liferay, alfresco, they looks heavy and very slowly.
I think I can be a little confused because lots of people and big companies continues using JAVA for the web. Why? it's about integration?
On the other hand Java is faster than PHP, but JAVA's servers need lots of memory (more expensive). In a server with many request we can improve with a language like php with bigger time per process and less memory per process because the server never is collapsed because of memory. Sometimes a JAVA server could collapsed because of memory and the average of response time in a real production environment would be bigger than php.
I'm really pleased with Codeigniter, why so many people thinks Java is better?
Thanks in advance,
Alberto
well I'm not using CodeIgniter so my comparison is already incomplete.
Question one would be: why do they ask for Java? Often big companies only offer Java or .Net environments for productive systems so they might not have the people to productively run PHP applications. I know its not complicated but the maintenance people define what they are running.
Ofter people talk on languages and their features but when the first business use case has to be discussed no framework will save you that amount of time to make it count. Most programming language will somehow solve the issue.
Java is not only RichFaces or JSF. There is a lot to choose from. A LOT. Not an advantage.
Stuff often forgotten is the tool support. Java comes along with a JVM that can be analyzed in detail what it does with its memory, garbage collector, threads and so on. Profilers in Java allow you to identify almost any memory leak within a few hours.
Most of the JVM monitoring works in realtime (with about 5% overhead).
Talking about tool: refactoring support is far beyond what PHP IDEs come along with.
You are correct if the first look at Java compared to PHP looks like elephants and horses. (ok the logo of php is an elephant, perfect comparison...). Horses are more flexible to turn around corners but they might not carry that much around.
I think from a language perspective Java is still more advanced than PHP. Namespaces, Classes, Type-Safety. These are somewhat available in PHP but still quite new.
Frameworks like Spring allow you to leverage your application on an architectural level and are more than just libraries.
I'm not the biggest Java EE fan, so I'll not complain on that.
A simple approach for you could be Tomcat+Spring+SpringMVC and a template engine for the GUIs. There is also GWT (Vaadin) if you target higher speed client behaviour (still a lot more out there).
There are lightweight approaches in Java too. I agree the standards in Java do have a more fatty tendency.
In my experience Java has no major drawbacks compared to PHP. The language choice will only affect success of the project if people come with less knowledge than required and spend too much time in learning things. And trying to find the right book about Java could be a project by its own :)
(counting as an advantage)
But I have no doubts PHP would allow you to finish the project.
I would rather look into the goals and requirements before choosing the technology. This often implies or simplifies a decision.
I hope I did answer at least one question here :)
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I was reading the article "PHP Sucks, But It Doesn't Matter" by Jeff Atwood.
In the comments he writes:
That said, I absolutely think it's important for PHP devs to be aware of the architectural limitations of PHP, and understand the alternatives.
What are those limitations and how do they compare with other scripting / weakly typed languages?
Also, what are the alternatives in those conditions where limitations need to be avoided?
There are basically two real limitations I see:
PHP is a fully synchronous language. This has impact on which things you can easily implement in PHP and which not. For example implementing a Long Polling driven chat application isn't trivial, because PHP would need block one process per chatter. I'm not saying it's impossible, you can hack around this limitation using some PHP Daemon library. I'm just saying that this is one of the cases where other languages, like JavaScript, are more appropriate (NodeJS).
PHP is slow. Please don't understand this an an offense. It's a fact that PHP - as implemented by Zend - is slow compared to other scripting languages. This typically is no problem when building websites, but you obviously can't do certain things: Implementing a ray tracer in PHP is definitely a bad idea - whereas in JavaScript you could do this.
But apart from that, I think that PHP is pretty multi-purpose. You can use it for nearly anything - and I do ;)
Take a look at the date. The article was written in 2008.
It means, that if you'll see the PHP5.3 advantages, you'll find there many things, like closures and namespaces, which were in other languages before. Some of them is already affected the architecture of famous frameworks, like Symfony.
And that list will never be complete.
Meanwhile, I meet a lot of people who think that "weak typing" language is an architectural problem itself.
Then, some people think that inline regex syntax is good thing in, for example, JavaScript, but others think, that "different language" must be written down in string constants there, as in PHP. Etc.
I'll take a stab at this without getting too into the nitty gritty:
The initial design of PHP as a collection of functions still shows through.
Object-oriented patterns that have been implemented in the latest PHP 5 releases are still half-baked and lack multiple inheritance (or "mixins"), proper module support, and are designed to be backwards compatible with the CoF (collection of functions) design.
Method overriding and callbacks are not supportive natively.
Closures. They are there, but they are very weak.
Errors vs Exceptions — methods are inconsistent in which they use (thanks again to CoF design), and error-handling is half-baked.
I'm sure I'm stepping on someone's toes here and I'll get any angry mob, but I'm also sure that I still didn't hit everything. It's largely subjective, but it's easy to see what is to dislike when you stack PHP up next to Ruby or Python.
I don't find it odd anymore that all of "PHP SUCKS" articles are coming from developers accustomed to established Microsoft technologies.
What I do find odd are statements that indicate that PHP is a spaghetti code. It's completely up to the author of the code whether the code will be spaghetti or if it'll use certain design rules when approaching the problem.
The reason a lot of PHP code out there is spaghetti code is because examples and tutorials are such that they don't teach beginners the good coding practices. Also, people are quick to grasp examples like hello world or connecting to MySQL, doing a query and looping over the result - but that's it, that's where ALL tutorials stop. I still haven't found a tutorial that covers the following:
what is a framework and what it helps with
what are data structures and data types (explained in a way a normal human can understand)
what is an array, what are array dimensions, how do arrays work, what are arrays useful for
what is object oriented code, why object oriented code, how does PHP do it, what is considered good, why are there patterns out there and so on
As you can see, a beginner programmer won't be bothered to learn all of those points outlined above, I know that because I was a beginner too and did all the mistakes beginners do. However, even if someone doesn't know how to program, they can still create useful applications.
Many popular scripts were written by people who knew WHAT they want to achieve, however they did not know HOW to properly design the environment (framework) in which they'll deploy their php code.
That's why we see scripts that become incredibly popular due to the ease of their use as a regular user which are hard to extend looking at it as a developer, using weird function names, odd coding conventions and no commenting.
Also, what's ridiculous is saying PHP is slow which is absolute nonsense. When I come across such statement, I want to shoot myself in the head for reading such a blog entry.
One has to know several things before making such a statement:
PHP is a scripting language, that means the interpreter is invoked every time someone requests a PHP page which takes A LOT of CPU power. That has been addressed by using bytecode caching mechanisms such as APC which stores the copy of pre-interpreted piece of the script in memory. The results are impressive, and I kid you not - execution for some of my scripts goes from 20 milliseconds to 1 microsecond, where some benefit "only" 5 times. That's on a system that serves 1 thousand concurrent users. Now, if someone wants to tell me that 1 microsecond is slow (or 5 milliseconds) - I'll take that as bullshit.
PHP is not the only thing involved in serving a web page. There's also underlying server (Apache) which has its own issues, there's MySQL which runs queries - and who says all queries are optimal? There's the network, there's the hard disk, there's the CPU, there are tons of other processes. Configure Apache with PHP-FPM, optimize MySQL to perform good on 8 core machine with 16 gigs of ram, use APC, use Memcache - and voila, you're getting an incredibly fast, scalable system capable of serving an incredible amount of traffic.
Languages that PHP is being compared to are often "compiled" into the bytecode and then executed by
You can extend PHP yourself. Assuming a PHP function is slow, NOTHING prevents anyone from creating a .so in C that is able to do the job faster and then hooking everything up trough extension in PHP. Not that I know what would such job be that would require that, but such a thing IS possible.
Sadly, and I say sadly because I respect certain programmers and admire their work (and I'm by no means a PHP fanboy) but it hurts me when I see uneducated, inexperienced and subjective comments about a tool which spreads misinformation.
As for why big websites use PHP - because it's fast. Because they laid proper foundations before starting the projects. Because it's free, extensible and scalable. Because it follows C syntax. Because you can extend it when you need it to be faster. Because it runs on a free operating system. Because it's easy to use.
PHP is improving everyday. It is open source and used all around the world. That said, when you have a problem, it is most probable that you will find your solution or get help faster than any other language.
The very reason of this article, I believe it is simple. If you (or in that matter any other programmer) used to code in C++, Java etc.. they had a lot of possibilities such as OOP coding and PHP was limited in the beginning.
It is a good thing that PHP has many built-in functions / methods / classes so you don't have to spend hours to code some function / class / method which PHP already has.
You don't have to (and you shouldn't) try to memorize all these functions. It is useless to memorize all of them (which one is doing what, how to use it etc). Imagine you are working on some project which took you 4-5 months to finish (yeah big one (: ) You are not going to use all these functions in all the projects and eventually you will forget what they were doing since you don't use them often.
The point is, you should know the syntax of PHP. When you need to do something, check first if PHP already has what you want to do in its library. Check the manual to see how to use it. This way, you will also LEARN (NOT MEMORIEZE) the ones you use often and this information will be hard to forget.
PHP or any other programming language is just like a normal language which we humans use daily to communicate with each other. If you don't use it, you will forget.
PHP 5.3 and above brought many features. Static feature is one of the biggest feature for me. It made my life so much easier that I can't even begin to describe.
Since PHP is that famous and open source web scripting language, Facebook developer team created HipHop.
What HipHop does is, takes the data from PHP and sends it to C++. C++ does all the process and sends back results to PHP for outputting.
The whole idea of HipHop was to make Facebook use less servers & improve the page display times.
Now you tell me if this seems limited and / or slow to you?
i dont think there is anything like 'architectural limitation' for php. developer knowledge limitation might be the reason. read this http://www.quora.com/What-is-Facebooks-architecture . most of the time, non-world-class developer does not know how they could use php to its full capabilities.
I would assume he is referring to the fact the the OOP portions of PHP are not the greatest compared to languages that are purely object oriented.
Architecture Limitations in Addition to nikic's answer
Writing extensions for PHP is a PITA. Not as bad as with Perl or Java, but not as easy as it could be. The ease of extensibility champion is still TCL which hails from the early 90's. Nearly any C function taking char* can be made into a TCL extension.
Embedding PHP in other systems. mod_php, gtk.php.net shows it can be done, but Guile and TCL are much easier to embed.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
It is widely believed that PHP is the easiest programming language to learn for a beginner. The argument goes that PHP is the easiest language to use for getting a quick prototype up-and-running.
Why might this be? What, specifically, makes PHP easier to use than other languages?
Would this remain true, even when learning to use the object-oriented aspects of PHP? Or is it actually the object-oriented aspects of PHP that make it easy to learn? How does it compare with other web programming languages?
PHP is native to the web. While Ruby and Python have much cleaner syntax, more elegance, and more power, there will always be a layer of abstraction between Ruby/Python and the web itself -- after all, they were designed for much wider domains than the web.
Newbies to programming are typically newbies to sysadmin, and getting to Hello World in a Rails or Django is pretty painful -- for some even prohibitively so -- compared to PHP.
For newbies, it's easy to conceptualize that typing in:
http://mysite.com/something.php
...will execute the code stored in the file:
/path/to/mysite's/webroot/something.php
This simple one-to-one routing also mirrors that of HTML and other static files.
Beware, however, because this one-to-one routing also leads to security problems (i.e. people tend to keep all of their executable code within the webroot -- even secure code, which may contain passwords, hash salts, and other Privacy-Important code). Combine this with a lack of sysadmin experience, and many sites on the web are a chmod away from being totally exposed.
Responsible PHP like Symfony helps people avoid this, but Symfony requires the same level of sysadmin chops as Rails and Django.
Object oriented programming is optional
PHP is forgiving
The script continues running on minor faults.
When E_NOTICE (or even E_WARNINGs) are suppressed, the errors aren't even noticeable.
But also in the small things like substr: In C# you'll get a big fat exception when you'll try substr($text, 3) on a $text with 1 character.
Great online manual
http://php.net/manual/
Quick and Dirty is the default
The language is filled with useful shortcuts.
PHP lets me express what I want without typing an essay.
Conceptual simplicity.
A php site can consist of one file representing one page, with the dynamic content embedded within the static markup as needed. You can scan down a simple php file and see everything defined and run sequentially.
With a simple php site, there is no learning curve where one has to figure out in what file a specific piece of logic belongs, or in what external file a function has been defined.
...
Of course there is a reason that frameworks like rails provide lots of files and a fixed structure, and I would definitely recommend using one for any sizeable (and probably almost every small) site.
I do think though that it's this very low barrier to entry that is responsible for a lot of php's popularity.
I don't think that there's any reason a better php style system couldn't be written in ruby or similar - think just directories and .erb and .haml files and nice 4.days.ago syntax. But most people who could do this see the value in the extra tools that a framework provides. Sinatra is a minimal framework, in which it's possible to define an entire site in one file, but even it has routing powered by code instead of just directory and file naming.
PHP have many web tutorials and books about it, it's free and popular which makes PHP communities bigger. And also it's intuitive.
While PHP is far from the best web programming language, it's the most common (in terms of availability in hosting packages), the most popular (even in things like tags here on SO), it has some of the best documentation, and it's one of the least strict in terms of having to follow any sort of standards.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Friends,
I've got some exp in c++ and now kind of starting my way to J2EE (to survive:))). Meanwhile, I've got a plan to venture in to a web portal my own. But with very little experience in web technology, I'd need to start from scratch. I'm little confused on which way to go and I'm here.
PHP, Python or JSP, considering the fact that, anyway I've got to learn J2EE at my work.
Would that be worth to learn PHP or Python to develop a portal which I expect to get 80-100K
hits per day "IF" everything goes well OR jsp would be sufficient?
Many thanks
Before learning either of these, spend some real time and learn HTML and CSS in depth. Also learn Javascript and JQuery (or your favorite client side library). The O'Reilly books on the topic are pretty much all good IMO.
I say that because I think that you'll find that for most modern web sites, a lot of richness is moving to the client side, and away from the server side. Under this model, your code in PHP or JSP is probably going to look pretty similar (ie, fetch data from the database and serve it to your view or into JSON for the client to consume).
Considering you're used to c++, should look at aspx and c# - probably closer to your current experience.
That said, PHP is a doddle, so it shouldn't present any challenges. Bear in mind that if you want to get the most from the language, you absolutely have to learn a little bit about configuring apache, and frameworks (cake, codeigniter, zend etc).
All the server-side technologies you list are "sufficient" for the volume of traffic you expect, if you design the site well from a performance and scaling viewpoint -- and so do many others you haven't mentioned, such as other Java-based approaches, C# ones, and (last but not least) Ruby (probably with Rails, though, like the other languages, it has several frameworks for you to choose from).
As most everybody said, the client-side considerations are sharper -- unless you want to try a "server-side generator of client-side code" like gwt (I'm told the latter works well, but personally I'm always wary of code generators, esp. using a code generator w/o understanding of the "code" it makes for you, which in this case is HTML, CSS, and Javascript with its own framework). Except for GWT and similar approaches (if that's your chosen poison), really learning HTML, CSS and Javascript is really a must -- and then you get to choose among many, many frameworks again (jQuery, Dojo, closure, etc, etc).
For performance issues, you really want to study Steve Souders' site (and books, etc) -- Steve was a server-side guru until measurement showed him the bottleneck was really client-side, and then he turned himself into the client-side performance wizard;-). But to get the most out of the books you'll need understanding of HTTP, HTML, etc, etc, to start with;-).
Hit's per day isn't a really useful metric for estimating performance. You really need to be concerned with the peak load and the acceptable response time.
80-100k hits per day is an average of about 1 hit per second. The hits are not going to be evenly spread out, so for normal traffic you might expect a peak load of 10 hits per second.
If you are going to promote the site with newsletters or commercials, expect to peack at 100's of hits per second.
If you selling $1 air tickets, expect to peak at 1000's of hits per second.
Now the language you choose for the site isn't nearly as important as your choice of database (not necessarily relational) and the way you store the data in the database.
Scaling up frontends is relatively easy, so having really fast efficient HTML generation shouldn't be a primary concern. Pick a platform that is going to be efficient for development time.
I expect this question to be closed as being subjective. But, I'll put in my 2 cents.
JSP would likely dovetail well with J2EE. (I've heard that it can be a bit rigid, but I have no experience to provide any insight on the matter.)
PHP is a good candidate, because it's popular. You can find a lot of info on the web.
Python isn't as popular for webdev, so finding examples won't be as easy.
I also second Dave Markle's opinion. If you want to learn webdev, HTML, CSS and JavaScript will be crucial as well. You may never want to be a front-end developer, but you can't get away from dealing with those technologies at some point.
There are many options.
Since you already know (and is learning about) Java, one option is to use GWT for both server and client. This can help you in that you do not need to learn another language (JS/HTML/Python/PHP etc). If your portal is going to be big, using Java can help you organise the application better - usually JS/HTML based applications are not very suitable for proper organisation, even if you use good JS Libraries like jQuery or YUI. Having a good organisation can help a lot - during updation and modification later.
If your planned venture is a single/two person venture or if it is time bound - where time to market is everything - then I would not suggest the earlier approach - especially if your server side part is expected to be big.
Java is a slow language to write code in. A project which you will take say 6 months to write in Python will take you close to 1 year + in Java. In such a scneario, I would prefer Python - it is a proper language - unlike PHP, and you create code with good organisation there too - albeit a little less organised than using Java.
Please note that if your client side code is much more complex than your server side code, then going with GWT will do you no harm. But if your server side code is very complex compared to the client side, then I would suggest Python.
Another point is to use existing Web Frameworks to ease your work. For Python, Django is an excellent choice. This itself will decrease your work time by 50% or more, while making your code much more secure and scalable.
It really isn't that similar to C++, but I would recommend PHP. You really can't expect a server-side scripting language to be similar to a compiled language like C++. Personally, I find PHP to be an ugly, messy looking language, but once you get into it, it's very rewarding. Other languages have too many drawbacks. ASP.Net is too Microsoft-centric, Python and Ruby on Rails are too obscure, and are also non-curly bracket languages, meaning it will require a lot of adjustment to change to them. Hope this helps.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 13 years ago.
Back when I was learning HTML, I loved how easy it to build pages and arrange everything just the way I wanted using tables.
Then I moved to CSS and learned that you could quickly swap designs without recoding your page. With just a few CSS changes your HTML designs could go from one theme to another and any element could become any other! With CSS I could design spans that looked like images!
Moving from HTML to CSS expanded my concept of design by implementing what I would later learn is modularizing things - just like MVC.
I am now a very competent PHP programmer who is thinking about Ruby. Most of the stuff I pull up on google is PHP vs Ruby rants which don't truly help anything. They are two different languages and take their style from different points. PHP looks like C++ strlen($string) while Ruby looks like server-side JavaScript. str.len()
I want to know the top 3 things about ruby that could really open my eyes as a programmer and justify the time I know it will take to pickup and master a new language.
Please, no mention of abstract things
like language maturity, or obvious
library's like AR which exist in both
languages.
MVC is now used in almost every web
programming language so it doesn't
count either. It is also not
sufficiant in and of it's self to
cover everything. MVCLLCC
(Model/View/Controller/Library/Locale/Cache/Config)
is more accurate.
:UPDATE:
Apparently there isn't too much new in Ruby compared to the other languages I use. Blocks appear to be nothing more than functions with a different name. procs seem to be blocks with callbacks which would be like a hooks system. MVC, AR, and everything else is already in the other languages.
However, I believe the most exciting thing I have seen is that you can open up classes at runtime and add new methods! This is a very important concept and really removes some hurdles that PHP has. No longer do you need extend child classes just to add a few methods to a parent class.
Well, you cut out a few of the things that make Ruby really fun, so I think any remaining list is going to be somewhat arbitrary. Here's why I think Ruby is nicer to work with than PHP:
Consistency: In Ruby, everything is an object -- even numbers. You call a method on an object the same way -- there aren't really any "special cases". Moreover, the standard library (and most 3rd-party libraries) have consistent naming schemes and styles. The PHP library has grown...organically, and as such, the names, use of underscores, etc., is chaotic.
Functional-style programming: Ruby borrows a lot of constructs from functional languages like Lisp. This is a pretty arbitrary reason, but I like functional programming, so having easy access to functions like the map and fold* methods from Lisp and Haskell is a plus for me. It also makes heavy use of blocks (aka "closures") which not only open up some very nice programming styles, but also allows you to write some very general code that can be used in a very specific manner, depending on your needs.
True OOP: Ruby's OO model is borrowed heavily from Smalltalk, and uses the message-passing style rather than the method-calling style. This lets you do pretty cool things like implement your own handlers for missing methods. Ruby is also dynamic in nature, and thus lets you define methods -- and even entire classes -- on the fly, at runtime. You can also "open" classes up and provide your own methods, which can save yourself the hassle of, e.g., extending the String class just to add a rot13 method.
RubyGems: RubyGems is a package manager for Ruby gems (third-party Ruby modules). It makes installing, managing, and removing third-party modules (and their dependencies) a breeze. (I threw this one in as a bonus reason.)
Lambdas (blocks).
Mixins.
Heavy use of the above two concepts in the standard library.
I would also nominate continuations (callcc), but they seem to be relatively obscure (which is a pity), and are gone in 1.9.
Top 3 things about Ruby that I enjoy:
Blocks and procs
Metaprogramming
Enumerable module (tons of awesome Array goodies)
Its hard to stop at 3 but maybe others can add more.
Best thing is try some code out for yourself. Good luck and have fun.
Here's at least one reason that applies to me (maybe you too): The way ruby handles object-oriented programming has "freed" my mind a lot in terms of how I think about coding and architecture. Everything is an object with ruby...
Ruby is fun to read and write
Blocks are even more fun
RUBY IS JUST PURE FUN
I'd say give it a try. I was once a PHP coder too and then switched to Ruby and never looked back. The only downside is the documentation which is clearly better in PHP (I would even say PHP has one of the best)
Here are the three things I really like.
I am not going to speak about the language itself but of what I like in the ruby world in general.
Tests
A lot of frameworks are available. If find them simple. Far easier than anything I have tried in JAVA.
The ruby community is very test-centric and you can find very good screencasts and tutorial to get you started.
It has changed the way I code.
Rails
I believe I started (seems so long ago :)). With Html+tables then CSS then PHP etc.
2 years ago I discovered Rails. And I really think It is an amazing framework.
From my point of view it is the best by far if you do Web Development.
I am curious so I have looked at other things like django, CakePHP, Zend etc but I have never find something as good as rails. Of course it is a matter of taste but I strongly advise you to try it.
Rails is not only an MVC. It is an easy to use MVC.
Ruby != Rails.
But Ruby gained an huge increase in popularity with Rails
Readable syntax
exit unless "restaurant".include? "aura"
You can try to take this interactive online tutorial (15 minutes) to see if you like the syntax.
Ruby is a general-purpose scripting language which has been incorporated into web design, and PHP is a language created for use in web design. (that's not a pro or con for either, merely a point of clarification)
If you already have experience scripting with using Ruby, it's easy to take the next step and incorporate it into your web design (as a corollary, it's also easier to pull Ruby code out of your web design and test it as a standalone script)
For many people/projects, the differences aren't monumental enough to warrant starting over with a new system. I'm somewhat of a Ruby evangelist but I would have to say if you already know PHP well, you will likely do better to stick with what you know. Certainly do not completely re-write a working PHP web application from scratch in Ruby without a lot of thought. This is a source of frustration for a lot of people (as you have probably read in your aforementioned rants) that can unfairly leave a bad taste in your mouth about a language or framework
Ruby is relatively new.
Therefore most tutorials using Ruby are using the latest best practices.
It does a lot of things differently to other languages, so it's a language you either love or hate. I personally am not a fan of it, and I'm sure a Ruby fan will come along soon and give a long list of advantages. And shortly after that, this question will be closed as subjective.
Ruby block is totally awesome!
You can create a DSL ontop of it and improves code readability which you can not achieve with anonymous function. One trivial example is like this:
def it(expect)
yield expect
end
it 'should do as I want it to be' do |this|
puts this
end