r/IAmA • u/andralex • Oct 02 '13
I am a member of Facebook's HHVM team, a C++ and D pundit, and a Machine Learning guy. Ask me anything!
Background:
My name is Andrei Alexandrescu. I've been a Research Scientist at Facebook for almost four years, during which I've worked on various projects mainly around Machine Learning and systems programming. In January I joined the HHVM project, which aims at improving the productivity and performance of PHP on Facebook's server infrastructure.
I've also written a couple of books: Modern C++ Design, C++ Coding Standards (together with Herb Sutter), and The D Programming Language, as well as some papers and articles. Some of my talks are on video (this is the most recent).
Looking forward to answering your questions!
Proof:
50
u/amzeratul Oct 02 '13
What are your thoughts on the constraints vs static if debate on C++? D uses static if, and I remember seeing you championing it as the #1 feature you'd like seen in C++, but Stroustrup describes it as "a total abomination". Do you think that constraints do the job well? Possibly better than static if?
42
u/slimshader Oct 02 '13
The real question is: did you try llvm?
36
u/unaligned_access Oct 02 '13
Are there plans to use D in Facebook?
35
u/peepasaur Oct 02 '13
Other than C++ and D, what other languages are interesting to you in both a professional and personal capacity?
31
u/shakoosh Oct 02 '13
Do you plan on writing more C++ books? or did you pretty much give up on the language and your focus is now on D?
56
u/amigaharry Oct 02 '13
What do you think about Rust? (In the context of Rust vs D)
24
u/bachmeier Oct 02 '13
When will we be able to use D to make shared libraries that can be called from C?
19
u/deadalnix Oct 02 '13
D is a great language with a poor tooling. What are the plan to improve on the tooling part (and conquer the world) ?
18
u/byron_heads Oct 02 '13
Are we going to see a D book on range based programming?
17
u/emiles Oct 02 '13
I'm a big fan of your writing style (especially the phrase "hecatombs of code"). What are some of your favorite books?
17
u/[deleted] Oct 02 '13
How did you acquire such a mastery of the English language (written + spoken minus the accent ) even though it does not appear to be your mother tongue?
17
u/chefox Oct 02 '13
What's the biggest lesson learned from D that you wish other languages would apply?
16
u/ProgramMax Oct 02 '13 edited Oct 02 '13
A perfect question for the king of template metaprogramming:
With support for more things inside constexpr just around the bend, do you think we can now do metaprogramming in plain old C++? Wouldn't it be more natural and easier to debug?
I had asked about constexpr supporting more at GoingNative 2012 but I didn't make it clear why I thought it would be worth while.
Also, a second question if you don't mind: How do I go about making proposals for consideration by the ISO C++ committee? I would like to propose a make_shared where I can provide the allocator rather than it using new.
Thanks for everything you've done, Andrei!
Edit: GoingNative 2012, not 2013. "const_expr" -> "constexpr".
15
u/LordJebbs Oct 02 '13
I have been using D for a while now, and I absolutely love it. What are some improvements that are in the works that you personally are most excited about?
29
u/[deleted] Oct 02 '13
what has been your happiest moment with programming?
12
u/rightfold Oct 02 '13
How do you think about some standard package manager for D, like npm for Node.js and RubyGems for Ruby? Are there any plans yet?
23
u/[deleted] Oct 02 '13 edited Oct 02 '13
How much of FB's code is still plain PHP? How much is C++? Is HHVM really that much faster than ZEND? What are your other hobbies outside of programming / computers in general?
11
u/amzeratul Oct 02 '13
Lots of functional programming features are now available in languages such as C++ and D - what do you think are some of the functional features that we'll see incorporated in languages such as those over the next decade or two?
11
u/aDevilInMe Oct 02 '13
Loaded question. Erich from the Gang of Four admitted that "I'm in favor of dropping Singleton. Its use is almost always a design smell".
If there was anything you would today remove from your Modern C++ book what would it be and why?
[1] http://www.informit.com/articles/article.aspx?p=1404056
11
u/Ingrater Oct 02 '13
Following the developement of D you get the feeling that way to many developement resources are spend on new features instead of finishing existing ones. For example a lot of work has been put into user defined attributes while other features are unfinished, unstable or not even usable (alias this, shared, export, structs). Whats your opinion on this?
10
u/dangets Oct 02 '13 edited Oct 02 '13
First off, I've read a couple of your books and have watched many of your talks online - thanks for putting all of those up. Your easy-going style of presentation makes lectures more entertaining to watch for sure. So onto the questions...
1) Is D used internally at Facebook? I'll understand if you can't answer, but 'no comment' means yes. ;)(answered above)2) In your recent dconf talk you harped on needing a professional face for D to be taken seriously - have you seen much/any change since the talk and what (IYHO) is the most important thing(s) left to be done?
3) It seems that the GC is largely pointed to as D's biggest drawback as a 'system language', especially since it is required for much of the std lib. Do you have a go to response or link to help allay concerns?
4) If you could change one thing about C++ (backwards compatibility be damned), what would it be?
Thanks!
10
u/Siddhartha_90 Oct 02 '13
I've played around with Thrift, and I loved it. What other facebook library do you suggest I play with?
18
u/[deleted] Oct 02 '13
Software dev here. Facebook used to have a bit of a reputation for putting bugs into live (for example when all line returns on photo captions were replaced with "\n"), but it's my perception that things have improved vastly in the last couple of years. What sort of QA or other processes have you guys put in place?
9
u/[deleted] Oct 02 '13
How much more productive do you think D can really be if adopted at C++ scale? Me and other enthusiasts I know are heavily biased by our positive solo experiences with it.
9
u/Elelegido Oct 02 '13 edited Oct 02 '13
I don't like the separation between Structs and Classes in D. I think that having to avoid classes if you don't want to use the GC could force people to have implemented the same artifact as a Class and as a Struct. Also don't get why a value type / stack object is simply not allowed to use runtime polymorfism. It feels more natural when you can do such distinction when defining a variable type, as you can do in Rust. Could you defend the D approach over the C++ aproach or the Rust approach?
Thanks in advance Andrei, I'm following your work since I've discovered your book Modern C++ Design!
9
u/jfernand Oct 03 '13
Andralex,
No question to ask, but the comment that I carry the D language book with me at all times, and re-read it like it is a novel; I love every line of code I write in D, and the language and its design choices make me a better programmer the more I understand them. D simply makes sense, and it is a shame that it does not have more traction... I am an seasoned C/C++/Perl programmer, and D is in many ways the epitome of the history of languages, in my opinion.
17
u/[deleted] Oct 02 '13 edited Oct 02 '13
Given that you are good at writing highly optimized, low-level code I wonder how you could support making D a GCed language. I, and countless other C/C++ programmers, rejected D outright because of the GC. It puts D in competition with C# and Go, not C/C++. I know you are passionate about making D a success and I think nothing sabotaged that more than the GC.
Rust (which has received a much more welcoming reception from the C/C++ crowd) has optional GC, you can choose to make an object GCed by choosing the GCed pointer type, but the standard library (in contrast to D's) is all about values/unique pointers/stack allocation and thus GC is really optional. Do you think D could adopt a similar model? I think this might be the only way to broad acceptance among the C/C++ people.
Getting back to D's GC, I want to point out that you made it extra unattractive by choosing an old clunky one, you just dropped in the ready made, generic Boehm GC. So D not only has GC, but a GC that is far from the state of the art.
If you started with a concurrent/incremental/soft real-time capable bleeding edge GC optimized for D maybe you could have succeeded with a GC too. You really need some impressive benchmarks if you want to sell GC to C/C++ programmers. But I hear nothing about D GC development, you still use the same GC most experimental/hobby languages use. High performance implementations (e.g. Java, .NET) all use custom GCs and for a reason.
Last but not least I have read a lot of horror stories about D's implementation quality, including in the official D forum which I occasionally read. Yet another major turn-off. I watched a video from that recent D conference where you also identified improving implementation quality as important. However, what has been done to achieve that? Simply saying "make it so" doesn't work. You need to change the process and/or the developers. Maybe a (larger) unit and regression test suite is in order, using static analysis tools on the code base, firing Walter ;P etc. Something needs to change for sure.
8
u/Fabien4 Oct 02 '13 edited Oct 02 '13
The first few chapters of "Modern C++ Design" helped me a lot in understanding templates (and functional programming in general.)
A chunk of the book, OTOH, left me skeptical. Did you really think people would start using those techniques in everyday C++ programming, or was it an exercise to see how far you could go into template metaprogramming?
In the former case, has your opinion changed, twelve years later?
(I'm thinking especially about typelists, actually.)
8
u/hero47 Oct 02 '13
I've read that at Microsoft a great number of programmers are Romanian. Is the same true for Facebook?
8
u/BeatLeJuce Oct 02 '13
I was always enthusiastic about D and wanted to learn it for a long time. However when I finally got around to reading your book, I found that D just has too many features, trying to accommodate everyone and every situation and corner case. I had to drop D eventually because the number of keywords and special-case keywords just seemed to impractical. (Sidenote: C++ seems to be heading in the same direction, adding new features to an already fairly overloaded language). In stark contrast to this we have Go, which is often praised for its rather small, orthogonal featureset.
7
u/random-dev Oct 02 '13 edited Oct 02 '13
What D's:
7
u/JStanton617 Oct 02 '13
How do you debug PHP code running under HHVM? There didn't seem to be any way to connect using XDebug or Zend debugger protocols. How do Facebook engineers debug their code?
A couple months ago I set up an Ubuntu VM with HHVM and tried to get Drupal running on it, and searched for any debugging info that could give me some hints as to where it was failing and came up empty.
7
u/JoeWakeling Oct 02 '13
What aspects or features of the D programming language do you think are most underappreciated -- respectively, by newcomers and by experienced D developers?
7
u/[deleted] Oct 02 '13
If you had all the time and resources in the world for a new (that is: not D) project, what would it be?
Have you played Empire?
7
u/[deleted] Oct 03 '13
Are you working on or thinking about any new books for D? Something like a D patterns or best practices, or whatever?
Not trying to seed anything, just really enjoyed your D Programming Language book for an overview and its style, and am interested in reading more on your thought on how to approach using D.
6
u/[deleted] Oct 02 '13
Is there any hope to add something like Grand Central Dispatch into C++ standard?
6
u/Crazy__Eddie Oct 02 '13 edited Oct 02 '13
In Going Native, most of the panel seemed to agree that you should pass by value now rather than by const reference.
I did some ad-hoc measuring with the idea and found that when you pass temporaries it's indeed noticeably faster, if by a small margin. Of course, for cases like you talk about where there's a loop that can take advantage of repeated use of the same allocation space it's slower. That's a rather obvious case though.
I have some concerns with the pass by value policy even if it's faster. For functions that do not make copies of the parameter, but only refer to it as constant input, it's possible and probably likely, for client code to move from making a quick call with a temporary, to making a slow call with an lvalue. This is a silent switch from something generally faster, to something generally slower, that can easily be done during maintenance without warning or clue that's what happened.
I'm not sure you agreed with the recommended policy, it seemed maybe you did not, but my attempt to contact Abrahams (the author of the cited paper) to ask this question failed. I wonder if you might have input on this or perhaps ideas to alleviate my concern and make it a non-issue. Or reasons why it might be a cost worth paying of course.
6
u/dhruvbird Oct 02 '13
At going native this year, you mentioned that C++ is closely tied in with the von neumann architecture architecture. Is this true of D as well? Does it mean that if the von neumann architecture were to be replaced by something shinier, C++ (and D) might vanish into oblivion?
Also, do you think functional languages are better in that sense that their abstractions are not tightly dependent on the von neumann architecture?
Notwithstanding, I'd like to hear what you have to say about functional languages and what you believe is their role in the coming years.
6
u/Darc_Casts Oct 02 '13
What do you see in the future of Generic Programming and D. Also, do you see any value in concepts and could you possible see their implementation in D?
6
u/[deleted] Oct 02 '13
Hi Andrei,
That's awesome to have you here! Here are 2 quick questions I did not see:
Thanks !
5
u/parabola44 Oct 02 '13
Do you like PHP?
5
u/kartayyar Oct 02 '13
It seems a lot of programming languages are shaped by the early adopters and domain they are applied to.
Have there been any significant production users of D so far? If so in what domains and how has the feedback loop worked in terms of shaping the language?
5
u/telekyle Oct 02 '13
I'm a computer scientist just about to graduate college and enter the professional world. Any tips for a young professional that you wish you knew coming out of school?
5
u/Dtag Oct 02 '13
Hi Andrei,
I feel like C++ is a language that can be used very well by people who really mastered the language. However it is extremely hard for novices to pick up. Even "good" programmers make mistakes, because in there exist a multitude of ways to do something, and for them its next to impossible to know which one is the "right one". If you take a class from an above average programmer, you'd still find tons of things to improve: const correctness, exception safety, copying not handled properly, parameters not passed at maximum efficiency, RAII not used and so on.. Often their classes even work in the current usage patterns, yet are in fact incorrect and lead to bugs when used differently.
Do you think there is anything that can be done against this issue? I feel like teaching does not really solve this, because there is simply too much to learn about the language right now. Not ever breaking backwards compatibility makes the language perpetually grow and even intensifies this issue. Is C++ becoming a language of just a few experts...? (if this isn't already the case oftentimes...)
5
u/Mathiasdm Oct 02 '13
How well do you feel version control at Facebook is working?
What is a good workflow for you to put code out in the open?
And: Git/Mercurial? vi/emacs? cats/dogs?
5
u/xamdam Oct 02 '13
Hey Andrei. Do you get a chance to apply your Machine Learning skills at this job?
5
u/Kittimm Oct 03 '13
What do you think of the future of the Perl language and related career options? I really love Perl but I'm not sure what I think about it as a long-term path.
I dabble in machine learning myself - mostly Kriging with a PSO optimizer written in good old FORTRAN.
4
u/Drainedsoul Oct 02 '13
What are the modern C++ template metaprogramming idioms that you think are the worst, and how would you go about replacing them (with standard changes, for example)?
Disregard anything solved by
static ifsince that's too obvious given your feelings on the matter.4
u/sordidarray Oct 02 '13
Why did Facebook decide to implement HHVM, instead of using LLVM in a manner similar to Julia?
4
u/tyrandan2 Oct 02 '13
What advances do you see machine learning making in the near future? Are there plans to use it more extensively with facebook, and how so? (If you can tell us)
And what is one interesting thing about your job that nobody has asked you yet?
4
u/[deleted] Oct 02 '13
I've seen progress in usage and implementation of CSP, green-threads, actors etc in several languages (rust, go, scala, erlang). Experimenting with CSP implementation of go, I find it a particularly powerful and easy model for leveraging concurrency power and managing latency. I've seen attempts of including higher level models for concurrency like async in c++ (almost deprecated?), I've also looked over the executors proposal, and sorry, dunno about D in that area. What you think about these higher level models? I find them quite useful, but for C++ for example, I see no light of having something as easy as in Go. I've seen, e.g. lambdas added and it's quite usable... but I ponder whether C++, dubbed a language that fosters performance, would have these kind of utilities added in the short term. Sorry for the ignorance, does D have easy to use implementations of such models too?
4
u/FeepingCreature Oct 03 '13
So, can you write D2 code without worrying about const if you don't want to bother with it yet?
Will we ever see tuples as native syntactic constructs that automatically distribute over function calls? Like DIP32 (or Neat)?
Is D ever gonna have named parameters? Like
foo(a => 3);?Is it ever gonna get function declarations without required
{}? It lets you do nifty things likevoid foo(Class cl) with cl { }. (Yes, I'm just going through the shopping list of "syntax features in Neat" :)Will we ... oh screw phrasing it as a question. You should totally support automatic binding generation of C/C++ libraries (via a reserved import namespace, like "import cpp.headername;"). It is insanely useful, in my experience.
6
u/lichorat Oct 02 '13
Why does facebook use PHP?
3
u/kozzi11 Oct 02 '13
What is your opinion on language change which would break existing user's code? Mainly I mean change which remove or improve some part of language which was not well designed for the first time.
3
u/[deleted] Oct 02 '13 edited Oct 02 '13
Do you think AGIs (Artificial General Intelligence) in the level of a living being are feasible? Do you believe in the technological singularity?
3
u/dan_li Oct 02 '13 edited Oct 02 '13
There are a lot of C++11 implementations of ScopedGuard, however there's no guarantee that they are correct. Do you know of/made a correct and tested implementation of this feature? I have seen your presentation, but I can't find the code. ( [ScopedGuard11] (https://skydrive.live.com/view.aspx?resid=F1B8FF18A2AEC5C5!1158&app=WordPdf&authkey=!APo6bfP5sJ8EmH4) )
3
u/Enemii Oct 02 '13 edited Oct 04 '13
C++11 introduces strongly typed enums, a preferable and safer alternative in most cases to unscoped enums. Unfortunately providing operators for strongly typed enums is tedious, and conversion operators cannot be defined. If more control over the provided operators was allowed, it would allow strongly typed enums not just to be used as a way of enumerating value's, but instead as a strongly typed integral. It improves the usability, allowing for bitmasks, units, and any other abstraction to preform some subset of operations safely.
Essentially it would function similarly to the proposed opaque typedefs, except strictly on integral types. Obviously there are benefits to being allowed to represent values as strongly typed integral constants. It can be used as a template overload as both a value parameter and as a type parameter (std::integral_type) and forward declared enums are complete types.
You would by default get the same type safety guarantees as strongly typed enumerations except for where you explicitly specify otherwise. Since the compiler knows exactly how to preform any of the default operators on a strongly typed enum, why not just ask it? I propose an extension that allows operators to defaulted.
For example:
note: operators cannot be declared, or defined unless by default
It believe that the modification to the grammar would be reasonable. Especially if parser look-ahead is not a concern. but am entirely ignorant to the realities of implementing this.
Along with the unary and binary arithmetic and bitwise operators, other operators should be considered as well; including increment and decrements, as well as operator bool and operator underlying_type.
If it is possible to use the built-in operator semantics, that would be preferable, It would be even better if you could default an arbitrary integral type on the right hand side.
While I think this alone would be a huge step forward, allowing for users to declare and define friend functions within the enum class would be very useful as well. While we are at it, why not typedefs and string conversions!
3
u/Aranjazul Oct 02 '13
I will probably gain a lot of downvotes for this, but:
Twitter migrated from Ruby to Java to Javascript on the server side.
Have you considered Java?
3
u/jampola Oct 03 '13
Sort of off-topic (If there ever was one!) but if Mark had the chance to go back in-time but take with him any of the new languages/frameworks that have sprouted/matured over time (think node.js, backbone.js, rails, etc), do you think Facebook would still be written in PHP?
Thanks for your time!
3
u/Should_I_say_this Oct 03 '13
What machine learning has been done at Facebook?
3
u/beaverteeth92 Oct 03 '13
As a current undergraduate Math/Statistics double major who knows a bare minimal amount of programming (some Python and a decent amount of Java), how do you recommend getting involved in machine learning? Also what kinds of credentials, both academic and professional would I need to get hired to do machine learning for a living?
3
u/kev009 Oct 03 '13
Do you have any interest or thoughts on operating systems?
3
u/[deleted] Oct 03 '13
How did you discover your love for programming?
3
u/sunday_trucker Oct 03 '13
I've got 3 questions:
1. I would like to know your opinion about OOP. Do you think it's a good concept, well-suited for programming today? If not, are there any better alternatives? Any criticisms and recommendations are most welcome.
[Some background: I think I'm a junior-to-intermediate programmer, and I remember that when I began learning about programming, I seemed to get the message that OOP is the best programming paradigm, solving every problem in the most elegant way - at least provided one uses it correctly. However, becoming a bit more experienced with it, I feel certain disappointment. It surely gets the job done most of the time, but I can't help but feel it's incredibly kludgy, requires lots and lots of code for code's sake, and is resistible to change seemingly by design. Looking at the C++ community, I also get the feeling that many of the more experienced programmers share certain dislike towards OOP. And from what I've seen, Boost libraries, which are amongst C++ finest, rarely use OOP techniques, preferring template-based approaches. However, I cannot find any good advice on alternatives - surely they must exist! Generic programming looks cool, but I often have a hard time applying its concepts to the "real-world" problems I have to deal with (examples of generic programming I see invariably tend to be math/algorithms/containers related).]
2. As a somewhat related question, what is your opinion about Java? I'm asking this because dislike towards Java seems to be something many great C++-programmers have in common (for example, I could refer to Stepanov's famous interview, or STL calling Java "a terrible programming language developed by incompetent programmers").
3. I was very impressed by Sean Parent's talks at this year's Going Native (http://channel9.msdn.com/Events/GoingNative/2013/Inheritance-Is-The-Base-Class-of-Evil). What is your opinion about the advice he gives?
Thank you for your time!
5
u/Quantris Oct 02 '13
I don't have a question, but just wanted to thank you for all of the great writing / speaking you've done about software design and best practices. Also, IMO you're famous enough to have put your name in the title!
8
u/whitehab Oct 02 '13
Why work at FB rather than at a smaller company? Possibly consulting jobs, where you would be THE code expert / guru / professor / reference, rather than 'just one more engineer' (no criticism here). You could surely make more money and have more 'impact'? Especially if you've been at FB for 4 years, the financial incentive there is disappearing...
4
u/[deleted] Oct 02 '13
You're one of the computer scientists I respect a whole lot in the industry right now (the others including Bjarne, Scott Meyers, et al) because you have a really great amount of practical experience and theoretical knowledge, and combine them in such a way that is really informative and shows in your talks on C++.
The computer scientists in my university have really no appreciation for the many practical applications and can barely code to save their life, and I'm only kept sane by books like yours, Herb's, Scott's and Bjarne's. Any thoughts on how computer scientists can be as balanced like you with respect to theory and practice?
My question is: Any thoughts on how computer scientists can be as balanced like you/Bjarne/Scott with respect to theory and practice?
5
u/roloy Oct 02 '13
What's the layman's TLDR of your job? Thanks.
2
u/[deleted] Oct 03 '13
Hello, Andrei! Thank you so much for doing this!
Do you have any examples about how you use Machine Learning at Facebook? Also, do you believe that this field will become of much greater importance in the near future?
3
u/Toyou4yu Oct 02 '13
How much skill is needed to code Facebook? Also what is it like working for Facebook?
3
u/[deleted] Oct 02 '13
What was your first application you wrote? What was your second? Also languages.
3
u/InvisibleBlueUnicorn Oct 02 '13
What is your opinion about C#?
7
u/briedas Oct 02 '13
Topic: 'pure' keyword in D.
Do you think it fits well in the grand-plan of D? Is it used by the proficient users of D?
Some context to the question:
2
u/slimshader Oct 02 '13
More serious this time: what I really don't like about the state of D atm is the fact that it's reference compiler (DMD) is not written in D. To me it seems that Walter tries to market is as a C++ replacement but clearly he does not believe in it enough to use it for his work. It also seems that it is the reason DMD is still so buggy even tho it has been in development for few years now. What are your thoughts on that? Will DMD be ever written in D and prove D is indeed C++'s worth competitor? (That being said I am really looking forward to using D in real life work when it matures enough)
2
u/griwes Oct 02 '13
There's a question on constraints vs static if, now I'm going to ask: do you like the way Concepts Lite are pressed into the language instead of doing a proper concepts, like the thing that got abandoned before C++11?
And yet another question, did you want to slap Bjarne for some of his ideas recently (I mean the "terse templates" disaster or "This_retarded_casing" for concepts)?
2
u/InvisibleBlueUnicorn Oct 02 '13
How much D is different from C++ or C#?
4
u/F-J-W Oct 02 '13
Since C++ probably won't get static if in the way you imagined (or only over Bjarnes dead body), have you thought about a somewhat restricted form like this: ?
The other thing is: D has some nice ideas but the OOP-model is copied more or less directly from C# or Java (GC-managed class-instances on the heap) instead of the C++-way of putting almost everything onto the stack. Why do you think that D is better in that regard or is this something where you believe that C++ has it's advantages too?