Folly – Faceboook’s open source C++ library
github.com
github.com
Maybe if C++ had a standard package manager, people would stop coding huge libraries like that, focusing on smaller libraries that can be reused (independently).
There are so many build systems in C and C++ because for each of those, someone finds something to be inadequate and has something else that works for them.
Just like there is no standard for sizeof(int) or whatever, because it started with one size on one CPU and somebody brought it to a different CPU where another size made better sense. Today you can usually guess that it's 32 bits, but there are domains where it's not.
These languages are meant to not impose a lot on the implementer or practitioner. Having the standard specify that every build needs to potentially pull down a bunch of crap from github or wherever else is going to be really annoying to a lot of people. It is a misguided suggestion. I think it mostly comes from people not working in the language, or unfamiliar with code bases that are working well as-is.
This is different: C has to be implemented efficiently on a wide range of hardware, almost without regard for how good of a fit that hardware is for C or any modern language. Machines with 36-bit integers and 18-bit pointers? They got C compilers. Machines with no native notion of byte addressability? Plenty of C compilers for those things. Machines with application-visible segmentation? Of course! Those machines were quite popular for a while.
Therefore, the C programming language has to at least try to make it possible for portable programs to exist. That's the implied contract of the C standard: Code to the standard, and your programs will be compilable and runnable on every platform targeted by a conformant C compiler. So, since int is going to be a size adapted to the hardware, as required for efficiency, the programs have to know how big an int is, as required for portability.
> Having the standard specify that every build needs to potentially pull down a bunch of crap from github or wherever else is going to be really annoying to a lot of people.
No language standard specifies that, I'm pretty sure. The ES6 standard doesn't specify left_pad and the C++ standard doesn't specify Boost. However, the standards also don't specify things which could replace those external libraries in a portable fashion which is guaranteed to always be there. If you take something out of the standard library, it has to go somewhere; people aren't going to stop doing that thing just because the standard no longer mentions it.
This works so well you may have hardly even noticed its so widespread as a solution to the problems you describe.
Makes me wonder why Lisp is cursed[1] but C++ isn't.
[1]: http://www.winestockwebdesign.com/Essays/Lisp_Curse.html
Never underestimate the power to use the OS SDK to sell a programming language.
Framework in JS, is just similar to a more abstracted library in C++.
In the whole stack (or spectrum) of machine, language, application, C++'s design philosophy naturally encourage things like Folly and Absl. Just like JS encourages React, VUE etc.
Also yeah, every reimplementing jquery would be extremely strange and mostly defeat the point of jquery... which is to not have to implement jquery's constructs in Vanilla JS
Most C++ shops don't have their own equivalent of Folly, they use Boost or Google's Abseil or something else.
So people extrapolating from a ~100 person company or a ~1000 person company using JS might as well think it's about the language, but it's really about the size, I think.
Google uses some boost code and plenty of other external libraries (I can't speak to Facebook but imagine it's similar) - I think the point is just that Facebook and Google have an enormous amount of c++ code and have thus created libraries (some of which are fundamental enough or self-contained enough to open source)
This is just what happens when a bunch of engineers are all working in the same language - the utility libraries become large enough, robust enough and useful enough to open source
-----
As an aside, I think the similarities between folly and absl say something more meaningful about the state of c++
As an example, look at this folder which:
https://github.com/facebook/folly/tree/master/folly/compress...
In short, these are compression tools. Why not have 1 easily uninstallable package per compression tool in a standard package manager that works the same on all platforms.
Things don't have to be more or less generic.
This is more of an artifact of companies that produced them, which use large monorepos, than the ecosystem itself.
That said, you can pick and choose which part of boost you use, just as you can pick and choose which part of Abseil/Folly you use.
Because C++ sucks and its dependency story is a nightmare. There are a few competing C++ package managers. They’re all relatively new and none of them are particularly popular.
The most widespread C++ libraries are ones that are single header files. Because that’s the only thing that’s trivial to implement into an existing project.
Compiling OpenSSL requires installing Strawberry Perl. This type of garbage of BS is the norm.
Source: C++ dev for 15 years
I think this has much more to do with templates than anything else. A template can only exist in a header.
Then there is also the performance benefit of inlining. (As well as performance hit of inlining, namely code size.)
There is a separate, much later movement/phenomenon of C (not C++) developed as header-only libraries, which by contrast I don't think there is nearly as good reason for except for that some people are confused at how a linker works. I have seen use of that technique advocated on Hacker News much more frequently than in production.
These libraries generally have no third party dependencies. Because tracking down and compiling C++ dependencies is a dumpster fire.
I would take the sqlite amalgamation as an example of good use of "few files, few dependencies". First off, it is above all a solid piece of work. It is distributed with one header file and one .c, even though it is developed as multiple files. Iirc the sqlite website cites a ~10% speed improvement or so due to the optimizer being able to do a better job across the whole library. In my opinion this is a better reason than "tracking dependencies sucks" or "omg too many files".
The presence of a defacto package manager completely changes the library dynamics.
I can't even link and test properly against GMP on Windows :/
It also predates the time period when people would whine about a lack of package managers.
As do a bunch of these libraries.
The standard libraries should, in that they can have Spooky Deep Knowledge of the compiler and other standard libraries which external code won't, like how there's no way to add two ints which is faster than the standard + operator.
A simple example is `std::vector`. The structure is a nice resizable array, but for a long time you couldn't override the allocator and the performance of your application could be affected by heap fragmentation or even just the performance cost of heap allocations. A lot of C++ shops often wrote their own replacement containers that had a better allocation strategy. The design needs of a PlayStation 2 programmer ended up being different than an x86 desktop computer with virtual memory.
For a tool that does attempt to do virtualenv-like workspaces for C++ packages, see colcon [1], but there are still a lot of rough edges there— it's an evolution of the catkin multi package build system/tool from the ROS ecosystem, and part of the promise of it is a pluggable mechanism for discovering the packages in your workspace to avoid needing to a patch in a special XML file containing dependency information.
So C++ does not have a standard package manager.
Or are we really going full HN and debating the meaning of the word standard? Even if we are... is there a standard system? For that standard system, is there a standard package manager?
python question: Do people re-implement a lot of the core library routines at every company? Compared to other scripting languages, I found python to have a pretty large/compatible standard library (except when they renamed the url/configparser module names)
I expect to see company specific libraries for rust at some point because rust can play in the same space as c++ where you might want to make a different trade off.
https://github.com/facebook/folly/tree/master/folly/io/async
The overview is much more informative: https://github.com/facebook/folly/blob/master/folly/docs/Ove...
I suspect that this information seems so obvious to the maintainers that it gets overlooked. But its frustrating when a repo looks like it might be what I need but all I can find are installation instructions.
At a more detailed level, I find Folly much more substantial than Abseil. For example, both provide high performance hash tables. Abseil also provides a BTree-based map, which Folly does not. But Folly provides concurrent skip lists, LRU evicted hash maps, a high performance MPMC queue, etc. And that's just talking about data structures. Folly also has asynchronous I/O tools, futures, reference-counted buffers for IO, and many other things outside the scope of Abseil.
Personally, I am loving the asynchronous I/O mechanisms in Folly. It feels more expressive and results in cleaner code than boost ASIO. Just a first impression though, I am relatively new to the library.
>Folly (acronymed loosely after Facebook Open Source Library)
You literally broke your first promise. That literally translates ot FOSL. You could've used FOSL. That's a word. It makes sense. It's even a bit funny.
>is a library of C++14 components designed with practicality and efficiency in mind.
As opposed to all those components that are designed with impracticality and inefficiency in mind. I honestly don't think I can say I've ever designed anything without those two things in mind.
>Folly contains a variety of core library components used extensively at Facebook.
Which tells me literally nothing about what's in this library. How do I know what's used extensively at facbook? Last I saw it was mediocre PHP 4.
>Because of folly's fairly flat structure, the best way to see what's in it is to look at the headers in top level folly/ directory. You can also check the docs folder for documentation, starting with the overview.
That said, the code is also reasonably well commented as well, for example: https://github.com/facebook/folly/blob/master/folly/Singleto.... So "read the code" is not terrible advice in this case either.
The development process itself is fine. This takes place inside Facebook on their own infrastructure. The problem is their process to automatically sync their internal repo to GitHub and keep the public CI green is broken.
If you poke around the github issues, you'll note that several folks are successfully compiling folly with Clang.
The readme was updated and now reads
> folly supports gcc (5.1+), clang, or MSVC. It should run on Linux (x86-32, x86-64, and ARM), iOS, macOS, and Windows (x86-64). The CMake build is only tested on some of these platforms; at a minimum, we aim to support macOS and Linux (on the latest Ubuntu LTS release or newer.)
folly is used in FB opensource projects on Windows, macOS, and Linux (e.g. watchman) and Android and iOS (React Native, though that might not include the whole library.)
One motivation for this is so that a user may know whether folly supports the version of the gcc c++ compiler which is preinstalled on their system, since many systems ship with a preinstalled gcc. Likewise for systems which ship with a blessed package repo.
But folly also supports recent versions of clang and msvc, as other commenters here note.
It could be their statement "folly requires gcc 5.1+" meant gcc 5.1 or greater, where clang might be greater?
Reminds me of an old joke: "The package said it required Windows 95 or better, so I installed Linux."
They'd save a lot of guessing by putting in which Special Modern Features their code relies on.
The first paragraph of the readme starts with "Folly (acronymed loosely after Facebook Open Source Library) is a library of C++14 components" and gcc 5.1 is the first version (https://gcc.gnu.org/projects/cxx-status.html#cxx14) which supports all of c++14
Don't know if it's still true, but when I was at Facebook we used Clang for debug builds, and GCC for production builds.