CppCon Program Highlights, 5 of N: Modern C++ and Databases

The CppCon 2014 conference program has been posted for the upcoming September conference. We've received requests that the program continue to be posted in "bite-sized" posts, a few sessions at a time, to make the 100+ sessions easier to absorb, so here is another set of talks. This series of posts will conclude once the entire conference program has been posted in this way.

 

Whether you're using an in-memory flat database or a cloud-scale RDBMS, SQL and ODB databases continue to be a critical layer of modern software. But how do you use them well with modern C++? The following CppCon talks address this question, and as always are presented by the right people -- Those Who Know and Those Who Do, as usual with an international global perspective and including a two-part talk by CppCon's own Boris Kolpackov.

In this post:

  • sqlpp11, An SQL Library Worthy Of Modern C++
  • Persisting C++ Classes in Relational Databases with ODB
  • ODB, Advanced Weapons and Tactics

 

sqlpp11, An SQL Library Worthy Of Modern C++

SQL and C++ are both strongly typed languages. They should play well together. But most C/C++ interfaces to SQL databases are string based. They force the developer to effectively hide the SQL types, names and expression structures from the compiler. This defers the validation of SQL expressions until runtime, i.e. unit tests or even production. And the strings might even be vendor specific, because different databases expect different dialects of SQL in those strings.

That feels wrong. Modern C++ can do better.

This talk gives an introduction to sqlpp11, a templated embedded domain specific language for SQL in C++. It allows you to build type-safe SQL expressions with type-safe results, all of which can be verified at compile time, long before your code enters unit tests or even production.

In addition to its obvious use with relational databases, sqlpp11 can also serve as an SQL frontend for all kinds of data sources: Since sqlpp11 offers complete SQL expression trees even at compile time, it isn't hard to apply SQL expressions to std::vector or std::map for instance, or streams, or XML, or JSON, you name it. With your help, sqlpp11 could become for C++ what LINQ is for C#.

Speaker: Roland Bock, Head of Development, PPRO Financial Ltd., London/Munich.  Roland is Head of Development at PPRO Financial Ltd, an FCA regulated e-Money institute offering prepaid MasterCard card programs and comprehensive financial solutions for international electronic payment transactions. Since 2008 he has been using SQL in C++. Being unhappy with the string-based approach of most SQL libraries, he decided to do something about it and developed a type-safe EDSL for SQL in C++: sqlpp11, see https://github.com/rbock/sqlpp11. In his spare time Roland is preparing sqlpp11 to be proposed for boost and possibly also for the C++ standard. He lives and codes in Munich (Germany). C++ is his preferred language, especially since the arrival of C++11.

 

Persisting C++ Classes in Relational Databases with ODB

ODB is an open source, cross-platform and cross-database (SQLite, PostgreSQL, MySQL, MS SQL Server, Oracle) object-relational mapping (ORM) system for C++. It allows you to persist C++ objects to a relational database without having to deal with tables, columns, or SQL, and without manually writing any mapping code.

In the first part of this two-part talk we will cover the basics of transactionally persisting, loading, updating, and deleting simple C++ classes in a database as well as querying the database for objects. We will then look into persisting C++ classes that have more interesting data members, such as containers and pointers to objects, or that form a polymorphic hierarchy. Support for C++11, Qt, and Boost value types, containers, and smart pointers will also be covered.

Targeting 5 different database systems at the same time may sound like a daunting task but as we will see it is not that hard with ODB. Life would also be a lot easier if our C++ classes never changed. The next best thing is to have comprehensive tooling support. So we will conclude the first half with a discussion of database schema evolution and its support in ODB.

ODB, Advanced Weapons and Tactics

Hiding a relational database behind an ORM does not work. Did I just say that? Yes! Performance and scalability limitations always get in the way. Should we then throw away the whole ORM idea and go back to SQL? We don't have to. In fact, the bulk of ODB features were specifically designed to resolve these limitations without degenerating to JOINs and SQL. And that's what the second part of this talk is all about: bulk operations, object caches, lazy pointers, views, change-tracking containers, optimistic concurrency, object sections (partitions), and prepared and cached queries. By the end of the second half you will be ready for anything that real-world C++ object persistence and database access can throw at you.

Speaker: Boris Kolpackov Boris Kolpackov is a founder and chief software designer at Code Synthesis, a company focusing on the development of open-source tools and libraries for C++. For the past 10 years Boris has been working on solving interesting problems in the context of C++ using domain-specific languages (DSL), C++ parsing, source-to-source translation, and code generation. His notable projects to date include the ODB C++ ORM system as well as XSD and XSD/e XML Schema to C++ compilers.

CppCon Bonus Talk: C++ in MS Office -- Boris Kolpackov

cppcon-051.PNGThe CppCon organizers left a few slots in the CppCon 2014 program for "invited talks" on important but otherwise under-represented topics (such as game development, mobile and embedded systems, etc) or generally interesting and unusual uses of C++. On Tuesday, they announced the first two invited talks on Facebook’s heavy use of C++ in their server infrastructure.

Today, they announced another:

Bonus Talk: C++ in MS Office

by Boris Kolpackov

From the announcement:

Tony Antoun, Igor Zaika: "How Microsoft Uses C++ to Deliver Office (and More) Across iOS, Android, Windows, and Mac"

What does it take to target multiple major mobile devices (as well as traditional environments) with portable, efficient, single-source code? This talk demonstrates architectures, techniques, and lessons learned rooted in actual experience with using C++ to deliver several major cross-platform projects across iOS, Android, Windows, and Mac: Microsoft Office (Word, Excel, PowerPoint, OneNote) and the SQL Server PowerBI. Each presents a different case study: For example, Office already used C++, whereas PowerBI was originally written in Silverlight and then rewritten in C++; Office is a set of user-facing apps, whereas PowerBI is a system component. Although some of these are demanding first-tier “Cadillac” applications, we expect this experience to be a model for the future as more and more apps fall into this category and use C++ to target many popular platforms from (mostly) a single source base.

This talk covers the following key topics and tradeoffs: Rich vs. reach, including access to latest OS features (e.g., iOS 8 additions) and hardware features (e.g., vector units, GPUs). Consistency of functionality. Client code vs. server/service web code. Sharing vs. quality, including dialing appropriately between more shared code and high quality code. Drawing the line between the bulk of C++ code and interfacing with non-C++ for UX and PALs (platform adaptation/abstraction layers) for target-specific user interface and system services. Architecting PALs, including why “mini-PALs” rather than an “über-PAL.” Forcing “doing the right thing” and good architecture with composable components. How C++ enables things not feasible using other technologies. Velocity and enabling faster cross-platform development and deployment. Cost of maintenance, including time, size, and complexity (both breadth and depth). And, last but not least, developing in a single modern C++ source base built with different evolving C++ compilers, including VC++ and Clang/LLVM.

Speakers’ bio: Tony Antoun is Director of Development for APEX, focusing on delivering Office on all Apple platforms and form factors (iPhone, iPad, Mac), as well as aligning the Office experience on other major platforms (Win32, WinRT, Android). Before that, Dev Manager for SQL PowerBI – a cross-platform interactive client data visualization solution (iOS, WinRT, Web) connected to the SQL Reporting cloud service. Before that, Dev Manager for HD-DVD, cross-platform client solution for High Definition interactivity of media experiences (Win32, WinCE, Linux, Xbox).

Igor Zaika is the Development Manager for the Office Core Experience team at Microsoft, responsible for shared UX components and application framework used by Office applications. Before that, Igor worked in various areas related to Office client applications, ranging from building Word Object Model and integrating VBA (Visual Basic for Applications) with Office, to shipping first version of OneNote for the WinRT platform. Before joining Microsoft, Igor worked on 3D CAD application and contributed to the Kronos project.

CppCon Program Highlights, 4 of N: C++ and Modern Concurrency

The CppCon 2014 conference program has been posted for the upcoming September conference. We've received requests that the program continue to be posted in "bite-sized" posts, a few sessions at a time, to make the 100+ sessions easier to absorb, so here is another set of talks. This series of posts will conclude once the entire conference program has been posted in this way.

 

CppCon would be incomplete without strong coverage of concurrency-related techniques. But this year's material isn't about just any old concurrency techniques -- it's about stitching high-update-rate data structures and highly responsive algorithms into high performance scalable code. As always, these talks are by the right people -- Those Who Know and Those Who Do in some of the leading efforts in our industry, from *nix to Windows and from IBM to Microsoft to BlackBerry.

In this post:

  • C++ Memory Model Meets High-Update-Rate Data Structures
  • Lock-Free Programming (or, Juggling Razor Blades)
  • Lock-Free by Example
  • Async Sequences and Algorithms to Compose Them

 

C++ Memory Model Meets High-Update-Rate Data Structures

Highly performant and scalable techniques such as RCU and hazard pointers have been quite successful in read-mostly situations. However, there do come times when updates are necessary. It would be convenient if there was some general update-side counterpart to these techniques, but sadly there is not yet any such thing. Nevertheless, there are a number of specialized update-side techniques whose performance and scalability rival those of RCU and hazard pointers. This talk will discuss several of them, one of which is a solution to a challenge to the speaker at the 2014 Issaquah C++ standards committee meeting. This talk will also provide an outlook into the future of low-overhead scalable updates.

Speaker: Paul E. McKenney, Distinguished Engineer, IBM Linux Technology Center. Paul E. McKenney has been coding for almost four decades, more than half of that on parallel hardware, where his work has earned him a reputation among some as a flaming heretic. Over the past decade, Paul has been an IBM Distinguished Engineer at the IBM Linux Technology Center. Paul maintains the RCU implementation within the Linux kernel, where the variety of workloads present highly entertaining performance, scalability, real-time response, and energy-efficiency challenges. He is also the editor of "Is Parallel Programming Hard, And, If So, What Can You Do About It?" Prior to that, he worked on the DYNIX/ptx kernel at Sequent, and prior to that on packet-radio and Internet protocols (but long before it was polite to mention Internet at cocktail parties), system administration, business applications, and real-time systems. His hobbies include what passes for running at his age along with the usual house-wife-and-kids habit. Website: http://www.rdrop.com/users/paulmck

 

Lock-Free Programming (or, Juggling Razor Blades)

Example-driven talk on how to design and write lock-free algorithms and data structures using C++ atomic -- something that can look deceptively simple, but contains very deep topics. (Important note: This is not the same as my "atomic Weapons" talk; that talk was about the "what they are and why" of the C++ memory model and atomics, and did not cover how to actually use atomics to implement highly concurrent algorithms and data structures.)

Speaker: Herb Sutter, Microsoft. Author, chair of the ISO C++ committee, software architect at Microsoft.

 

Lock-Free by Example

Dive into and follow along making a lock-free queue. In particular, a multi-producer, multi-consumer, growing, shrinking, mostly contiguous, lock-free circular queue. With this single (complicated!) example, we will come across, and attempt to solve, many of the typical problems found in lockfree programming, and delve into the pros and cons of various solutions to those problems.

Speaker: Tony Van Eerd, C++ Guy, BlackBerry. Tony Van Eerd has been coding for well over 25 years, and hopefully coding well for at least some of that. Most of that time has been in the graphics/video/film/broadcast industry (at Inscriber/Adobe), writing low level pixel++, high level UI, as well as threading and everything else in between. He now works at BlackBerry, watching over the BlackBerry APIs. He is also the company-wide "C++ guy" writing half of his code in emails and wiki pages.

 

Async Sequences and Algorithms to Compose Them

All have heard and some have wept over all the many ways to express sequences (eg. iterator, range, container) and the algorithms to compose them (eg. filter, transform, merge, zip) in C++. I will describe one more sequence that must have a representation and an algorithm library - A sequence of values that will arrive over time.

Speaker: Kirk Shoop, Developer, Microsoft Open Technologies, Inc. Hi! I have a family. I like food. I need sun (My need for sun must be why I live in Seattle). I like C++. I don't like threads (My aversion to using threads must be why I spend all my free time working on a library that composes sequences on many threads). I work at Microsoft Open Technologies, Inc.Website: http://kirkshoop.blogspot.com/Twitter handle: @kirkshoop

 

Solaris Studio 12.4 Beta update 7/2014

The Oracle Solaris Studio 12.4 Beta, Update 7/14 release is now available for download.

This update includes new features and enhancements based on current user feedback during the Beta program. We look forward to getting additional feedback!

Feature highlights in this update include:

  • Additional support for C++11, including full support for Lambda expressions and initializer lists
  • Updated Performance Analyzer with a completely redesigned UI that automatically saves your configuration settings and allows you to save custom configurations, new Heap data view, new metrics to track IPC/CPI, and call-tree enhancements
  • Updated Code Analyzer with performance and memory usage improvements
  • OpenMP 4.0 implementation tuned for the latest Oracle systems
  • And many more features, enhancements and fixes in response to user feedback

Learn More and explore resources including the What's New guide and the latest videos and articles.

CppCon Bonus Talks: C++ at Facebook -- Boris Kolpackov

cppcon-053.PNGIn the CppCon spirit of talks "by the C++ community for the C++ community" given by Those Who Know and Those Who Do in some of the leading code bases in our industry, we're very pleased to relay this just announced on CppCon.org:

Bonus Talks: C++ at Facebook

by Boris Kolpackov

From the announcement:

We left a few slots in the CppCon 2014 program for what we call “invited talks.” They are used to fill in important but otherwise under-represented topics (such as game development, mobile and embedded systems, etc) or generally interesting and unusual uses of C++. Today we are ready to announce the first two invited talks which are on Facebook’s heavy use of C++ in their server infrastructure:

Marcelo Juchem: "Meta Techniques: Heterogeneous Polymorphism and Fast Prototyping at Facebook"

As data driven systems evolve there’s an ever growing demand for bringing new functionality into existing systems in an efficient, maintainable and least intrusive manner. When implementing features with different semantics or interfaces, virtual inheritance requires a compromise between design simplicity and performance. This implies a need for new techniques to achieve heterogeneous polymorphism efficiently. With C++11 and 14, type lists, type maps and variants can now be trivially implemented by the initiated. Facebook moves fast so we quickly adopted the new standards to further explore the capabilities of the type system. This talk demonstrates some meta-programming techniques like reflection and compile-time built structures to achieve heterogeneous polymorphism and fast prototyping.

Speaker’s bio: Marcelo Juchem is a Software Engineer at Facebook, working in stream processing and spam fighting systems. Fascinated by template meta-programming, he sees the C++ compiler as a powerful type juggler and programmable code generator. Such capabilities allow the combinatoric composition of types into efficient abstractions, reducing code duplication and enabling non-library writers to design logical components interaction and semantics rather than deal with low level details.

Drew Paroski: "C++@Facebook: How HHVM Uses Modern C++ for Fun and Profit (Both Literally)"

After an overview of HHVM’s architecture and history, this talk delves into what made C++ the language of choice when writing VMs and execution engines, including performance, benefits over assembly, and enabling C++ to call into JIT’d code. We cover the importance of control over ‘unsafe’ details: for memory layout, unions, casting, and bit-stealing. HHVM found important wins from being able to ensure that certain structures (Classes) are allocated in low-memory (i.e. addresses that fit within 32-bits) which allowed use of 32-bit immediates in machine code and 32-bit fields in objects. Also, being able to have fine control over memory allocation enabled having “huge pages”, a feature exposed in Linux (and other OSes) that allowed using fewer iTLB entries which gave a significant boost for Facebook’s PHP codebase. The talk will also mention some things that got in the way and how they were dealt with. Some were language features, such as virtual functions, member pointers. Before move constructors and rvalues were introduced in C++11, there were performance issues with returning smart pointers. While these were things that got in the way, it’s a testament to C++’s flexibility that there were always ways to work around these things in a stable fashion.

Speaker’s bio: Drew Paroski is a Software Engineer at Facebook and a co-creator of the HipHop Virtual Machine (HHVM) and the Hack programming language. Among other things, Drew is the primary designer and implementor of HHVM’s virtual instruction set architecture and Hack’s Collections framework, and he was a core contributor to HHVM’s JIT compiler in the early days of the project. Before Facebook, Drew worked at Microsoft helping improve the performance of Microsoft’s virtual machine for .NET languages (C#, VB.NET, F#, and more) known as the Common Language Runtime. Drew has been coding in C++ for over 10 years, and he enjoys designing and optimizing complex low-level systems.

Exception-Safe Coding in C++ -- Jon Kalb

If you haven't sent a colleague to this site lately, why not send someone there this week?

Exception-Safe Coding in C++

by Jon Kalb

Safe usage of exceptions is a non-trivial problem that the industry has struggled with for the better part of two decades. If you have fear, uncertainty, or doubt about exception safety or just want to see the best practices for using exceptions in C++, this session is for you. We’ll start with “What is the problem we are trying to solve?” and discuss alternatives, acknowledge the challenges associated with exception usage, and cover some well-meaning but misguided attempts at safety. I will then present a set of guidelines that are the basis for safe exception usage and solid implementation techniques, including how to transition from an exception-unsafe legacy code base.

When we are finished you will know how to produce code that is easier to write, easier to understand, faster, and 100% robust in the face of exceptions.

... "To say that I learned a lot from that video would be an understatement! I LOVED the talk and I really think you need to either write a book about this or at least have an article/blog." -- Abi Ullattil

You and your colleagues can also enjoy a live and interactive updated version of this talk at CppCon this September. CppCon 2014 will feature an updated and interactive version of this talk, along with some 100 other high-quality sessions about C++ across many domains, from mobile devices and web development, to games and embedded systems (including the Mars Rover), to Parallel STL and TMP.

Inline Functions -- Andrzej KrzemieĊ„ski

Today from Andrzej:

Inline Functions

by Andrzej Krzemieński

From the article:

Inlining functions can improve or worsen your program’s performance (however you define ‘performance’). It has been described in detail in Herb Sutter’s GotW #33. Compiler can decide to inline your function, even if it was not declared inline and conversely: it can decide not to inline it even if it is declared inline. So, you might be tempted to think that declaring functions as inline has no useful portable meaning in C++. This is not so. I have found inline functions useful, and its usefulness has nothing to do with inlining...

A Cheat Sheet for HTTP Libraries in C++ -- Vladimir

cheat-sheet.PNGRecently on Kukuruku:

A Cheat Sheet for HTTP Libraries in C++

By Vladimir

From the article:

... I decided to make a cheat sheet with examples of HTTP requests in C++ using different libraries. I guess Kukuruku is the best place for keeping such cheat sheets.

We’re going to take a look at the following libraries:

  • WinInet
  • WinHttp
  • Casablanca
  • Qt
  • POCO
  • wxWidgets
  • Boost.Asio
  • libcurl
  • neon
  • .NET (С++/CLI)
  • IXMLHTTPRequest
  • HappyHttp
  • cpp-netlib