{"id":195,"date":"2009-02-14T00:10:43","date_gmt":"2009-02-14T06:10:43","guid":{"rendered":"http:\/\/www.philhassey.com\/blog\/?p=195"},"modified":"2009-02-14T00:10:43","modified_gmt":"2009-02-14T06:10:43","slug":"from-python-to-c","status":"publish","type":"post","link":"https:\/\/www.philhassey.com\/blog\/2009\/02\/14\/from-python-to-c\/","title":{"rendered":"From python to C++"},"content":{"rendered":"<p>I think I wrote an article a few months ago comparing C and python. \u00a0I&#8217;m doing some new iPhone games now, and this time I&#8217;m using C++. \u00a0I found not having classes was getting to be too painful for me, so I&#8217;m trying out C++. \u00a0Here are a few things I&#8217;ve observed:<\/p>\n<p>(As a side note &#8211; I&#8217;m writing my games \/almost\/ the same way I&#8217;d write them in python. \u00a0So if you&#8217;ve seen my game code, I&#8217;m doing almost the same stuff, except in C++.)<\/p>\n<ul>\n<li>As usual, not having memory management is a bit of bother. \u00a0Fortunately, I&#8217;ve found there are only a few places where I actually need it. \u00a0The main thing I had to do was write some basic reference counting code for my state engine class.<\/li>\n<li>I&#8217;m using structs instead of classes, since I have no use for private variables or methods.<\/li>\n<li>Having separate .h and .cpp files is a drag. \u00a0But them&#8217;s the breaks .. It sure would be swell if C++ was a wee bit smarter about that.<\/li>\n<li>For my in-game objects, I just define a single struct that has all the possible variables I need. \u00a0This is pretty much how I did things in python anyways. \u00a0I&#8217;ve never been a big fan of using much inheritance.<\/li>\n<li>For writing my GUI classes, in python I was able to get lots of magic into them. \u00a0In C++ it isn&#8217;t so easy to get magic, so I&#8217;m doing without most of it. \u00a0It seems that most of the magic was gold-plating anyways.<\/li>\n<li>Having written all this code in python before, getting clean C++ code seems pretty natural. \u00a0I know what I WANT my code to look like, so I try to get my C++ to be as close as possible to that.\u00a0<\/li>\n<\/ul>\n<div>I think the bottom line of this post, is that my code is coming out pretty pythonic. \u00a0Maybe?<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I think I wrote an article a few months ago comparing C and python. \u00a0I&#8217;m doing some new iPhone games now, and this time I&#8217;m using C++. \u00a0I found not having classes was getting to be too painful for me, so I&#8217;m trying out C++. \u00a0Here are a few things I&#8217;ve observed: (As a side [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,13,6,2],"tags":[],"class_list":["post-195","post","type-post","status-publish","format-standard","hentry","category-c","category-crazy","category-development","category-python"],"_links":{"self":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/comments?post=195"}],"version-history":[{"count":0,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/195\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/media?parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/categories?post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/tags?post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}