News for hackers. Stuff that matters.
Re:C++14: Transducers by vvanders on Wednesday December 16, 2015 @12:44PM (#10745863)
I think the relevant bit is that we're seeing this without GC which makes it applicable to a whole set of problems that weren't previously relevant(which is also why I think Rust is so interesting).

Yeah, we get it that functional languages came first, but rather than looking down on C++ why not celebrate that functional constructs are making it into places where they haven't been before.

Re:C++14: Transducers by jlarocco on Wednesday December 16, 2015 @02:53PM (#10746794)
> Yeah, we get it that functional languages came first, but rather than looking down on C++ why not celebrate that functional constructs are making it into places where they haven't been before.

Because that's a meaningless thing to celebrate? Having functional concepts available in a poorly integrated way, with super ugly syntax is more depressing than anything, because seeing it in use is a reminder of how much cleaner it would be in a language like Haskell or OCaml.

Why not accept that C++ isn't a functional language, and realize that many die-hard C++ users won't use these features for the same reasons they're not already using functional languages.

I'd rather see these efforts directed towards improving the compilers and libraries for languages like Haskell, OCaml, etc.

Re:C++14: Transducers by dragonwriter on Wednesday December 16, 2015 @02:54PM (#10746811)
> Having functional concepts available in a poorly integrated way, with super ugly syntax is more depressing than anything, because seeing it in use is a reminder of how much cleaner it would be in a language like Haskell or OCaml.

I swear I remember fans of older OO languages saying the almost exactly the same thing with "object oriented" in place of "functional" about the way C++ grafted OO concepts onto C when C++ was new -- and, IMO, with good justification. Still, C++ was not exactly unsuccessful with that, either.

Re:C++14: Transducers by quizotic on Wednesday December 16, 2015 @06:54PM (#10748388)
> Why not accept that C++ isn't a functional language, and realize that many die-hard C++ users won't use these features

I'm a die-hard C++ user, and have come to love functional programming for a very C++y reason: improved performance that comes from lock-free parallelizability (if you never modify values, you don't have to synchronize access).

But I also love the simplicity that comes from not having to think so deeply about lifetimes and which portions of code can see which objects in which states. The abstraction of data-structure from algorithm is nice, the terseness is nice, the regularity is nice, but it's the lifetime and visibility simplification that helps me the most.

I don't know Haskell or OCaml. I wouldn't know a monad if it slapped me in the face. But functional C++ makes me happy

Re:C++14: Transducers by zem on Friday December 18, 2015 @02:36PM (#10760458)
pony might make you happy too. here's a great presentation on it: https://cdn.rawgit.com/darach/my_little_pony/master/my-littl...
Re:C++14: Transducers by CyberDildonics on Wednesday December 16, 2015 @03:16PM (#10746977)
I guess that's why so much of the software you use every day is written in Haskell and OCaml.
Re:C++14: Transducers by rwmj on Wednesday December 16, 2015 @12:47PM (#10745880)
What are the problems where GC can't be used? I'm going to guess very tiny embedded systems and hard real time. What are the places where C++ is being used? Unfortunately a lot more than those, resulting in expensive, unreliable, insecure software.
Re:C++14: Transducers by agentultra on Wednesday December 16, 2015 @02:02PM (#10746392)
I can think of a few more...

Operating Systems. Games. Deterministic soft and hard real-time systems (there's a reason you wouldn't be able to certify a control system for a fighter jet written in Javascript). Scientific stacks. Multi-media (do you think Renderman is written in Ruby?).

I'd even argue against using GC'd languages in desktop applications. It's getting to a point where these run-times are gobbling up a few gigs worth of pages from the OS and they still hang or crash when the OS decides to start paging them to disk. Or another process gets priority from the scheduler. The fact is while processor speeds have increased memory hasn't and that's the big bottle-neck on current hardware. Despite popular beliefs I think users do care about performance. They don't notice good performance but as soon as that beachball/whitescreen/whatever comes up and the UI is unresponsive you can bet their face is scrunching up like a walnut. Does that happen only to 1 or 2 users? 10%? We don't measure things like that enough when our happy little GC will take care of it for us.

Tuning GCs for workloads is probably as much or more work, in my limited experience, as designing your program from the bottom up around its specific data patterns. You'll get better performance from the latter approach more often than tuning a GC to your workloads after profiling. The wins in that case are incremental (we tuned our JVM after some profiling and shaved off 1.8% from our inner loop!). Where they can be dramatic with the right data structures and careful attention to locality (we saw an 800x reduction in cycles due to cutting unnecessary allocations and a 300% speed increase -- sweet!).

Even tuning your allocation strategy can net you bigger gains than trying to structure your code around a JIT.

All that being said -- GC's are incredibly useful in many situations. You just have to measure and be thoughtful. Memory is still an issue GC or not.

Re:C++14: Transducers by pjmlp on Wednesday December 16, 2015 @02:13PM (#10746486)
> Tuning GCs for workloads is probably as much or more work, in my limited experience, as designing your program from the bottom up around its specific data patterns.

If you are coding the full application yourself, probably.

If doing distributed development with 20+ team members from multiple contractors of various skill levels, which is my world, I have my doubts.

Re:C++14: Transducers by vvanders on Wednesday December 16, 2015 @12:58PM (#10745961)
Any place you care about memory layout, AKA performance. O(n) doesn't matter if you cache miss all over the place. Some GC languages(like C#'s structs) have some tools for this but as soon as you work with refs you've lost control.

To me that's any device with a battery(I'm looking at you smartphones), gamedev, and as you mentioned embedded systems.

There's also another class of programs that's not related to GC. C++(and C by subset) is the only way to write truly cross-platform code for all the modern OS's. If you want to target Android, iOS and Desktop C++ is the only supported path on all those platforms with the right performance guarantees(JS doesn't cut it perf-wise on mobile, yet). That's why you see DropBox and quite a few other shops using C++.

Re:C++14: Transducers by pron on Wednesday December 16, 2015 @01:12PM (#10746059)
GC and control over memory layout are two completely orthogonal issues. You can have either one, neither, or both.
Re:C++14: Transducers by vvanders on Wednesday December 16, 2015 @01:22PM (#10746115)
I don't know that they're completely orthogonal, GC by nature controls the allocation of objects which implicitly means that the layout in memory is controlled by the GC algorithm.

For instance if you have a GC that compacts then by definition you cannot guarantee object relative layout. This object layout is critical in making sure that your traversal order is cache and pre-fetch friendly.

AFAIK struts+arrays in C# are the only construct I've seen that lets you get close to explicitly control ordering of objects. In almost every other GC'd language you end up needing to use a giant byte array(hello emscripten!) in order to make those guarantees. If you work in that manner you're throwing away 90% of what makes the language useful and paying the cost of not working with the objects in their native form.

Re:C++14: Transducers by pjmlp on Wednesday December 16, 2015 @02:10PM (#10746460)
> AFAIK struts+arrays in C# are the only construct I've seen that lets you get close to explicitly control ordering of objects.

Check Mesa/Cedar, Modula-3, Oberon, Oberon-2, Active Oberon, Component Pascal, D.

All system programming languages with GC.

Re:C++14: Transducers by vvanders on Wednesday December 16, 2015 @02:15PM (#10746499)
I knew I should have included the caveat of being widely available on many platforms with a rich library ecosystem :).

I'm sure they fit the definition but I don't know that I'd want to use any in production aside from D. D is so similar to C++ I'd just rather use C++ instead since it's a bit more proven of a stack.

Re:C++14: Transducers by pjmlp on Wednesday December 16, 2015 @02:54PM (#10746808)
Except for D, those languages died because they were tied to OSes that didn't managed to jump into the mainstream, but they showed the way.

The problem is to have an OS vendor that would care to bring those features back.

So far I see it happening with Swift and C#, where Microsoft is slowly adding features from System C# used in project Midori.

Will they kill C++? Surely not, but they might reduce the use cases one would use it for.

For example, nowadays I don't write full stack applications in C++ any longer, I just use it for infrastructure code.

Re:C++14: Transducers by vvanders on Wednesday December 16, 2015 @03:48PM (#10747212)
Yup, that's totally fair. I'm a big fan of a solid C++ core + wrapper language that maps to the domain I'm in. Very common in the games space to see C# for all tooling/editor with the core engine in C++ for portability/performance.
Re:C++14: Transducers by pron on Wednesday December 16, 2015 @03:45PM (#10747188)
> For instance if you have a GC that compacts then by definition you cannot guarantee object relative layout. This object layout is critical in making sure that your traversal order is cache and pre-fetch friendly.

You do that in GC and non-GC environments exactly the same way: by embedding your objects in arrays.

> AFAIK struts+arrays in C# are the only construct I've seen that lets you get close to explicitly control ordering of objects.

And Java's upcoming value types.

> If you work in that manner you're throwing away 90% of what makes the language useful and paying the cost of not working with the objects in their native form.

I disagree. Even without value types, working with byte buffers in Java may still be significantly less work than C++, depending on how much of your application requires this kind of work. And the GC saves you a lot of work when you deal with concurrent data structures.

The main disadvantage (good) GCs have is their significant RAM overhead when good performance is required.

Re:C++14: Transducers by vvanders on Wednesday December 16, 2015 @03:57PM (#10747269)
Arrays work great for uniform objects(in languages that make guarantees about contiguity which Java doesn't). However once you have disparate types(which is very common) that falls apart. What happens if you have a string associated with an object that you don't want to cache miss on? I haven't seen a language that deals with that appropriately other than C/C++.

Value types are nice in Java, when will we see them in production? We don't even have Java8 on Android yet so I probably won't be able to use them till ~4-5 years from now.

Byte arrays may be less work but they still have problems, you'll pay the int->float cast costs for one, which can be non-trivial on some platforms. Also if you want to use Strings you end up allocating a new string on each access since Java doesn't have a nice way to wrap an immutable string(take a look at FlatBuffers if you want to see this in more detail).

I think it's important to understand they we're talking about a specific set of areas that C++ excels in. There are certainly places where I think Java and other managed languages make sense but if I need to make performance guarantees I'd rather not shoe-horn in a GC'd language where proven stacks have been successful.

Re:C++14: Transducers by pron on Wednesday December 16, 2015 @04:21PM (#10747438)
> What happens if you have a string associated with an object that you don't want to cache miss on?

Then you embed the array of chars in the object, just like in C++. I don't see what having a GC has to do with it. As to embedding arrays in objects in Java, I think it's planned as part of the value-type project, but no prototype yet. I know John Rose (JVM architect) said that the two features they intend to address are arrays of structs and structs of arrays (but not buffers of structs of arrays).

> you'll pay the int->float cast costs for one

HotSpot should optimize it away (not sure about byte buffer usage, though). It sees an integer read and a cast to float, and reads directly into a floating-point register.

> Java doesn't have a nice way to wrap an immutable string

You mean mutable string? Well, there's the CharSequence interface that String and the mutable StringBuilder implement, but it's true that not many standard APIs accept a CharSequence.

> I think it's important to understand they we're talking about a specific set of areas that C++ excels in.

I agree. C/C++ is unparalleled for single-threaded traversals over encoded binary data (e.g. video encoding/decoding and other signal processing) and for performance-sensitive applications running in memory constrained environments . Managed runtimes even try to compete in those domains.

In other cases, the extra performance you can squeeze out is too insignificant (and growing less significant with time) to justify the extra effort. And in some cases of growing importance (interesting multi-threading), C++ has to work really hard to even match GC-runtime environments. The real cost that is always paid is the significant RAM overhead.

And BTW: Android isn't Java. It's compatibility with Java has always been very partial, and, of course, its development is not directed by the JCP.

Re:C++14: Transducers by fmstephe on Saturday December 19, 2015 @02:51PM (#10764618)
Go supports this, I think. I am not quite sure what is meant by object relative layout.

In Go:

A struct is laid out as you declared it, with possible compiler added padding. A struct value field (not a pointer) in another struct is laid out contiguously in memory as you declared it. An array (or a slice) of values (no pointers) are laid out contiguously in memory.

You can happily take pointers into any of these larger structures. If you had a data structure where you really wanted to control the layout, you can create a slab allocator as a big array of values, and take pointers into that array to allocate pieces of your data structure. I did this exact thing to write a red-black tree in Go.

It is true that Go's GC isn't compacting. But it will be in the future (or it is planned to be).

But, if I hadn't programmed in Go I would have agreed with your comment above.

Re:C++14: Transducers by bassislife on Wednesday December 16, 2015 @04:14PM (#10747392)
> AFAIK struts+arrays in C# are the only construct I've seen

or Go, especially with the value types. Now there is no automatic SoA/ AoS conversions but otherwise, you have full control over memory layout.

Re:C++14: Transducers by Guvante on Wednesday December 16, 2015 @12:57PM (#10745943)
To be fair soft-realtime systems don't interact well with GC's since random multi-millisecond pauses break everything.

There is at least work towards making controlled GC pauses a possibility.

Re:C++14: Transducers by pjmlp on Wednesday December 16, 2015 @02:16PM (#10746509)
> To be fair soft-realtime systems don't interact well with GC's since random multi-millisecond pauses break everything.

Like these ones?

http://www.atego.com/de/products/atego-perc/

Used for this?

http://mil-embedded.com/news-id/?21468=

Re:C++14: Transducers by Guvante on Wednesday December 16, 2015 @04:26PM (#10747475)
Deterministic garbage collection is a completely different beast than what most people call GC. It is not a nearly magical fairy that lets you have infinite memory.

Also IIRC aviation has incredibly strict rules on freeing during flight, so this likely switches to a fixed memory model for at least part of the time.

Re:C++14: Transducers by pjmlp on Thursday December 17, 2015 @07:30AM (#10751059)
You aren't allowed to free at all in avionics.

In Ada deallocattion requires use of the unsafe package and in SPARK dynamic allocation it isn't even possible.

However the usage of GC based systems by the military in their weapon control systems, shows that there are GC implementations that able to cover certain types of real time use.

After all a GC pause during a battle situation is probably not something one wishes for.

Re:C++14: Transducers by pron on Wednesday December 16, 2015 @01:16PM (#10746077)
> random multi-millisecond pauses break everything

Then either use a GC that doesn't have multi-millisecond pauses, or make sure your "plain" GC doesn't. Both approaches are used very commonly.

Re:C++14: Transducers by Guvante on Wednesday December 16, 2015 @04:29PM (#10747496)
It is hard to have a discussion about GC's in the super abstract because object pools are better than GC's and even malloc. Without additional details about what the implementation will look like it is impossible to know the best memory allocation mechanism is.

I was just pointing out that most GC's that are general purpose have 2-3 ms pauses for collection which is a no-go for soft-realtime systems. I did not say that GC's are incompatible with soft-realtime systems.

Re:C++14: Transducers by pron on Wednesday December 16, 2015 @04:45PM (#10747595)
> because object pools are better than GC's

Object pools and GCs do different things, and you can have object pools in both GCed environments as in manually-managed ones, and they'd work equally the same. But note that you need a very, very good (and far from trivial) object pool to beat a good GC in multithreaded environments.

> I was just pointing out that most GC's that are general purpose have 2-3 ms pauses for collection which is a no-go for soft-realtime systems.

Well, most free ones. If you're writing a soft-realtime system with stricter latency requirements you'll either work harder to avoid the GC or pay for a low-latency one.

Re:C++14: Transducers by pron on Wednesday December 16, 2015 @01:14PM (#10746065)
I've used a GC language (Java) in hard-realtime systems successfully. Realtime Java (RTSJ) gives you control over which threads can trigger a GC and which operate in an arena. Even hard realtime systems have a very small core that's actually hard realtime, and real-time Java isolates it nicely.
Re:C++14: Transducers by vvanders on Wednesday December 16, 2015 @01:29PM (#10746157)
Isn't that effectively the same thing as embedding the JVM inside C/C++ with thread execution control?

From what I've read on the RTJS spec the real-time areas you're talking about use an arena allocator which is a different memory allocation strategy than GC.

Re:C++14: Transducers by pron on Wednesday December 16, 2015 @02:19PM (#10746525)
> Isn't that effectively the same thing as embedding the JVM inside C/C++ with thread execution control?

I don't see how.

> From what I've read on the RTJS spec the real-time areas you're talking about use an arena allocator which is a different memory allocation strategy than GC.

Yes, but both hard- and soft-realtime threads (that do use a GC) share the same JVM and can share some objects. Also, keep in mind that realtime JVMs guarantee scheduling latency for hard realtime threads of up to a few microseconds. If you can live with higher latencies, you can use realtime GCs.

Re:C++14: Transducers by marshray on Wednesday December 16, 2015 @12:56PM (#10745937)
'hard real time' -> multimedia and action games
Re:C++14: Transducers by unwind on Wednesday December 16, 2015 @02:09PM (#10746451)
Not sure what you mean by that arrow, but if you're implying those things on the right are examples of hard real-time, I disagree.

In hard real-time systems, there's generally the idea that if scheduling fails, things will break and/or property (or, worse, people) will be damaged.

Think of things like industrial high-torque motor control and avionics.

Re:C++14: Transducers by mpweiher on Wednesday December 16, 2015 @02:20PM (#10746532)
Also, hard real-time systems often don't have to be particularly fast. They are just not allowed to ever be late.
Re:C++14: Transducers by AnimalMuppet on Wednesday December 16, 2015 @05:25PM (#10747836)
This. "The right answer, too late, is wrong."
Re:C++14: Transducers by mpweiher on Wednesday December 16, 2015 @05:58PM (#10748033)
And it doesn't matter if you got the right answer 100 times faster than needed 99 times if you are late once.
Re:C++14: Transducers by marshray on Wednesday December 16, 2015 @02:27PM (#10746588)
Physical property damage isn't a requirement of the definition of 'hard real time', it's just that common examples are often given that way.

If deadlines are missed in multimedia applications the product isn't meeting its stated and implied requirements.

The consequences may be different, but a television that drops perceptible video frames is just as 'defective' (from an engineering point of view) as an industrial control system which drops motor control signals.