This blog is interested in imperative, functional, procedural, logic-based, and all sorts of ways of thinking about programming. I write mostly about C++, my bread-and-butter. Recent articles have focussed around functional programming in C++; this is one paradigm C++ programmers often neglect. Many believe that it is not possible or efficient to do. I challenge this assertion by example!
The RPG-ification of AAA titles has been going on for so long that it’s almost strange to see the rare game where you aren’t collecting some resource to get stronger and improve one attribute or another. The motivation is obvious: It gives a sense of progression, expression, replayability, and allows players to trade skill for time. It seems hard for AAA studios to release games that are difficult…
I first saw Vampire Survivor as demoed on Northernlion’s youtube channel and it struck me as “just another game”. The gameplay looked simplistic, the art looked rough, and the concept didn’t seem like a very big innovation. I didn’t really look at it with any seriousness until I saw “20 Minutes Till Dawn” and “Spirit Hunters: Infinite Horde”. That’s when it occurred to me: this is kinda a big…
Media criticism is one of my favorite uses of Youtube and somehow, the platform unearthed a really great set of critics to choose from, for movies. There are Lindsay ellis , Folding Ideas, Filmento, CJ the X, Filmento, etc., but in games we have far fewer. GMTK is the current gold standard, then there are Adam Millard, Design Doc, Dunkey, Noah Cadwell, Psych of Play, and a few others strewn here…
If you've ever followed an OpenGL tutorial, you probably saw code like this: float verts [] = { // Position TexCoords - X , - Y , Z , 0.0f , 1.0f , X , - Y , Z , 1.0f , 1.0f , X , Y , Z , 1.0f , 0.0f , - X , Y , Z , 0.0f , 0.0f }; GLuint vbo = glGenBuffer (); glBindBuffer ( GL_ARRAY_BUFFER , vbo ); glBufferData ( GL_ARRAY_BUFFER , sizeof ( verts ), verts , GL_STATIC_DRAW ); So far not... terrible.…
Note: code highlighting thanks to http://hilite.me/ Note2: This blog is primarily on template meta-programming--when the opportunity presents--using it to solve practical problems. This post assumes knowledge of C++17 fold expressions . If the reader is unfamiliar, this may not be the best learning material, but if the reader gets the idea and wants a practical example, please read on. Update July…
Return type deduction pre- decltype and auto could really make one mad. Back then, if you wanted a function object, you had to make it "adaptable", meaning it had to inherit from std::unary_ or binary_function and define its first_argument_type , second_argument_type , and result_type . There had been no concept of " transparent functors " allowing us to pass polymorphic functions to higher order…
Of the STL, <algorithm> may be the most well-used non-container library, but often requires a level of verbosity that requires just as much typing as the hand-written loop, making it not always feel so convenient. It benefits code that uses it with increased clarity and mathematical soundness, so reducing the syntactic overhead should be a goal of those using it. Today I will talk about these…
No matter how many articles get written about rvalue references, I still get the impression that many people don't understand them fully. Some belief that rvalues work differently as template parameters than they do in non-template contexts, which requires special rules in overload resolution. I intend to show how rvalues would consistently with the rest of the language. In the coarse of writing…
Recently, for a job interview task, I was asked to write a Python module with a C or C++ implementation to solve an otherwise simple task. Obviously, I chose C++. While I had never used the Python API before, I found that the existing information on extending Python with C quite sufficient. What surprised me, however, is how little information existed for using C++. A few libraries exist, like…
With each new release, gcc and clang add on more C++11 and C++14 features. While clang has been behind on some features, though ahead on others, they now claim to have C++1y all worked out . This article is not comprehensive. Clang's 3.4 C++ release notes: http://llvm.org/releases/3.4/tools/clang/docs/ReleaseNotes.html#id1 libc++'s C++1y status: http://libcxx.llvm.org/cxx1y_status.html Note: To…
Recently a Faisal Vali put forth an implementation of n3418 , which he co-authored with Herb Stutter and Dave Abraham, allowing generic lambdas using a fork of clang. It also includes auto type deduction, which I wrote about being implemented in gcc 4.8 . There are a few caveats before continuing: This has not been merged into the mainline. It has a few bugs, but Vali is quick to fix them if you…
Update: Added examples for dup and foldMap . Probably the most useful parts of the standard C++ library would be container and algorithms support. Who has worked in C++ for any non-trivial amount of time without using std::vector , list , map , or any of the others? <algorithm> , on the other hand, is more something everyone should know. It solves many of the problems that C++ developers encounter…
Previously , I discussed some basic things that can be done with tuples. I showed how a tuple can be applied to a function, however I did not show how member-wise transformations could be done. The code of this article builds on the code of the prior . Zipping. If we have several tuples, what if we want to apply a function to the nth element of each one? template< template<size_t> class Fi = Get,…
std::tuple is an odd-but-fun part of the new standard. A lot can be done with them. The members of a tuple can be applied to functions, both in groups and individually. The tuple itself can be treated as a function environment. They can be reorganized, appended, and truncated. The list goes on. The thing is, what can tuples be used for? Any POD struct or class can be a tuple instead, although this…
Note: GCC 4.8 is still in development; this article is based on Ubuntu's snapshot package of 4.8. I do not know about availability on other platforms. I say "has" because it does work and code can be written using it right now, even if it's in testing. Update: It turns out this feature has been implemented to test n3386 . You can read the discussion and even see the patch on the mailing list:…
So, " Learn how to capture by move " was posted on isocpp.org and then this morning, " Another Alternative to lambda move capture " was on reddit. These are both impressive solutions and I look forward to seeing what other creative answers the C++ community will come up with. I also want to go over how this problem can be solved with partial application. First, here's the definition. template<…
Control.Arrow shows an odd-but-interesting part of Haskell. Arrows are functions; composable and callable. Arrows and Monads sometimes seem to be referred to as alternatives to each other. Perhaps now would be a good time to relate some category theory. From A to B. A category theorist might view functions as a transformation from one type to another. For example, std::to_string : X -> std::string…
Function objects allow for freedoms that free functions do not. They are more compatible with higher order functions, composition, and generic programming. They are easier to use; extensible and convenient. They are often even more efficient. Higher Order Functions. Write a function that adds two arguments of any given type. template< class X, class Y > constexpr auto add( X&& x, Y&& y ) ->…
Are not the ones who praise a drug-free space also the most tempted to bring drugs to it? Are the ones who cry in empathy for the poor not actually rich? Is it not the case that those who despise intolerance are the most intolerant? Don't those who scream "Revolution!" fear change? Are the people who demonize sex not the ones who crave it deeply, and they that oppose pornography not the same as…
When researching parsing in Haskell, I always find this pdf: eprints.nottingham.ac.uk/223/1/pearl.pdf I will be referring back to this paper and encourage my readers to at least skim it as well. It may provide more understanding in how it works. It describes a simple, yet hard to comprehend functional parser. I have attempted to translate this to C++, but first I wrote a more intuitive, less…
Dear Microsoft, I see that you have decided to release C++11 in the form of a CTP . Congratulations on catching up! For a long time, it seemed like you just didn't give a shit, but thankfully that's not true. I see you now offer variadic templates. Great! You know when GCC 4.3 came out offering back in 2008, and Clang 2.9 the April of last year, it was really amazing, so I'm glad to see you're…
It occurred to me that some of those who found my " Generic Function Objects " article were not all that familiar with C++11 syntax, and in particular, template template parameters and variadic templates . Learning these concepts is one thing--just takes some googling, reading, and a little practice. Understanding examples like in my article may be more difficult, so I will explain how it works…
Previously, I discussed using inheritance to simplify the writing of generic functions. However, it occurred to me that I can't find anyone else advocating the same thing. No one has yet told me it's a bad practice, but I can't find any other examples of it on the web. (If anyone knows of one, please relieve me of my ignorance.) It's a very short amount of code. Obvious and intuitive. So what…
So, I posted " Rethinking std::binary_function ", which was this epiphany that instead of writing all these variadic operator types, I could actually define a base class and inherit its operator overloads. That lead to another realization: https://gist.github.com/4049946 . What I am about to elaborate on below feels like a discovery rather than an invention. It's also only a few days old. I…
I thought I'd take some time to highlight some of the interesting proposals I read today after having stumbled on a link to them: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/#mailing2012-11 I've been waiting over four years for Concepts to become standard. It started to feel like Stroustrup had given up on the idea, but luckily N3351 (pdf) by him and Sutton shows there has been…