<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Joseph Anderson&#39;s C++ Blog</title>
    <description>Exploring C++, one feature at a time.</description>
    <link>http://josephanders0n.github.io/</link>
    <atom:link href="http://josephanders0n.github.io/feed.xml" rel="self" type="application/rss+xml" />
    
      <item>
        <title>Is C++ a low level languange?</title>
        <description>&lt;p&gt;I often quip that C++ is the best high level low level programming language. The reason is that it can be as hight level as you like and almost as low level as is possible while remaining portable.&lt;/p&gt;

&lt;p&gt;A short example: I often deal with embedded systems with heterogeneous processor systems. If a certain processor wants to access a certain element without too much overhead , it has to be N bytes aligned in memory. The required alignment is often different for each system. In this case I could do my memory management manually, but that would be ugly. I could ignore the issue, but it would degrade performance, often by an order of magnitude. With C++ i can of course use the rich template system and a custom allocator to simply handle the problem with the type system.&lt;/p&gt;

&lt;p&gt;There are of course other ways in which C++ can realize low level constraints in a high level way. This is just one of the cases I came across this week.&lt;/p&gt;

&lt;p&gt;The other thing is that, if necessary, you can really get down to the basics and write block of C-like code and use it inside C++. I generally discourage this practice, but it is sometimes useful to manually optimize a small piece of code here and there. The fact that each object has a fixed memory location really helps here.&lt;/p&gt;
</description>
        <pubDate>Mon, 28 Mar 2016 00:00:00 +0000</pubDate>
        <link>http://josephanders0n.github.io/2016/03/28/is-c-a-low-level-languange.html</link>
        <guid isPermaLink="true">http://josephanders0n.github.io/2016/03/28/is-c-a-low-level-languange.html</guid>
      </item>
    
      <item>
        <title>I want C++17 Now!</title>
        <description>&lt;p&gt;I know, I know, we don’t even have proper working implementations of C++14 and there are a lot of proposals. These things take time, I know, I know.&lt;/p&gt;

&lt;p&gt;But I must say, whenever I read one of the proposals, I just think: Fuck yeah, we need this. It really triggers my Autism. It annoys me I have to wait so long.&lt;/p&gt;

&lt;p&gt;Still, better wait a while and get a proper standard than rush it and end up with unusable crap.&lt;/p&gt;

&lt;p&gt;Disclaimer: There really is no substance in this post. I’m just venting.&lt;/p&gt;
</description>
        <pubDate>Sun, 21 Feb 2016 00:00:00 +0000</pubDate>
        <link>http://josephanders0n.github.io/2016/02/21/i-want-c-17-now.html</link>
        <guid isPermaLink="true">http://josephanders0n.github.io/2016/02/21/i-want-c-17-now.html</guid>
      </item>
    
      <item>
        <title>String View</title>
        <description>&lt;p&gt;My favorite proposal for the C++17 standard is &lt;a href=&quot;http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3762.html&quot;&gt;string_view&lt;/a&gt;. If accepted it adds a new type to the standard library which describes a string but doesn’t own the memory containing the string data. What’s the point one might ask, and oh, isn’t this unsafe?&lt;/p&gt;

&lt;h2 id=&quot;why-do-we-need-this&quot;&gt;Why do we need this?&lt;/h2&gt;
&lt;p&gt;Performance and convenience, mostly. A lot of code that deals with strings will at some point work with substrings. This means that part of a larger string is cut out to form a new smaller string to do further work on. Without string views one can either create a new string, or work with iterators and describe the substrings with a begin/end pair.&lt;/p&gt;

&lt;p&gt;The first solution is highly inefficient as it wastes memory to hold the data of the substring and precious CPU cycles in order to copy the data. Since we’re dealing with C++ here, it’s safe to assume that performance is at least somewhat important.&lt;/p&gt;

&lt;p&gt;The second solution is fast but makes writing the code more difficult. The easy convenience functions for strings become much longer structures. Still, this is what I chose to do most of the time. It’s a bit annoying, but it works and it’s fast.&lt;/p&gt;

&lt;p&gt;String views solve this problem by essentially wrapping the iterator pair into an object that behaves like a string in pretty much any way. It’s even castable to a string if you need to work with some external library that expects an std::string. This will of course cause the aforementioned overheads. However, in cases where a string is manipulated multiple times, this cast may happen only once, so there’s still a performance improvement.&lt;/p&gt;

&lt;p&gt;The real kicker is the fact that string views allow the programmer to write efficient code &lt;em&gt;without&lt;/em&gt; having to think too much about it. As long as one understands what a string view is and what it represents, writing code with string views is a simple as with strings.&lt;/p&gt;

&lt;h2 id=&quot;is-it-safe&quot;&gt;Is it Safe?&lt;/h2&gt;
&lt;p&gt;Okay, so the string view doesn’t own the memory. Won’t this lead to segfaults and security issues. Well, if you don’t know what you’re doing, yes that can happen. It’s the exact same situation with the iterator solution though, or for any use of iterator use in general.&lt;/p&gt;

&lt;p&gt;String views are meant to be used as temporary objects for string manipulation, and when used as such they are perfectly safe. When you try to use them to store data, you will get a not so funny surprise. In order to avoid problems, treat the string view like a reference to a string object, not an object itself. Since any decent C++ programmer should be acquainted with references and how they work, I really don’t see a big safety concern.&lt;/p&gt;
</description>
        <pubDate>Sat, 20 Feb 2016 00:00:00 +0000</pubDate>
        <link>http://josephanders0n.github.io/2016/02/20/string-view.html</link>
        <guid isPermaLink="true">http://josephanders0n.github.io/2016/02/20/string-view.html</guid>
      </item>
    
      <item>
        <title>Account unlocked, but Blog not updating.</title>
        <description>&lt;p&gt;Github has unlocked my account after I’ve proven my humanity once more. Unfortunately the blog is not showing the posts I write. I know a 10 minute delay is normal, but I’ve been waiting for about 8 hours now. Tinypress is cool, but there are issues that need to be worked out before it becomes viable. I’m not giving up just yet though.&lt;/p&gt;
</description>
        <pubDate>Sat, 13 Feb 2016 00:00:00 +0000</pubDate>
        <link>http://josephanders0n.github.io/2016/02/13/account-unlocked-but-blog-not-updating.html</link>
        <guid isPermaLink="true">http://josephanders0n.github.io/2016/02/13/account-unlocked-but-blog-not-updating.html</guid>
      </item>
    
      <item>
        <title>Why I haven&#39;t given up on C++</title>
        <description>&lt;p&gt;I’ve recently come across &lt;a href=&quot;http://dorinlazar.ro/the-day-i-gave-up-on-cpp/&quot;&gt;this article&lt;/a&gt; in which the author attempts to outline why he is no longer using C++. I figured it would be a good idea for me to consider each of his points and state why I either agree with them or not. I may even have learned something along the way.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;C++ IDEs suck. Big time.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There’s something to this. Most C++ IDEs have problems, probably because C++ is a difficult language to fully parse. I’ve only ever used Visual Studio and KDevelop. Neither was awesome, but neither was horrible either. VS is a little strange to get used to, like almost all Microsoft products. KDevelop crashed a lot until around 2014, then started working relatively smoothly. It’s missing some debugging features, but that’s not too bad. All in all I don’t think C++ IDEs are all that horrible. The fact that I haven’t been forced to try any others show that they work just fine for most tasks.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;It’s an unmanageable language.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I’ve never really understood the big fuss about split header files. They work well, really aren’t a big hassle and can even serve as a short overview of the code. Include guards are a bit ugly though, I agree. But I must say, I’ve not come across a compiler without #pragma once in the past few years. What I really don’t understand in this section in the original article is how headers are supposed to be fine in C but somehow horrible in C++.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;It’s a barely portable language.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I’ll really have to disagree here. The standard libraries and Boost work fine without any preprocessor handling. Unless you want to do low level optimizations, this is just not an issue. And don’t get me started about Java being portable. It’s portable on paper, not in practice, but that’s a topic for another post.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;It’s a counterproductive language.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I honestly don’t quite understand the point that is being made here. Something about trying to implement a game ladder and C++ containers being a problem. A problem how? I don’t know what’s supposed to be unintuitive about standard containers. Maybe the libraries he used had odd behavour. I don’t know.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;STL sucks.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now here I really disagree. I think the STL is the one point where modern C++ really shines. It’s fast, its intuitive, and it’s reasonably simple. Most of the criticisms he writes are about the naming of the data structures. The thing is, the naming scheme makes perfect sense if you have any idea about what these data structures are about. They are not simply containers for putting stuff. They are specific containers that are meant to be used in certain ways and optimized for that usage pattern. As always, the motto is: You don’t pay for what you don’t use. The unified interface for containers are the common iterators. Iterators work just fine, with minimal overhead.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The focus on performance actually makes STL impracticable.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The focus on performance makes STL great. It’s easy to write some working, but slow container structures. But C++ is meant for writing efficient code. You don’t pay for what you don’t use.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;namespace stupidity&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Namespaces actually make large projects manageable. The code may not look nice, but it’s quite readable. I don’t understand this obsession with nice looking code. In many cases it makes sense to use a local typedef though. Not for making the code shorter, but in order to make it even more readable and adaptable.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The language sucks. It sucks because it’s so complicated.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I agree it’s complicated, but that’s not necessarily a bad thing. You really don’t need to understand the whole thing to start using it. And when you’ve been using it for a while and start to understand the intricate details, it becomes very, very powerful.&lt;/p&gt;

&lt;p&gt;In summary, I disagree with most of the points made. The real reason I still use C++ though is because it is unrivaled as the best high level, low level programming language. You can write highly abstract code which yet obeys tight hardware level criteria. It’s often not easy, but just because it’s difficult doesn’t mean it sucks. I haven’t given up on C++, and don’t think I will any time soon.&lt;/p&gt;
</description>
        <pubDate>Fri, 12 Feb 2016 00:00:00 +0000</pubDate>
        <link>http://josephanders0n.github.io/2016/02/12/why-i-haven-t-given-up-on-c.html</link>
        <guid isPermaLink="true">http://josephanders0n.github.io/2016/02/12/why-i-haven-t-given-up-on-c.html</guid>
      </item>
    
      <item>
        <title>Locked out again</title>
        <description>&lt;p&gt;GitHubs automated system thinks I’m not a human again. This is the third time this has happened now. I don’t know what triggers this behavior, but it’s getting kind of annoying, especially because the blog goes down for a while each time. Aargh!&lt;/p&gt;
</description>
        <pubDate>Fri, 12 Feb 2016 00:00:00 +0000</pubDate>
        <link>http://josephanders0n.github.io/2016/02/12/locked-out-again.html</link>
        <guid isPermaLink="true">http://josephanders0n.github.io/2016/02/12/locked-out-again.html</guid>
      </item>
    
      <item>
        <title>Initial Post</title>
        <description>&lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;I’m Joseph Anderson and I’ll be writing about C++. You can find me on GitHub &lt;a href=&quot;https://github.com/josephanders0n&quot;&gt;here&lt;/a&gt;. I hope you’ll enjoy reading my articles as much as I’ll enjoy writing them.&lt;/p&gt;
</description>
        <pubDate>Fri, 05 Feb 2016 00:00:00 +0000</pubDate>
        <link>http://josephanders0n.github.io/2016/02/05/initial-post.html</link>
        <guid isPermaLink="true">http://josephanders0n.github.io/2016/02/05/initial-post.html</guid>
      </item>
    
      <item>
        <title>Blog currently in Limbo</title>
        <description>&lt;p&gt;For some reason GitHub suspects that I am a Robot. Until I can prove my humanity to the GitHub overlords, this blog won’t function properly:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;One of our mostly harmless robots seems to think you are not a human.
Because of that, it’s hidden your profile from the public.
If you really are human, please contact support to have your profile reinstated.
We promise we won’t require DNA proof of your humanity.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is the first time I’ve ever had my humanity called into question, and by a bot no less. What can you do? Still, I’m hopeful that the support team responds quickly and releases my account so I can get on with writing the best blog evah!&lt;/p&gt;
</description>
        <pubDate>Fri, 05 Feb 2016 00:00:00 +0000</pubDate>
        <link>http://josephanders0n.github.io/2016/02/05/.html</link>
        <guid isPermaLink="true">http://josephanders0n.github.io/2016/02/05/.html</guid>
      </item>
    
  </channel>
</rss>
