![]() |
| Languages compared |
|
pmeserve
HostMySite Tech
|
Here's an idea. Post some short code snippets in your language of choice, and then others can rewrite the code in whatever their favorite is. Let's say a max of 15 or so lines for the original snippets. I'll start with Ruby:
Output: Ruby is full of beautiful code PHP is full of spaghetti code Perl is full of unreadable code Points awarded for clarity, brevity, or whatever else you may value in your language |
||||||||||||||
|
|
|||||||||||||||
|
andystops
|
Ok Heres the same code in CF. I did a cross between scripted and tagged so it gives a nice balance.
Output: Perl is full of unreadable code. CF is full of taggy but clear code. PHP is full of spaghetti code. Pretty similar to that of others and especially C based languages. but for many programmers it is easy to see where code begins and ends. |
||||||||||||||
|
|
|||||||||||||||
| Well, I have to say, I used to be a big fan of Rails, but... |
|
comprug
Forum Regular
|
I used to be a big fan of rails, and still am, but I don't see any reason to move from cldfusion as it is just as maintanable with CFCs and that styff, and if you want a MVC framework you can use CF on Wheels. As for Ajax, there's the Yahoo UI library which is just as good, and the Script.aculo.us libraries and prototype libraries which RoR uses can be used for any language. and like andy stops said, it DOES make sense to see where code ends, and that stuff.... Now for the languages compared... Try this .......
|
||||||||||||||
|
|
|||||||||||||||
|
cspencer
|
At the risk of putting all other languages to shame, here's a little Python ;)
|
||||||||||||||
|
|
|||||||||||||||
|
pmeserve
HostMySite Tech
|
OK, since no one else was man enough, this is how bad it is in PHP:
Yes, that's a completely ugly/almost incomprehensible callback function to be able do a sort on an array of arrays(array of hashes in Ruby) |
||||||||||||||
|
Last edited by pmeserve on Fri Jun 16, 2006 7:01 pm; edited 1 time in total |
|||||||||||||||
|
cspencer
|
Javascript is an under-appreciated language.
|
||||||||||||||
|
|
|||||||||||||||
|
pmeserve
HostMySite Tech
|
Hah, Python ties Ruby in lines of code - I think I'd just about have to give it the edge in clarity there too. One question I have is, does that sorted function have the proper ability to sort based on an element of a complex object. i.e. in the original, I could add a third element to the hashes, like :year_created => 1995, and then just change the sort to say languages.sort_by { |lang| lang[:year_created] }
This was the worst part about using PHP, and I was actually surprised that CF seems to have a nice multi-dimensional sort function that can do that Update: And where's the Javascript sort? |
||||||||||||
|
|
|||||||||||||
| Let's try this.... |
|
comprug
Forum Regular
|
Now in JSP
No sort, but no too bad. Also, sort may exist, or this code may be wrong, especially the &'s because I have only dabbled with JavaServer Pages. |
||||||||||||||
|
|
|||||||||||||||
|
cspencer
|
A sorted(a,b) call basically does a.__cmp__(b), so it'll work fine as long as a.__cmp__ knows how to handle b. For Python's base types, this is well defined. In my code, I compare tuples, which know to compare the first element, then the second if the first are equal, then the third if the second are equal, etc. You can also override this by giving sorted() your custom compare or key function. For example, if I have a list of tuples:
I could sort by year using either:
I got lazy
|
|||||||||||||||||||||
|
|
||||||||||||||||||||||
|
pmeserve
HostMySite Tech
|
Here's the IP validate code in Ruby. Probably could be nicer, but I think it's pretty readable. The collect part is to convert the split/exploded string parts from strings to INTs for later comparison
And the sort is the whole fun of the first one comprug! PHP was a complete pain to implement the sort, and given that that's a pretty standard thing to want in a language I think it reflects badly on PHP. That said, I would kill for a PHP strtotime equivalent in Ruby Well looks like pretty good coverage so far, who's gonna step up and do Perl and .NET? I won't even suggest Java... |
||||||||||||||
|
|
|||||||||||||||
| As you can tell I'm a complete novice |
|
comprug
Forum Regular
|
A couple of important things....
1). as you can tell i'm a complete novice... I just geussed on the JSP, and I didn't even use arrays corectly... I'm also a novice at PHP, and many would also probably conside me a novice at CF too...... What do you think of the JSP? it's not actually that bad... I actually tried to test out my JSP code on my old Linux Builder Plus (stil has JSP) but it gave me a 503 2). I probably also shoudl have used the levenshtein() function for the validating of IPS, because it senses the % difference in a string from the specified or existing string/float. 3). There are so many functions in one language that you can find in others, but not the one you use, yet the one you use has an advantage. A prime example is the levenshtein() strtotime() and shell_exec(). I really wish I could execute shell in coldfusion so I could use image magick, but instead I have to post to a php script which can be a huge security risk.... I unsuccessfully lobbied to get cfexecute...... It annoys me so much.. That's why they should make CML (combined markup language) combining the best functions from all languages. Allthough, I do have to say that I really do liek CF's Contains operator rather than having to go through strpos() in PHP or grep(). Although CF has is meant for businesse in particular. It has many functiosn PHP doesn't have like Currency conversion and that stuff... I also wonder if Ruby/PHP has module that could rival cfgraph.... |
||||||||||||
|
|
|||||||||||||
|
pmeserve
HostMySite Tech
|
I really have no familiarity with JSP. It seems interesting, but at this point I'd rather try to focus on expanding my meager knowledge of the languages I do know. Jack of all trades type of thing...
If I was going to generalize a lot, I would say: - php has a function for just about anything you'd ever want to do(internally) - cf has all sorts of high-level stuff tacked on to let you create certain really amazing things(mainly end-user) very easily - ruby is incredibly intuitive and hits home runs on a lot of the basics(anything from switch statements with ranges to a really comprehensive and understandable object model - Rails does crazy things like adding and changing built-in Ruby object methods for ints and dates...I don't think you'll ever have something like that in CF) |
||||||||||||
|
|
|||||||||||||
|
cspencer
|
Here's the equivalent Python code:
|
||||||||||||||||
|
|
|||||||||||||||||
|
pmeserve
HostMySite Tech
|
Python definitely looks like good stuff to my eyes. The one thing that freaks me out is the whole "identation as syntax" thing. It seems in certain ways like a good idea, but just having to deal with Ruby hating on my line breaks was world-shaking enough
|
||||||||||||
|
|
|||||||||||||
| An ideal language.... UFPL |
|
comprug
Forum Regular
|
This is what I think would be the ideal programming language for this solution and how it would accomplish this situation. First of all, I would like to say that my language is called UFPL (User Friendly Programming Language). UFPl Statements start with
UFPL: If you want to output that without executing code you do this: ~UFPL:~ ~~ escapes aything. So this is how I would accomplish this with UFPL, how it should be accomplished:
Produces: CF is full of taggy, but organized code PHP is full of complete, but spaghetti code Perl is full of unreadable code Python is full of ok code Ruby is full of beautiful, but weird code JSP is full of obsolete code Javascript is full of nice, but weird code Lasso is full of unknown code Java is full of maintanable in 1000 years code Asp.net is full of ok code UFPL is full of English code the basics of UFPL are the following six: 1). Only use quotations for output 2). Do not worry about what datatype a variable is... (e.gints floats etc... just output like cfdump in coldfusion) 3). Use english terms such as i and then just like Coldfusion 4). put dashes before actions so it doesn't confuse it as variable names, operators or output or arrays 5). Use 's instead of dots for sub classes and variables in a structure as shon above with the help of lang's name 6). end ends statements and variables and arrays and ifs and lops and that stuff. every function or variable must have and end. if statements end at the end of the statement block This is the IP code:
Produces: can't be sure about ip, please log in again test passes What do you think of UFPL. If I actually had time (enough time to create a language that was open Source) I would create ti exactly like that. Thanks!! |
||||||||||||||||
|
|
|||||||||||||||||
| Languages compared |
|
||
|


