Beta
×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Facebook Introduces Hack: Statically Typed PHP

Unknown Lamer posted about 6 months ago | from the sml-and-php-fall-in-love dept.

PHP 230

alokmenghrajani (2602135) writes with news of Facebook's new Open Source language, Hack. Quoting: "Today we're releasing Hack, a programming language we developed for HHVM that interoperates seamlessly with PHP. Hack reconciles the fast development cycle of PHP with the discipline provided by static typing, while adding many features commonly found in other modern programming languages. ... Traditionally, dynamically typed languages allow for rapid development but sacrifice the ability to catch errors early and introspect code quickly, particularly on larger codebases. Conversely, statically typed languages provide more of a safety net, but often at the cost of quick iteration. We believed there had to be a sweet spot. ... Hack has deep roots in PHP. In fact, most PHP files are already valid Hack files. ... Our principal addition is static typing. We have developed a system to annotate function signatures and class members with type information; our type checking algorithm infers the rest. Type checking is incremental, such that even within a single file some code can be converted to Hack while the rest remains dynamically typed. ... If a function parameter or class member does not have an explicit type annotation, the type checker considers its type to be dynamic, and it does not check the type of that value." In addition to static typing, they've introduced proper closures that capture the lexical environment, generics, collections, and array shapes. The Hack website has more details. There's a fairly complete language manual, tools to infer types in PHP source and annotate the code, and source available under the PHP license.

cancel ×

230 comments

Sorry! There are no comments related to the filter you selected.

English? (0)

Anonymous Coward | about 6 months ago | (#46537623)

Can someone please convert the summary in english, with basic explanations?

Re:English? (2, Informative)

Anonymous Coward | about 6 months ago | (#46537663)

FaceBook is developing an in-house version of PHP that adds optional static typing and some other features.

Re:English? (4, Funny)

Anonymous Coward | about 6 months ago | (#46537745)

Can someone please convert the summary in english, with basic explanations?

My interpretation of the summary is: Facebook has sunk a lot of investment into a turd, and now they've determined that that turd needs polishing.

Re:English? (5, Insightful)

MightyMartian (840721) | about 6 months ago | (#46537889)

My interpretation is that they've put a lot of work turning PHP into Java or C. Why go through all this effort when they could simply used one of the C-like strongly typed languages is beyond me. All that effort could have been put into creating a PHP-to-Java converter or something along those lines.

But hey, it's Mark Zuckerberg's bazillion dollars. If he wants to tape testicles on a eunuch, be my guest.

Re:English? (5, Interesting)

alokmenghrajani (2602135) | about 6 months ago | (#46537933)

Hack is more than turning PHP into Java or C. Java's type system is way different than C's (there are no objects in C). Hack's is different than Java's because it uses a type inference system. It also type checks incrementally, which allows the quick edit/save/reload cycles web developers are used to.

Re:English? (2)

Wootery (1087023) | about 6 months ago | (#46538219)

Why go through all this effort when they could simply used one of the C-like strongly typed languages is beyond me.

Because they already have a huge PHP codebase. That said, Twitter moved from Ruby to Scala for their back-end [theregister.co.uk] ; it seems it can be done. I suspect Facebook have more of a lots-of-programmers problem: they all know PHP, and they might not all know, say, Scala.

to creating a PHP-to-Java converter or something along those lines.

You mean take PHP source and translate it into readable, maintainable Java source? That's all but impossible. They're very different languages, and source-to-source translators tend to produce pretty unreadable code when faced with that kind of task. A human wouldn't design a PHP program the same way she'd design the same program in Java. Without some terribly impressive AI, there's really no way around this.

They could have translated PHP into totally-unreadable Java and then (run that through javac and) run the result on the JVM, sure, but then you're really just creating a rival PHP implementation. (Look like two [github.com] separate [caucho.com] projects have done just that, though, and apparently had pretty good results, outperforming the official PHP interpreter. All that says is that the official PHP interpreter is crap, which I think we all knew anyway.)

Re:English? (5, Informative)

Chris Graham (942108) | about 6 months ago | (#46538261)

For pragmatic-minded people, PHP is an extremely productive language to work in. No compiling, or waiting for compiling, no object files to mess with or get out of sync, and still relatively good speed. It really removes a lot of inconvenience between the programmer writing code and testing it. Despite what the detractors say, I've always found it a joy to work in (and I have worked in many languages).

The down-side has always been that the language also had many sloppy characteristics. Modern PHP has cleaned up a lot of the language design errors, and static typing is extremely useful for reducing quantity of bugs (I know this as I developed a PHP fork that enforces this and it's saved me many many times over the years). HHVM adds much more speed, so that really complex modern social webapps are really needing. There are still many small inconsistencies in the language, but it's not a big deal given the other advantages.

Re:English? (4, Interesting)

MightyMartian (840721) | about 6 months ago | (#46538385)

PHP is productive in that it can work as a fast prototyping language. Even I recognize that, and in fact use it as such.

Where it falls down is that it doesn't enforce the kind of discipline that better languages do. It is well and truly the BASIC of the 21st century.

That's not to say you cannot write good code in PHP. I do strive when I have to work in PHP (which is more than I would like) to write well-formed code, use newer language structures and so forth. But still, and maybe it's because I like the crutch, I just feel better coding in statically typed languages, and to be pretty blunt, if PHP is evolving into that kind of language, there are far better languages out there.

Re:English? (0)

Anonymous Coward | about 6 months ago | (#46538443)

There are still many small inconsistencies in the language, but it's not a big deal given the other advantages.

The thing is, there are dozens of other languages which have those same advantages, but don't have the legacy of basically being patched together from disparate ideas by people who don't think things through properly.

Re:English? (1)

Marginal Coward (3557951) | about 6 months ago | (#46537791)

Can someone please convert the summary in english, with basic explanations?

The basic idea is that they've hacked PHP into something called "Hack" by turning it into something PHP was never intended to be. Yet Hack is still backwards-compatible with PHP. Presumably, this is to avoid the need to convert Facebook's large base of sluggish PHP code into some other language which was designed from the start for run-time efficiency. Instead, they can make incremental efficiency changes to their code base to make it run as if it had been written in a more efficient language in the first place. Much saving of expensive hardware and power will ensue.

If all you've ever used is a hammer, everything looks like a nail. But if you eventually find yourself faced with a screw and you're really smart, you can just hack your hammer into a screwdriver rather than hammering in the screw like those not-so-smart folks who find themselves using the wrong tool do.

Re:English? (1, Troll)

Minwee (522556) | about 6 months ago | (#46537997)

Team Zuck has been trying to find something that is more of a hack than PHP, but couldn't. So they invented one.

Re:English? (2)

K. S. Kyosuke (729550) | about 6 months ago | (#46538009)

convert the summary in english

They reinvented soft typing. ;-)

Spy (2)

Sigvatr (1207234) | about 6 months ago | (#46537641)

Obviously a backdoor for the NSA 8)

static typing is awesome (1)

Anonymous Coward | about 6 months ago | (#46537649)

Many years ago I was a fierce opponent of static typing and loved the power of Obj-C and Python (was a NeXT/Mac head.) C++ and Java were crap (especially since Java didn't have type variables at the time.) Then I tried Haskell and my mind was duly blown. Now I'm a huge proponent of static typing, even if I still can't stand Java and avoid C++ unless necessary. IMHO Scala is the current sweet spot for statically typed general purpose programming language.

Re:static typing is awesome (2, Interesting)

Anonymous Coward | about 6 months ago | (#46537757)

that's great.. but the reason Scala is so sweet is that it does type inference. This means all your code is purposely typed even though you don't have to type all the tries (AC doesn't have to apologize for puns). This is going to be a nightmare where your last five dynamic functions his the bug that kills you.

It's so sad that the fact that Mark got extremely lucky means that all this excellent computer science is wasted on a cesspool like PHP.

Re:static typing is awesome (1)

ebno-10db (1459097) | about 6 months ago | (#46538065)

the reason Scala is so sweet is that it does type inference

Haskell also does type inference.

Re:static typing is awesome (2)

goombah99 (560566) | about 6 months ago | (#46537763)

Many years ago I was a fierce opponent of static typing and loved the power of Obj-C and Python (was a NeXT/Mac head.) C++ and Java were crap (especially since Java didn't have type variables at the time.) Then I tried Haskell and my mind was duly blown. Now I'm a huge proponent of static typing, even if I still can't stand Java and avoid C++ unless necessary. IMHO Scala is the current sweet spot for statically typed general purpose programming language.

I wish there was just some voluntary static typing in python. By this I don't mean run time voluntary type checking. that makes it slower. No I mean a pre-run time filter that optimizes the .pyc to the extent it can.

Re:static typing is awesome (4, Informative)

Anonymous Coward | about 6 months ago | (#46537927)

Let me introduce you to https://en.wikipedia.org/wiki/Cython

You are welcome.

Re:static typing is awesome (0)

Anonymous Coward | about 6 months ago | (#46537773)

You should try http://nimrod-lang.org, the features you mentioned without the jvm overhead. I'm using it for mobile.

nimrod (0)

Anonymous Coward | about 6 months ago | (#46538323)

>indentation is done with spaces only
Nope, killed my interest.

Dynamic typing proponents are not awesome (1)

Anonymous Coward | about 6 months ago | (#46537783)

Many proponents of dynamically typed language say "Statically typed languages suck.", while they are only qualified to make the statement "The statically typed languages I know suck.".

People tend to compare modern languages they know that have features such as first-class functions and comprehensive standard libraries with the dinosaur languages they know such as Java, C and C++. For some unknown reasons the former tend to be dynamically typed and the latter are statically typed. Then they spread their bullshit opinions all over the internet.

Re:static typing is awesome (1)

Anonymous Coward | about 6 months ago | (#46537911)

Now I'm a huge proponent of static typing

There is a new language called Ceylon with a very interesting type system. It uses union and intersection types pervasively to fix some of the awkwardness with existing statically typed systems. It uses unions to prevent dereferencing null references at compile time; NullPointerExceptions (or its moral equivalent in whatever language) are impossible to express in Ceylon. The concept of a "principle type" for every expression simplifies type inference and makes it efficient. The notion of "non-denotable" types and their explicit exclusion from the language specification or implementation is also interesting.

It's not ready for prime time despite the 1.0 release version, and I'm no fanboi, but if you like static typing Ceylon is worth looking at.

Re:static typing is awesome (1)

ebno-10db (1459097) | about 6 months ago | (#46538077)

Actually that sounds a lot like Haskell.

BTW, why is it called Ceylon instead of Sri Lanka?

Re:static typing is awesome (1)

Bigbutt (65939) | about 6 months ago | (#46538199)

Misspelled Cylon.

[John]

Re:static typing is awesome (1)

ebno-10db (1459097) | about 6 months ago | (#46538091)

Then I tried Haskell and my mind was duly blown. Now I'm a huge proponent of static typing, even if I still can't stand Java and avoid C++ unless necessary.

While I have mixed feelings about Haskell as a whole, it's got the best damned type system I've ever seen. My advice to designers of new languages is just copy Haskell's type system.

Re:static typing is awesome (0)

Anonymous Coward | about 6 months ago | (#46538381)

Haskell's NIH version of SQL is tedious. Why didn't they just implement SQL?

Also, closures seem to me to violate the premise of static variables and fixed variable scoping. When you introduce closures into a language they are bound to cause all the same problems as global variables.

WTF (0)

Anonymous Coward | about 6 months ago | (#46537667)

Do all that work just for static typing?

Netcraft confirms it, facebook is dead.

Only PHP (0, Flamebait)

Anonymous Coward | about 6 months ago | (#46537671)

Only with PHP could static typing be considered a 'hack'

Use a real programming language, faggots!

Re:Only PHP (1)

maxrate (886773) | about 6 months ago | (#46537981)

I for one approve of your comment. -1 is an injustice.

So many bugs (5, Insightful)

ClayDowling (629804) | about 6 months ago | (#46537699)

So many of the bugs that have tripped me up over the years would have been solved by simply having static typing.

Re:So many bugs (3, Insightful)

Anonymous Coward | about 6 months ago | (#46537807)

Dynamic typing frees your mind to think about the problem at hand and the best solution to that problem, rapidly changing approach and methods as you learn from experience gained. I get sick of spending half my time dicking around with static types, casts, etc and spinning my wheels chasing down type errors when I could be progressing rapidly towards a solution. Unless I'm writing kernel code for a drive by wire system or something similarly life-and-death, I'll take dynamic typing any day and be done twice as fast, moving on to the next challenge. If absolutely necessary, once a final working codebase is established, it can be rewritten to take advantage of the additional lock-down offered by static types.

Re:So many bugs (5, Insightful)

MightyMartian (840721) | about 6 months ago | (#46537907)

It allows you to free your mind, express your inner coding monkey artist.

And then you get to debug...

Re:So many bugs (-1)

Anonymous Coward | about 6 months ago | (#46537935)

Wow, so much wrong with what you said. I hope to never use the code you wrote, or develop alongside you...

Re:So many bugs (0)

vux984 (928602) | about 6 months ago | (#46538019)

once a final working codebase is established

aka... never.

Especially if you wrote it "rapidly changing approach and methods as you went" and "moved on to the next challenge" as soon as it would occasionally run without crashing on you.

That's sounds like a recipe for well designed code, right?

it can be rewritten to take advantage of the additional lock-down offered by static types.

Not by you though. You'll leave unraveling the spaghetti you left behind for someone else.

Don't feel bad for 'them' though. It won't happen, they'll just ship your mostly working prototype and call it a day.

And if its not running well enough to ship, then yeah, they'll toss it and rewrite it but you'll be a distant memory by them.

Re:So many bugs (0)

MightyMartian (840721) | about 6 months ago | (#46538049)

I think this guy must have wrote the documentation system I was hired to debug about five years ago. Written in PHP in a very free-flowing (aka. spaghetti-like catastrophe), the guy charged the company about $20,000 bucks, and it cost them another $10,000 for me to basically scrap it and rewrite from the ground up.

There are far too many "programmers" like the parent poster, and PHP is the hurtful creature that allows them to persist.

Re:So many bugs (1)

kaiser423 (828989) | about 6 months ago | (#46538297)

I've written hundreds of thousands of lines of statically typed code and I'd say that at no point in my career, from programming noob in college to anywhere else did I ever spend more than 1-2% of my effort "dicking around with static types, casts, etc and spinning my wheels chasing down type errors when I could be progressing rapidly towards a solution", much less anywhere near half my time. That includes projects where I've done 1k+ SLOC in a morning to get proof of concepts out. I just don't see how static typing really slows anyone down unless your approach is to run a function, see what you get out and then hope that you can do something else with the returned object which is just ugly and slow in its own right. I guess that I just think differently than some; maintaining in my brain's working set what the objects I actually have in front of me are, and what they do and support is not that much overhead and doesn't detract from anything else.

Also, when I work with dynamically typed languages I tend to spend similar amounts of times if not more figuring out what really is and is not supported with this dynamic object in front me. I personally just don't see the speed up.

Re:So many bugs (2)

MightyMartian (840721) | about 6 months ago | (#46538461)

Usually the compiler will scream "Hey fuckwad, your integer array ain't a string! Error on line 205", and then you dutifully go correct the error. Much better than a dynamic language that happily takes your screwup seriously and you have to follow a debugger chain through half a dozen nested functions to find where you buggered up.

Re:So many bugs (1)

ebno-10db (1459097) | about 6 months ago | (#46538315)

I get sick of spending half my time dicking around with static types, casts, etc and spinning my wheels chasing down type errors

If you spend half, or any appreciable part of your programming time dealing with static typing issues, then you're doing something seriously wrong. Occasionally the compiler will be a pain in the ass about it, but most of the time static typing should require nary a thought. If it's otherwise, you're not thinking about types clearly. The static typing is there to catch you when you screw up. It also serves as useful documentation for the next poor schmuck that has to look at your code, and for good measure the compiler enforces the accuracy of this type of "documentation". If you're really too lazy to type "int" or "double", try a language with type inference.

Re:So many bugs (0)

Anonymous Coward | about 6 months ago | (#46538433)

You don't do any web programming, do you? It's all strings that need conversion to whatever and then back to strings.

Re:So many bugs (1)

beelsebob (529313) | about 6 months ago | (#46538439)

Dynamic typing frees your mind to think about the problem at hand and the best solution to that problem

Quite the contrary. It frees your mind to think about the problem incorrectly, then requires your mind to churn through many incorrect ideas before finally settling on the correct one. Meanwhile, static typing deals with a large chunk of correctness for you, and gets you to the correct solution faster by pointing out the errors before you hit them at runtime.

I get sick of spending half my time dicking around with static types, casts, etc

If you're casting, you're not thinking about the types correctly yet. Learn to code a bit better.

I'll take dynamic typing any day and be done twice as fast,

No, you won't. Because every time the static type checker points out an error, it's showing you something that's wrong, that is *going* to crash your program. It's just doing it faster than you would find out otherwise. Otherwise, you'd have to run your program, and discover that type error at runtime.

Re:So many bugs (2)

CastrTroy (595695) | about 6 months ago | (#46537883)

Yeah, with static typing, there's a whole class of errors that simply can't happen. Any time you lose from having to explicitly declare variable types, or casting variables to the correct time is easily saved by the fact that you don't have to write as many tests. Unless you aren't writing any tests, in which case, you have other problems.

Re:So many bugs (0)

Anonymous Coward | about 6 months ago | (#46538201)

I used to believe that too. Not anymore. Instead I use short functions, descriptive variable names and well defined API documents.

Please provide examples of these error classes.

Re:So many bugs (1)

Anonymous Coward | about 6 months ago | (#46538453)

Declare a variable, misspell it on use. A dynamic typed language such as Javascript will happily create a brand new variables (potentially obliterating an existing variable) in the global scope, and go on its merry way thus creating undefined behavior.

Have A Nice Day.

Re:So many bugs (2)

beelsebob (529313) | about 6 months ago | (#46538481)

Here's an example:
The null pointer dereference.

With a properly set up type system, you express one type as the non-null pointer. You then express a second type - the maybe type, which describes something that is maybe something else. Now you use the Maybe Pointer as the result of allocation. Now in order to use the pointer, you need to get it out of the Maybe or the type system will complain, which enforces that you actually check for null before dereferenecing. It proves that your program will never dereference null.

Obviously this is only one example, but yes, type systems really can eliminate entire classes of programming error. This is just one (particularly common) one that they can get rid of.

Re:So many bugs (1)

MoonlessNights (3526789) | about 6 months ago | (#46538491)

Obvious example:
-your data model has a function to get "n" entries from the data store
-someone passes in "five" (or "purple", array(5), whatever)
-an empty array is returned since the thing you passed in could not be evaluated as a numerical value (or you get a runtime exception of some sort, if you are lucky)

The problem here is that the caller is incorrect and the compiler would have told them that, had you specified that you required an int type.

So, instead of a 1-minute fix for a compilation error, it is potentially hours of hunting down why the program is providing incorrect results (since the actual problem is probably reported by a user due to a confusing result much further down the line).

Re:So many bugs (1)

MoonlessNights (3526789) | about 6 months ago | (#46538167)

I wish it were easier to explain that to less experienced developers (I remember being young and shared the common delusion that types were bad).

These days, it is intensely frustrating to work on a team with inexperienced developers who want to use all the "trendy" languages and frameworks only to get bogged down in constant re-writes or debugging once they realize that nobody can actually tell which parts of the project, if any, are "correct" (or even executed, in some cases).

When you point out that many of these problems are trivially decidable at compile time, they just dismiss you as being out of touch since "we don't compile anything before executing it, gramps."

Instead of listening to your argument, they just dismiss you for being old (you know, early 30s) and not understanding the "new" technology.

Re:So many bugs (1)

MightyMartian (840721) | about 6 months ago | (#46538479)

A goodly portion of the young developers don't really know what the word "compile" means.

hate the name (5, Insightful)

mr_mischief (456295) | about 6 months ago | (#46537707)

"Hack" as a language name? Really?

People are going to explain this at dinner parties. People who kind of understand that programming is more than being good at operating a computer as an end user but don't really know the difference between sysadmin, devops, programmer, business analyst, and DBA let alone what those roles really do are going to ask questions. Those questions will be things like "what kind of programming?", "what technologies do you use?", and "what are you working on right now?" The answer will be something about putting together a quick Hack program to change values in a database, and then it gets awkward.

Plus, did they consider at all how easily this will get confused with Haxe?

Re:hate the name (5, Funny)

swb (14022) | about 6 months ago | (#46537717)

"The answer will be something about putting together a quick Hack program to change values in a database"

I take it you don't get invited back to dinner very often.

Re:hate the name (2)

Xunker (6905) | about 6 months ago | (#46537753)

"I'm a hack hacker who hacks Hack."

Re:hate the name (0)

Anonymous Coward | about 6 months ago | (#46537949)

Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo.

Re:hate the name (0)

Anonymous Coward | about 6 months ago | (#46538027)

"I'm a hack hacker who hacks Hack."

I think you've got something in your throat.

*hands over a lozenge*

Re:hate the name (5, Funny)

pushing-robot (1037830) | about 6 months ago | (#46537771)

Hey, three focus groups chose this over "Kludge".

Re:hate the name (1)

c0d3g33k (102699) | about 6 months ago | (#46537789)

It shows they have a sense of humor, given the effort it must have taken to make a 'better PHP'.

Re:hate the name (1)

FuzzNugget (2840687) | about 6 months ago | (#46537831)

I agree, I'm just replying to undo the incorrect moderation I just did. Fucking phone UIs.

Think about why they really did it (0)

Anonymous Coward | about 6 months ago | (#46537839)

SEO purposes - to make anyone interested in computer security not find any of those 0days or exploit codes when things like "how to hack" or "become a hacker" are typed in google. Instead, some useless ass fork of PHP which offers static typing (WOW what a feature!) will show up in your search results and the security real hacker information will be at the very bottom of the barrel.

Well played NSA, and facebook, well played.

Re:hate the name (4, Insightful)

WillgasM (1646719) | about 6 months ago | (#46537947)

It's actually very clever marketing. Now everybody that searches "facebook hack" will get this as the first result. They get lots of hits for their new language and obfuscate any articles teaching people how to exploit FB accounts. Win-win.

Re:hate the name (0)

Anonymous Coward | about 6 months ago | (#46538031)

Talk about something other than your work with PHP at dinner parties.

Re:hate the name (0)

Anonymous Coward | about 6 months ago | (#46538221)

Haven't you heard? He's a chef.

Re:hate the name (2)

globaljustin (574257) | about 6 months ago | (#46538093)

this is my maxim: Geeks should not be allowed to name the things they create.

"Hack" as a name for a programming language is egregious. It's like naming your newborn baby "Wipe"

I wish my maxim weren't true, but it is.

Re:hate the name (2)

bitfarmer (219431) | about 6 months ago | (#46538211)

> "Hack" as a language name? Really?

Because "Brainfuck" was already taken.

Sarcastically Typed (5, Funny)

wisnoskij (1206448) | about 6 months ago | (#46537715)

We really need a sarcastically typed language. That would be truly awesome.

Re:Sarcastically Typed (1)

Pope (17780) | about 6 months ago | (#46537739)

def c$ as string(as.IF!)

Re:Sarcastically Typed (2, Interesting)

Sarten-X (1102295) | about 6 months ago | (#46537811)

I'm pretty sure that's Perl. You can define something first as a scalar, then refer to it as an array, because HA HA I WAS JUST KIDDING!

You can also take a single variable and make it behave entirely differently depending on context. As a scalar, it works fine, but if you try to refer to it as an array, rm -rf /.

Not saying you'd want to do those things, but you can.

Re:Sarcastically Typed (0)

Anonymous Coward | about 6 months ago | (#46537955)

Wait, if you try to refer to it as an array, it deletes Slashdot? Impressive.

Re:Sarcastically Typed (1)

Reapy (688651) | about 6 months ago | (#46537973)

Perl can be extremely frightening sometimes. Still useful though!

Re:Sarcastically Typed (1)

PhrostyMcByte (589271) | about 6 months ago | (#46537879)

Allow me to introduce you to C+= [github.com] and ArnoldC [github.com] .

Design by contract? (5, Insightful)

afidel (530433) | about 6 months ago | (#46537731)

This sounds a bit like layering design by contract on top of a typically dynamically typed language rather than being a strictly statically typed language. It's an interesting approach and would seem to achieve their goals of faster but more robust development.

So ... they re-invented Asp.Net? (0)

Anonymous Coward | about 6 months ago | (#46537737)

How is this different/better than Asp.Net?

Re:So ... they re-invented Asp.Net? (1)

CodeReign (2426810) | about 6 months ago | (#46537959)

ASP.NET requires a heavy application server.

As a Java EE developer I'd advocate the benefits of proper application servers/infrastructure but ASP/Java are slow to release languages. You need infrastructure and planning while PHP is a great language for systems that don't have huge reliance requirements and need the project done yesterday. (and even then obviously Facebook has managed to make it very reliable).

Additionally ASP.NET (with C# as you didn't specify) is statically typed. Even the "var" type is resolved at compile time to the base class of whatever it's first instantiation returns.

Re:So ... they re-invented Asp.Net? (1)

JDG1980 (2438906) | about 6 months ago | (#46538155)

How is this different/better than Asp.Net?

ASP.NET requires a Windows server. PHP (and presumably Hack) can be run on any cheap hosted Linux server with cpanel.

That said, ASP.NET/C# is a far better and more coherent development platform than PHP. But PHP's near-zero barrier to entry will keep it on top for the forseeable future.

Nope (4, Insightful)

Sarten-X (1102295) | about 6 months ago | (#46537769)

In fact, most PHP files are already valid Hack files.

No, no, no, and no.

The single biggest problem with PHP is the tendency for old code and old programmers to keep their bad habits around when moving to new projects. PHP lacked vital modern features (like static typing and namespaces) for so long, and it's evolved so many workarounds (like magic quotes), that programmers have learned the wrong way to accomplish basic tasks. Now they have a new language, supporting the right way to do these things... but the old and broken ways still work. Sure, there will be a few programmers that will use the new way and be thrilled about the good technique, but then time crunches will set in, and code reviews will be rushed (or nonexistent), and those old ways will creep in, bringing the bugs with them.

Backwards-compatibility with a broken language is a great way to improve a new language's adoption, and a terrible way to build a new language's reputation.

Re:Nope (1)

Anonymous Coward | about 6 months ago | (#46537877)

Seriously? Magic quotes aren't even in the language anymore. They were removed completely as of PHP 5.4.0. If you're going to troll, please at least do so with the relevant facts instead of outdated FUD.

Re:Nope (1)

Sarten-X (1102295) | about 6 months ago | (#46538113)

Fine. s/magic quotes/mysql_real_escape_string()/g... or if you prefer, preg_replace('/magic quotes/g', 'mysql_real_escape_string()', $post);

That's deprecated too, but I'd bet there's still folks out there clinging desperately to it and using it daily in production code.

Also, you should consider that I don't keep track of PHP's changes, because they'd have to change most of the language for it to be salvageable. I'm not trolling with outdated FUD; I'm arguing with one almost-outdated fact. It's almost outdated because PHP 5.3.8 is still distributed.

Re:Nope (0)

Anonymous Coward | about 6 months ago | (#46537975)

In what world is static typing a "modern feature"? Lol...

Re:Nope (1)

Sarten-X (1102295) | about 6 months ago | (#46538143)

The world of PHP.

Re:Nope (1)

narcc (412956) | about 6 months ago | (#46538029)

PHP lacked vital modern features (like static typing

Modern features like static typing.

Modern features like static typing...

Seriously?

Re:Nope (1)

Sarten-X (1102295) | about 6 months ago | (#46538123)

Your grasp of sarcasm is incredible.

Dynamic typing is a hack (1, Informative)

ArcadeMan (2766669) | about 6 months ago | (#46537805)

Ever tried to access 8-bit byte arrays and write them to a binary file in PHP? It's hell and it takes a lot of work to go around all the stupid dynamic typing.

Re:Dynamic typing is a hack (2)

narcc (412956) | about 6 months ago | (#46538101)

Ever tried to access 8-bit byte arrays and write them to a binary file in PHP?

Yes, I have.

It's hell and it takes a lot of work to go around all the stupid dynamic typing.

No, it's not. It was simple and painless.

Had you taken a few minutes to read the documentation, you wouldn't have suffered through "hell".

Maybe programming isn't for you? Have you considered a career more suited to your talents?

Re:Dynamic typing is a hack (1)

ArcadeMan (2766669) | about 6 months ago | (#46538149)

Instead of writing a flamebait reply, how about telling me how simple and painless you'd do that? Because all the examples and explanations I've found were nothing but "simple", they're all work-arounds for something that should be straight and simple.

Re:Dynamic typing is a hack (1)

narcc (412956) | about 6 months ago | (#46538311)

Because all the examples and explanations I've found were nothing but "simple"

You're either not very good at searching, terrible at programming, or both.

A quick look at the documentation and you'll find handy functions like fseek, fread, fwrite, pack, and unpack. It's easier than doing the same in Java, C#, or even C.

You won't run across any problems caused by dynamic typing. What strange and unusual approach did you take?

Re:Dynamic typing is a hack (1)

Minwee (522556) | about 6 months ago | (#46538505)

You won't run across any problems caused by dynamic typing. What strange and unusual approach did you take?

Posting on Slashdot about it, apparently.

hack for THE hack (0)

Anonymous Coward | about 6 months ago | (#46537817)

Trying to fix PHP is impossible just GIVE UP already!

Brillant! (0)

Megane (129182) | about 6 months ago | (#46537819)

So of all the languages they could have forked, they decided to fork PHP? [veekun.com] Okey-dokey.

Re:Brillant! (0)

Anonymous Coward | about 6 months ago | (#46538001)

Yeah, the language they've built a $7 billion company on that serves 17% of the species; PHP.

Not the first time they've done stuff like this either. For a while they were compiling PHP to C++ to reduce server load.

Re:Brillant! (1)

MightyMartian (840721) | about 6 months ago | (#46538301)

This is like justifying strapping a jet engine and wings to a Volkswagen beetle insisting that because it got you to the airport, well by God, it can get you airborne as well!

Sounds like a good band-aid for PHP codebases (3, Insightful)

PhrostyMcByte (589271) | about 6 months ago | (#46537835)

Every few months someone announces a new fad language despite them rarely bringing anything new to the table, or the new things they do bring not being significant enough to warrant switching from some other well-established one.

I'm actually happy with this one, because it serves an easier to justify purpose: migrating your existing PHP codebase and developers to something that is immediately better and familiar.

Ugly (1)

Njovich (553857) | about 6 months ago | (#46537925)

I guess it wouldn't hurt to have static typing in PHP, but for the love of god, why not just pick a more standard syntax?

Some of their examples:

?hh
function f1(): ?resource { ...
}

public function bar(): (string, string) {

Might look good in some languages, but in PHP I would really expect that type before the function name.

Of all the things to fix... (1)

Arancaytar (966377) | about 6 months ago | (#46537941)

I'd have thought the horrible global function namespace would have been a top priority.

Seriously [twimg.com] , what is this, C?

What about the performance on this beast? (0)

Anonymous Coward | about 6 months ago | (#46538017)

Is it different/same/odd compared to default PHP 5.5 or what? Surely benchmarks must matter a little bit for the big ol' faceborg..

Really... (0)

Ignacio (1465) | about 6 months ago | (#46538079)

With all the problems in PHP, ***this*** is the change they decide to make? Did they have nothing better to do?

kinda like typescript to javascript (1)

poached (1123673) | about 6 months ago | (#46538147)

Hack is to PHP as Typescript is to Javascript?

http://www.typescriptlang.org/ [typescriptlang.org]

Wait, PHP had no lexical scoped closures? (1)

Daniel Hoffmann (2902427) | about 6 months ago | (#46538153)

Really? WHAT YEAR IS THIS?

So it's C# with extra dollar signs? (0)

Anonymous Coward | about 6 months ago | (#46538191)

Check this out: http://docs.hhvm.com/manual/en/hack.async.php

So basically it's some sort of cross between PHP and C# 5.0, especially since they're literally taking keywords straight from it now...

Static languages coming back (1)

slapout (93640) | about 6 months ago | (#46538341)

Microsoft added static typing to Javascript (with Typescript). Now Facebook is adding static typing to PHP. After a few years of dynamic languages being in vogue, is the pendulum swinging back to statically typed languages?
 

Re:Static languages coming back (1)

MightyMartian (840721) | about 6 months ago | (#46538497)

Yes, mainly because there are literal mountains of shit code that no one can debug, and all of a sudden the notion that maybe having basically one variable type is a bad thing.

Somebody please tell me... (0)

ysth (1368415) | about 6 months ago | (#46538409)

Somebody please tell me this is an elaborate April fool's joke that someone noticed the groundwork for early?

I kinda want more specific types. (1)

Kaenneth (82978) | about 6 months ago | (#46538551)

I've contemplated a language/library with extra strict typing for doing real-world calculations.

For example, if floating point variables x and x were be classed as 'Lengths', and you stated "a = x * y;" a would have to be classed as an Area.

If you then stated "a *= 2;" a would still be an area (of twice the size), but "v = a * x;" would return a Volume class, and "a = a * x;" would be a compile time error (trying to assign a Volume result to an Area class)

other included types would be Time intervals, with a "(time)a * (length)b" giving a Velocity class, and "(velocity)c * (time)d" giving an acceleration class object...

This can all be done with simple Classes, be my specific thought is that once the (pre)compiler is done with the extended type checking, it throws out all the overhead, and compiles to just using simple floating point variables. It's to catch programmer errors, not run-time errors.

Load More Comments
Slashdot Login

Need an Account?

Forgot your password?

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>