I have seen many PHP improvement proposals over the years. I am really glad people are doing such things. But I would like to address something that seems a bit wrong-headed to me, that is common to many of these proposals.
PHP is a verbose language, it is known. It is not a bug, it is a feature. Yes, some languages like to make their source code look like it was gzip-compressed, and have one or two-character symbols for everything. PHP is not among those, and I don't see how writing "fn" instead of "function" really helps. Are you so lazy as to type "function"? Get a decent completing editor, it'll do it for you. But code saying "protected function sayHello()" is much better for everybody that one saying "pr fn sH()". Same goes for syntax like "!_->" - it looks like cartoon "expletive deleted" sequence, not like a readable code. PHP is not APL, it should be obvious to a reasonably knowledgeable person what goes on there.
The idea of space-as-syntax, the most known implementation of which is of course Python, has its advantages and disadvantages. I admire the cleanness of good python code, and and the same time I am greatly annoyed when I have my code break because there's some space instead of tab or tab instead of space or extra space somewhere where it is not obvious. But I'd be interested to see people try out "PHP with Python indentation syntax" and see how it works for them. I don't see it a big difference but would be an interesting idea to play with.
and the same time I am greatly annoyed when I have my code break because there's some space instead of tab or tab instead of space or extra space somewhere where it is not obvious.
I have to say, I love this. I often do website work for clients and it's so incongruent, that switching over to Python where the indentation is perfect every time is like programming from a cloud. Or some better analogy that means "it's nice".
WOW, I'm on hackernews, wow! I completely agree on not shortening array, object, private, public, etc. I reached a similar decision a while ago, but didn't get around to fixing the docs.
I like shortening fn though, as it often makes the difference if an expression containing an anonymous function can fit on one 80 character line or not.
About the "!_->" syntax in the validation part of the function definition. Recently I've decided to remove the entire validation part, because the syntax is too specific and weird. I still like the defining of arguments on top of the function because it removes duplicate argument names between docblocks and code. The idea of validation together with the argument defintion is still sound i think though.
"I am greatly annoyed when I have my code break because there's some space instead of tab or tab instead of space or extra space somewhere where it is not obvious."
I don't know if I'm the only one, but I hate with passion this trend to remove syntax from a language and call it an improvement. It may be easier to code, but the code you produce is often more cryptic and harder to maintain. The aspect of the maintainability of a language is often disregarded even tough it's a very important aspect. That project is a very good example of this. Sacrificing readability for a few keystroke is never a good trade-off.
Personally, I completely agree. Code is written once and read often, so when working with any codebase where contributors > 1, readability should win over writability every time.
This should not be an argument against language constructs which make languages more expressive, but there seems to be a trend where as languages move toward the functional end of the spectrum, they take on more and more terse and cryptic syntactical structures.
I've always felt that good code should read like a book. This can be reconciled with prefix notation, but not with overloading odd characters as operators.
With a passion? Kind of over the top don't you think? Snow is just a tool like php is just a tool. We're all programmers just trying to make development easier for ourselves and hopefully others. I don't know how anyone can hate any aspect of programming with a passion. It's our modus to find things we dislike and we write tools to prevent us from ever having to do them again.
I think the reason this is getting negative/poor feedback is because the SAT analogy does not hold - Snow:PHP::CoffeeScript:JavaScript
JavaScript is a great language with debatable syntax. CoffeeScript works because it clarifies the beauty in the language. Snow doesn't do this for PHP because there isn't much beauty underlying the syntax to begin with.
But the real reasons I use Coffee script are the features it adds to the language: list comprehensions, splats, existential operator, severely concise class syntax.
And I don't see this offering any features that are as useful as those. The Snow code looks uglier, I think, than the PHP code. But if it looked uglier and gave me extra features (like, for instance, splats, comprihensions, improved slicing and range syntax, etc), I'd still probably use it.
The whole journey of trying to "fix" PHP has indeed seemed difficult. Mostly because so much information is pushed to the syntax of the language. Where in python the "." operator is used both to designate namespace, calling methods and calling "static" methods, PHP has three different operators "\", "->" and "::". Has it been worth it? Personally: A big yes, thinking about languages is fun. Practically: When it's complete, I think I will like it better than PHP, but still prefer a lot of other scripting languages like Coffescript, Lua, Python, etc.
I get abbreviating function to fn since the import part is the name, it is very common, and a lot of languages do it. I think abbreviating private is a mistake. It is important in itself and should have attention called to it.
Speaking of readability: Just `pri` as the constructor?
When having just a quick glance at code I want to know which part does what. Function names help, even if it is __construct.
And the @str title=null line above the class seems very odd.
Depends on the languages you're familiar with... fn is common in some areas, _ is a popular "default variable", -> I see as an interesting addition although it would be equivalent to empty(_).
What I'm not sure about is @arr (why not @array?) and [] instead of {} for a map...
I'm not sure if it's beautiful, but it's definitely an interesting shortcut for common operations and I could immediately see why it's useful and already remember the syntax for it. I like it and the author seems to like it too, not everyone has to agree of course ;)
As something of a glorified preprocessor, there is a limit to how much it can "make the language better". However, they will probably be able to get a bit of hacker mileage out of code generation, and I can see how you could add features which would be handy (such as first-class anonymous functions; though good luck making that look like "idiomatic PHP code"). It is too bad, however, that they didn't decide to make HTML tags first-class entities in the language; although, of course, this is all vaporware at this point.
Anyone who is interested in new languages specifically designed for web programming should also check out: http://www.impredicative.com/ur/
>I can see how you could add features which would be handy (such as first-class anonymous functions; though good luck making that look like "idiomatic PHP code")
Strip the comments from the PHP code and there isn't a drastic difference in size (as the snow example lacks comments), other than that, the PHP example is more readable. /shrugs
-- w/ Single-line foreaches, exceptions, and ternary operators: 34 Lines
So if we use the same formatting, the PHP is only one line longer, and 5 of the lines are just end-braces.
Now, taking my condensed PHP, and the Snow code, and converting 4 spaces to a tab, the filesizes are:
Snow: 746b
PHP: 847b
Using a lazy comparison: 12% less code, roughly the same number of lines.
I'm with you - I don't see how using a completely different syntax & complicating your toolchain is worth it to save a handful of characters when typing. Maybe more example code (2k-3k lines) would help.
This would allow us to do things that aren't native to PHP but still have something much easier. Having strings, integers and other types used as objects (with a solid proxy syntax to the native functions) would be the first (and best) step forward.
I've said it once and I'll say it again: if you're going to compile down to a language, support macros. CoffeeScript tries to make Javascript better, but I personally prefer Javascript's syntax. That's not to say CS doesn't have its benefits for many people, but one of the only things missing from Javascript is macros, so CS is pretty much worthless to me.
After spending countless hours in lisp and javascript, php leaves a lot to be desired. One of the things I do not desire is a language of equal power with a completely different syntax. Syntax is meaningless if it doesn't allow greater power.
Honestly, it's bad enough that CoffeeScript is so prevalent. I understand why it's around and why people like it, but I don't prefer it to pure JS...and I'd rather the trend not spread to other languages.
What would be cooler is to use something like this as a basis to generate idiomatic php, python, perl or ruby. Let people sketch out their initial ideas in a common language, then compile in to a starter php project, or python project, etc.
Honestly I fail to see a more readable thing, having experience with PHP it is really hard to me to read the snow code. A lot of the syntax just doesnt make sense to me.
There is also another thing that annoys me, the significant whitespaces, that is something I do not like in python (while I like the rest of it, the indentation instead of brackets is annoying), yes I agree that indented code is more readable, and I like to read indented but I like to write my code without caring for indentation and fix it after it is doing what I want (read: tell my IDE to indent it, brackets help on that).
The replacement of .= for %= is just added confusion there is really no gain, and the return for <- seems just wrong looks like just a way to avoid using characters.
Dropping the semicolons doesnt make much difference to me, but being used to them it could be a problem, when writing in languages that dont require them I write them on habit leading to a long list of syntax errors.
Warning personal rant:
Why do people hate java like syntax and brackets WHYYYYYYYYYY? Whats wrong with brackets honestly???
PHP does have a big advantage, it's unbiquity on low-cost web hosts that no other language can match. The downside is having to deal with PHP itself.
I'd like a platform of PHP-done-right but compiles to a set of .php files I can deploy to any webhost. I don't think this new language is it, but I'm happy to see developments.
This is syntactic sugar at best; other languages such as Python are cleaner and are more performant. Facebook's efforts to compile PHP to C++, HipHop, demonstrate this need, and in my opinion, this project is a step in the wrong direction.
PHP was great for its time, but sometimes you have to let grandpa go.
[+] [-] smsm42|14 years ago|reply
PHP is a verbose language, it is known. It is not a bug, it is a feature. Yes, some languages like to make their source code look like it was gzip-compressed, and have one or two-character symbols for everything. PHP is not among those, and I don't see how writing "fn" instead of "function" really helps. Are you so lazy as to type "function"? Get a decent completing editor, it'll do it for you. But code saying "protected function sayHello()" is much better for everybody that one saying "pr fn sH()". Same goes for syntax like "!_->" - it looks like cartoon "expletive deleted" sequence, not like a readable code. PHP is not APL, it should be obvious to a reasonably knowledgeable person what goes on there.
The idea of space-as-syntax, the most known implementation of which is of course Python, has its advantages and disadvantages. I admire the cleanness of good python code, and and the same time I am greatly annoyed when I have my code break because there's some space instead of tab or tab instead of space or extra space somewhere where it is not obvious. But I'd be interested to see people try out "PHP with Python indentation syntax" and see how it works for them. I don't see it a big difference but would be an interesting idea to play with.
[+] [-] SquareWheel|14 years ago|reply
[+] [-] runekaagaard|14 years ago|reply
I like shortening fn though, as it often makes the difference if an expression containing an anonymous function can fit on one 80 character line or not.
About the "!_->" syntax in the validation part of the function definition. Recently I've decided to remove the entire validation part, because the syntax is too specific and weird. I still like the defining of arguments on top of the function because it removes duplicate argument names between docblocks and code. The idea of validation together with the argument defintion is still sound i think though.
[+] [-] user2459|14 years ago|reply
A good editor will show you that too.
[+] [-] HoLyVieR|14 years ago|reply
[+] [-] rowborg|14 years ago|reply
This should not be an argument against language constructs which make languages more expressive, but there seems to be a trend where as languages move toward the functional end of the spectrum, they take on more and more terse and cryptic syntactical structures.
I've always felt that good code should read like a book. This can be reconciled with prefix notation, but not with overloading odd characters as operators.
[+] [-] andybak|14 years ago|reply
[+] [-] user2459|14 years ago|reply
[+] [-] lunaru|14 years ago|reply
JavaScript is a great language with debatable syntax. CoffeeScript works because it clarifies the beauty in the language. Snow doesn't do this for PHP because there isn't much beauty underlying the syntax to begin with.
[+] [-] encoderer|14 years ago|reply
But the real reasons I use Coffee script are the features it adds to the language: list comprehensions, splats, existential operator, severely concise class syntax.
And I don't see this offering any features that are as useful as those. The Snow code looks uglier, I think, than the PHP code. But if it looked uglier and gave me extra features (like, for instance, splats, comprihensions, improved slicing and range syntax, etc), I'd still probably use it.
[+] [-] runekaagaard|14 years ago|reply
[+] [-] maratd|14 years ago|reply
I disagree. To each his own, I suppose. PHP inherited it's syntax structure from C, the language it's written in. Would you say that C is ugly?
[+] [-] danielhunt|14 years ago|reply
[+] [-] protomyth|14 years ago|reply
[+] [-] badboy|14 years ago|reply
And the @str title=null line above the class seems very odd.
[+] [-] orblivion|14 years ago|reply
[+] [-] zalew|14 years ago|reply
uhm, beautiful
[+] [-] viraptor|14 years ago|reply
What I'm not sure about is @arr (why not @array?) and [] instead of {} for a map...
I'm not sure if it's beautiful, but it's definitely an interesting shortcut for common operations and I could immediately see why it's useful and already remember the syntax for it. I like it and the author seems to like it too, not everyone has to agree of course ;)
[+] [-] ma2rten|14 years ago|reply
[+] [-] ezyang|14 years ago|reply
Anyone who is interested in new languages specifically designed for web programming should also check out: http://www.impredicative.com/ur/
[+] [-] mcantelon|14 years ago|reply
PHP added anonymous functions in 5.3.
http://php.net/manual/en/functions.anonymous.php
[+] [-] ars|14 years ago|reply
[+] [-] wingspan|14 years ago|reply
[+] [-] stevebakh|14 years ago|reply
[+] [-] whichdan|14 years ago|reply
PHP: 66 Lines
- w/o PHPDoc: 45 Lines
-- w/ Single-line foreaches, exceptions, and ternary operators: 34 Lines
So if we use the same formatting, the PHP is only one line longer, and 5 of the lines are just end-braces.
Now, taking my condensed PHP, and the Snow code, and converting 4 spaces to a tab, the filesizes are:
Snow: 746b
PHP: 847b
Using a lazy comparison: 12% less code, roughly the same number of lines.
I'm with you - I don't see how using a completely different syntax & complicating your toolchain is worth it to save a handful of characters when typing. Maybe more example code (2k-3k lines) would help.
[+] [-] orblivion|14 years ago|reply
[+] [-] jarek|14 years ago|reply
[+] [-] antihero|14 years ago|reply
[+] [-] afsina|14 years ago|reply
[+] [-] kemo|14 years ago|reply
Class definitions as well:
[+] [-] orthecreedence|14 years ago|reply
After spending countless hours in lisp and javascript, php leaves a lot to be desired. One of the things I do not desire is a language of equal power with a completely different syntax. Syntax is meaningless if it doesn't allow greater power.
Honestly, it's bad enough that CoffeeScript is so prevalent. I understand why it's around and why people like it, but I don't prefer it to pure JS...and I'd rather the trend not spread to other languages.
One possible candidate would be Pharen, though: http://scriptor.github.com/pharen/.
[+] [-] krsunny|14 years ago|reply
[+] [-] chc|14 years ago|reply
[+] [-] alexkappa|14 years ago|reply
[+] [-] mgkimsal|14 years ago|reply
[+] [-] h2s|14 years ago|reply
[+] [-] runekaagaard|14 years ago|reply
[+] [-] LoneWolf|14 years ago|reply
There is also another thing that annoys me, the significant whitespaces, that is something I do not like in python (while I like the rest of it, the indentation instead of brackets is annoying), yes I agree that indented code is more readable, and I like to read indented but I like to write my code without caring for indentation and fix it after it is doing what I want (read: tell my IDE to indent it, brackets help on that). The replacement of .= for %= is just added confusion there is really no gain, and the return for <- seems just wrong looks like just a way to avoid using characters. Dropping the semicolons doesnt make much difference to me, but being used to them it could be a problem, when writing in languages that dont require them I write them on habit leading to a long list of syntax errors.
Warning personal rant: Why do people hate java like syntax and brackets WHYYYYYYYYYY? Whats wrong with brackets honestly???
Sorry just had to say that.
[+] [-] billpg|14 years ago|reply
PHP does have a big advantage, it's unbiquity on low-cost web hosts that no other language can match. The downside is having to deal with PHP itself.
I'd like a platform of PHP-done-right but compiles to a set of .php files I can deploy to any webhost. I don't think this new language is it, but I'm happy to see developments.
[+] [-] pork|14 years ago|reply
[+] [-] ericfrenkiel|14 years ago|reply
PHP was great for its time, but sometimes you have to let grandpa go.
[+] [-] mcantelon|14 years ago|reply
[+] [-] unknown|14 years ago|reply
[deleted]
[+] [-] rman666|14 years ago|reply
[+] [-] hellerbarde|14 years ago|reply