<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: What I currently hate most about C++</title>
	<atom:link href="http://blog.mozilla.com/nnethercote/2009/06/19/what-i-currently-hate-most-about-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mozilla.com/nnethercote/2009/06/19/what-i-currently-hate-most-about-c/</link>
	<description></description>
	<lastBuildDate>Mon, 13 Feb 2012 14:54:05 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Nicholas Nethercote</title>
		<link>http://blog.mozilla.com/nnethercote/2009/06/19/what-i-currently-hate-most-about-c/comment-page-1/#comment-205</link>
		<dc:creator>Nicholas Nethercote</dc:creator>
		<pubDate>Sun, 21 Jun 2009 06:48:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mozilla.com/nnethercote/?p=130#comment-205</guid>
		<description>Jesse, LOL :)</description>
		<content:encoded><![CDATA[<p>Jesse, LOL <img src='http://blog.mozilla.com/nnethercote/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesse McNelis</title>
		<link>http://blog.mozilla.com/nnethercote/2009/06/19/what-i-currently-hate-most-about-c/comment-page-1/#comment-204</link>
		<dc:creator>Jesse McNelis</dc:creator>
		<pubDate>Sun, 21 Jun 2009 06:46:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mozilla.com/nnethercote/?p=130#comment-204</guid>
		<description>Object orientated programming is hard. It&#039;s major failing is that at first glance it looks easy and straight forward which makes n00bs jump straight in and make a big mess of it.

Functional programming has the great feature of scaring the shit out of n00bs who avoid it and don&#039;t even know where to start. The advantage of this is that the n00bs have to learn before they get a chance to make a mess of it.</description>
		<content:encoded><![CDATA[<p>Object orientated programming is hard. It&#8217;s major failing is that at first glance it looks easy and straight forward which makes n00bs jump straight in and make a big mess of it.</p>
<p>Functional programming has the great feature of scaring the shit out of n00bs who avoid it and don&#8217;t even know where to start. The advantage of this is that the n00bs have to learn before they get a chance to make a mess of it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nicholas Nethercote</title>
		<link>http://blog.mozilla.com/nnethercote/2009/06/19/what-i-currently-hate-most-about-c/comment-page-1/#comment-203</link>
		<dc:creator>Nicholas Nethercote</dc:creator>
		<pubDate>Sat, 20 Jun 2009 21:58:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mozilla.com/nnethercote/?p=130#comment-203</guid>
		<description>Sebastian, Kim,

You&#039;re right that this problem is OO-specific, not C++ specific.   (I mentioned that briefly at the start.)

And yes, it may just be that nanojit needs refactoring, and that C++ is not to blame.  But if I&#039;d written &quot;what I currently hate about Nanojit&quot; I wouldn&#039;t have got so many comments :)

But I suspect this problem crops up in a lot of OO programs.  TraceMonkey has some large awful classes too, and I bet the rest of Firefox does as well.  It&#039;s easy to blame bad programmers or bad OO design, but I suspect that OO programs tend in this direction if the programmer&#039;s aren&#039;t very disciplined.  And if a language or programming paradigm requires you to be really disciplined to avoid pitfalls, then it arguably deserves some blame when those pitfalls occur.

I am looking at ways to refactor the code, but it&#039;s going to be a long, slow process.</description>
		<content:encoded><![CDATA[<p>Sebastian, Kim,</p>
<p>You&#8217;re right that this problem is OO-specific, not C++ specific.   (I mentioned that briefly at the start.)</p>
<p>And yes, it may just be that nanojit needs refactoring, and that C++ is not to blame.  But if I&#8217;d written &#8220;what I currently hate about Nanojit&#8221; I wouldn&#8217;t have got so many comments <img src='http://blog.mozilla.com/nnethercote/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>But I suspect this problem crops up in a lot of OO programs.  TraceMonkey has some large awful classes too, and I bet the rest of Firefox does as well.  It&#8217;s easy to blame bad programmers or bad OO design, but I suspect that OO programs tend in this direction if the programmer&#8217;s aren&#8217;t very disciplined.  And if a language or programming paradigm requires you to be really disciplined to avoid pitfalls, then it arguably deserves some blame when those pitfalls occur.</p>
<p>I am looking at ways to refactor the code, but it&#8217;s going to be a long, slow process.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kim Sullivan</title>
		<link>http://blog.mozilla.com/nnethercote/2009/06/19/what-i-currently-hate-most-about-c/comment-page-1/#comment-202</link>
		<dc:creator>Kim Sullivan</dc:creator>
		<pubDate>Sat, 20 Jun 2009 20:42:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mozilla.com/nnethercote/?p=130#comment-202</guid>
		<description>One word - &quot;refactoring&quot;.

I haven&#039;t seen the code and how it came to be in what appears to be a real mess. Maybe the class can&#039;t be refactored into a dozen classes because of performance limitations? Maybe the code really has to do so much in one class (and has accumulated so many tweaks and hacks that it&#039;s impossible to de-entangle it without it breaking). But from the sound of it, it just sounds like badly written object oriented code (C with classes, instead of idiomatic C++).

In any case - complaining about state in C++ classes is not really about C++, but about OOP in general. Virtually all OOP languages (from Smalltalk to Java) do it like this.

Coming from a functional world where you don&#039;t have state that is the result of code with side effects (and are just used to passing everything you need as parameters), it&#039;s understandable to blame a particular language, but in this case, it really looks like it&#039;s just bad code (you can write more &quot;functional&quot; code using objects too).

I really recommend reading Martin Fowler&#039;s book on refactoring.</description>
		<content:encoded><![CDATA[<p>One word &#8211; &#8220;refactoring&#8221;.</p>
<p>I haven&#8217;t seen the code and how it came to be in what appears to be a real mess. Maybe the class can&#8217;t be refactored into a dozen classes because of performance limitations? Maybe the code really has to do so much in one class (and has accumulated so many tweaks and hacks that it&#8217;s impossible to de-entangle it without it breaking). But from the sound of it, it just sounds like badly written object oriented code (C with classes, instead of idiomatic C++).</p>
<p>In any case &#8211; complaining about state in C++ classes is not really about C++, but about OOP in general. Virtually all OOP languages (from Smalltalk to Java) do it like this.</p>
<p>Coming from a functional world where you don&#8217;t have state that is the result of code with side effects (and are just used to passing everything you need as parameters), it&#8217;s understandable to blame a particular language, but in this case, it really looks like it&#8217;s just bad code (you can write more &#8220;functional&#8221; code using objects too).</p>
<p>I really recommend reading Martin Fowler&#8217;s book on refactoring.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Vanier</title>
		<link>http://blog.mozilla.com/nnethercote/2009/06/19/what-i-currently-hate-most-about-c/comment-page-1/#comment-201</link>
		<dc:creator>Michael Vanier</dc:creator>
		<pubDate>Sat, 20 Jun 2009 17:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mozilla.com/nnethercote/?p=130#comment-201</guid>
		<description>Hmm, sounds like you&#039;re ready for Haskell and Ocaml ;-)

Another good language sharing the same space as C++ is D: http://www.digitalmars.com/d/
It&#039;s like a vastly improved, safer C++ but it also lets you get down and dirty if you want to.  I would love it if all C++ programmers took a good hard look at D.</description>
		<content:encoded><![CDATA[<p>Hmm, sounds like you&#8217;re ready for Haskell and Ocaml <img src='http://blog.mozilla.com/nnethercote/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Another good language sharing the same space as C++ is D: <a href="http://www.digitalmars.com/d/" rel="nofollow">http://www.digitalmars.com/d/</a><br />
It&#8217;s like a vastly improved, safer C++ but it also lets you get down and dirty if you want to.  I would love it if all C++ programmers took a good hard look at D.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bart J</title>
		<link>http://blog.mozilla.com/nnethercote/2009/06/19/what-i-currently-hate-most-about-c/comment-page-1/#comment-200</link>
		<dc:creator>Bart J</dc:creator>
		<pubDate>Sat, 20 Jun 2009 16:15:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mozilla.com/nnethercote/?p=130#comment-200</guid>
		<description>Hi,

Could you please tell me if I can access the rendering engine(Gecko) of Firefox.  My main task is to see the dimensions of a HTML element from a Java/Perl program.

Thanks.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Could you please tell me if I can access the rendering engine(Gecko) of Firefox.  My main task is to see the dimensions of a HTML element from a Java/Perl program.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sebastian Redl</title>
		<link>http://blog.mozilla.com/nnethercote/2009/06/19/what-i-currently-hate-most-about-c/comment-page-1/#comment-199</link>
		<dc:creator>Sebastian Redl</dc:creator>
		<pubDate>Sat, 20 Jun 2009 15:58:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mozilla.com/nnethercote/?p=130#comment-199</guid>
		<description>&quot;First, of all, C++ encourages (nay, forces) non-local state within classes, because all class methods have access to all fields within a class, even the ones they don’t need to.&quot;

You say that if you were writing C, you&#039;d pass this state as function arguments. Then why don&#039;t you in C++? It&#039;s not only perfectly valid, but actually highly encouraged to put local state into arguments. Class variables are for the class state.
What gives you the idea that C++ forces, or even encourages, non-local state? Just because the possibility of misuse exists, doesn&#039;t mean it&#039;s encouraged. Nothing in the C++ standard says you have to do it this way, and that&#039;s the only authorative source on what C++ does. If you go beyond the language, no book on C++ best practices I&#039;ve ever seen encourages making local state non-local by putting it into classes. (I&#039;ve seen some misguided OOP guides do this, but that&#039;s not a C++ problem.)

&quot;Let’s consider a single field, _thisfrag, which holds a fragment of LIR code. It gets set via an argument passed into the method beginAssembly().  It then gets overwritten — but with the same value! — via an argument passed into the method assemble().&quot;

That sounds like a class design problem to me. But class design is mostly language-independent. The problem would be exactly the same in Java, Python, Smalltalk, or any other object-oriented language you care to name. In fact, it would even be exactly the same in Mercury, OCaml, Haskell or Lisp if you decide, for whatever reason, to bundle up all that state into a single record type (or your language of choice&#039;s equivalent) and only pass that around instead of lots of free variables - suddenly you exposed state to functions that shouldn&#039;t have seen it, and thus you&#039;ve increased coupling and decreased maintainability. But the reason is still insufficient separation of state, not any particular language or any particular design method.

&quot;Good C++ practice encourages everyone to create private fields and use public get/set methods to access class data fields from outside the class.&quot;

That&#039;s just nonsense. No respectable guide on C++ will ever encourage direct access to state (be it in raw member variables or via get/set) where it isn&#039;t necessary. (Unlike Java, where the Beans specification comes very close to doing that.)

&quot;It would be better to just make _err public and avoid the get/set obfuscation;  at least then it would be obvious how exposed _err is.&quot;

Also wrong, for reasons mentioned by other commenters.

So in summary, you&#039;re frustrated about the poorly designed classes in Nanojit, but for some reason you chose to formulate your blog post in a way that blames C++ for this. But C++ is just a general-purpose language that supports object-oriented programming. There is no way you can blame it for poor class design.</description>
		<content:encoded><![CDATA[<p>&#8220;First, of all, C++ encourages (nay, forces) non-local state within classes, because all class methods have access to all fields within a class, even the ones they don’t need to.&#8221;</p>
<p>You say that if you were writing C, you&#8217;d pass this state as function arguments. Then why don&#8217;t you in C++? It&#8217;s not only perfectly valid, but actually highly encouraged to put local state into arguments. Class variables are for the class state.<br />
What gives you the idea that C++ forces, or even encourages, non-local state? Just because the possibility of misuse exists, doesn&#8217;t mean it&#8217;s encouraged. Nothing in the C++ standard says you have to do it this way, and that&#8217;s the only authorative source on what C++ does. If you go beyond the language, no book on C++ best practices I&#8217;ve ever seen encourages making local state non-local by putting it into classes. (I&#8217;ve seen some misguided OOP guides do this, but that&#8217;s not a C++ problem.)</p>
<p>&#8220;Let’s consider a single field, _thisfrag, which holds a fragment of LIR code. It gets set via an argument passed into the method beginAssembly().  It then gets overwritten — but with the same value! — via an argument passed into the method assemble().&#8221;</p>
<p>That sounds like a class design problem to me. But class design is mostly language-independent. The problem would be exactly the same in Java, Python, Smalltalk, or any other object-oriented language you care to name. In fact, it would even be exactly the same in Mercury, OCaml, Haskell or Lisp if you decide, for whatever reason, to bundle up all that state into a single record type (or your language of choice&#8217;s equivalent) and only pass that around instead of lots of free variables &#8211; suddenly you exposed state to functions that shouldn&#8217;t have seen it, and thus you&#8217;ve increased coupling and decreased maintainability. But the reason is still insufficient separation of state, not any particular language or any particular design method.</p>
<p>&#8220;Good C++ practice encourages everyone to create private fields and use public get/set methods to access class data fields from outside the class.&#8221;</p>
<p>That&#8217;s just nonsense. No respectable guide on C++ will ever encourage direct access to state (be it in raw member variables or via get/set) where it isn&#8217;t necessary. (Unlike Java, where the Beans specification comes very close to doing that.)</p>
<p>&#8220;It would be better to just make _err public and avoid the get/set obfuscation;  at least then it would be obvious how exposed _err is.&#8221;</p>
<p>Also wrong, for reasons mentioned by other commenters.</p>
<p>So in summary, you&#8217;re frustrated about the poorly designed classes in Nanojit, but for some reason you chose to formulate your blog post in a way that blames C++ for this. But C++ is just a general-purpose language that supports object-oriented programming. There is no way you can blame it for poor class design.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom K</title>
		<link>http://blog.mozilla.com/nnethercote/2009/06/19/what-i-currently-hate-most-about-c/comment-page-1/#comment-198</link>
		<dc:creator>Tom K</dc:creator>
		<pubDate>Sat, 20 Jun 2009 12:48:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mozilla.com/nnethercote/?p=130#comment-198</guid>
		<description>This argument is flawed. First of all is this not a critique of C++ but nearly all OO imperative languages, you mentioned it yourself - so change the title: &quot;What i hate most about oo-programming&quot;. This is not a peculiarity of C++ but an industry current practice (using classes and objects like you described them).

As someone already mentioned, C++ doesn&#039;t force you to do anything. You can really program referentially transparent. Do it all with static members and pass all arguments as you like them, no pointers, only copy by value and you are rid of all the stuff. Of course its not the way its meant to be.

By the way one can view classes as solution to the massive argument passing: aggregate common data that is worked on by a set of methods and pass them altogether - just getting rid of passing a million arguments 500 times - which sucks by the way too.

C++ does not force/encourage you to make anything a member, you didn&#039;t seem to mention that. It is simple aggregation, you want a data type composed of this and that and you choose yourself.

I think the problem isn&#039;t with C++ or oo languages but with software engineering how to structure and divide programs into modules/classes.

Also, you argue with non-local state and reasoning about that. But within a large software product you build up layers to reach higher levels and it becomes obvious that the state needs to be nonlocal and local reasoning will not suffice.

Lets take some procedure like: loadMachine() { moveRobotTo( pos ); openGate(); moveIn(); startCalibration(); moveOut(); startProcessing() }

Now tell me how you keep state local with robot and machine modules composed of thousands of ministates of sensors and actuators. Of course there is no total view of the affected data because of the high layer you are working.</description>
		<content:encoded><![CDATA[<p>This argument is flawed. First of all is this not a critique of C++ but nearly all OO imperative languages, you mentioned it yourself &#8211; so change the title: &#8220;What i hate most about oo-programming&#8221;. This is not a peculiarity of C++ but an industry current practice (using classes and objects like you described them).</p>
<p>As someone already mentioned, C++ doesn&#8217;t force you to do anything. You can really program referentially transparent. Do it all with static members and pass all arguments as you like them, no pointers, only copy by value and you are rid of all the stuff. Of course its not the way its meant to be.</p>
<p>By the way one can view classes as solution to the massive argument passing: aggregate common data that is worked on by a set of methods and pass them altogether &#8211; just getting rid of passing a million arguments 500 times &#8211; which sucks by the way too.</p>
<p>C++ does not force/encourage you to make anything a member, you didn&#8217;t seem to mention that. It is simple aggregation, you want a data type composed of this and that and you choose yourself.</p>
<p>I think the problem isn&#8217;t with C++ or oo languages but with software engineering how to structure and divide programs into modules/classes.</p>
<p>Also, you argue with non-local state and reasoning about that. But within a large software product you build up layers to reach higher levels and it becomes obvious that the state needs to be nonlocal and local reasoning will not suffice.</p>
<p>Lets take some procedure like: loadMachine() { moveRobotTo( pos ); openGate(); moveIn(); startCalibration(); moveOut(); startProcessing() }</p>
<p>Now tell me how you keep state local with robot and machine modules composed of thousands of ministates of sensors and actuators. Of course there is no total view of the affected data because of the high layer you are working.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sonny Corelone</title>
		<link>http://blog.mozilla.com/nnethercote/2009/06/19/what-i-currently-hate-most-about-c/comment-page-1/#comment-197</link>
		<dc:creator>Sonny Corelone</dc:creator>
		<pubDate>Sat, 20 Jun 2009 11:15:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mozilla.com/nnethercote/?p=130#comment-197</guid>
		<description>C+ is da bomb dude. Its better than VB.

RT
www.privacy-web.tk</description>
		<content:encoded><![CDATA[<p>C+ is da bomb dude. Its better than VB.</p>
<p>RT<br />
<a href="http://www.privacy-web.tk" rel="nofollow">http://www.privacy-web.tk</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Konstantin</title>
		<link>http://blog.mozilla.com/nnethercote/2009/06/19/what-i-currently-hate-most-about-c/comment-page-1/#comment-196</link>
		<dc:creator>Konstantin</dc:creator>
		<pubDate>Sat, 20 Jun 2009 10:06:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mozilla.com/nnethercote/?p=130#comment-196</guid>
		<description>OK. You&#039;ve started to work on existing code base. So what do you think about idea to improve current design of the code? 
Sorry, but 108 methods in 1 class smells really bad. Are you sure that you can&#039;t move part of them into Assembler components (composition in UML) or subclass Assembler to make it more clear?</description>
		<content:encoded><![CDATA[<p>OK. You&#8217;ve started to work on existing code base. So what do you think about idea to improve current design of the code?<br />
Sorry, but 108 methods in 1 class smells really bad. Are you sure that you can&#8217;t move part of them into Assembler components (composition in UML) or subclass Assembler to make it more clear?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

