<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Software EngiSneering</title><link>http://softwareengisneering.blogspot.com/</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/SoftwareEngisneering" /><description>Unix software development rants.</description><language>en</language><managingEditor>noreply@blogger.com (Bill Night)</managingEditor><lastBuildDate>Mon, 22 Apr 2013 15:53:02 PDT</lastBuildDate><generator>Blogger</generator><atom:id xmlns:atom="http://www.w3.org/2005/Atom">tag:blogger.com,1999:blog-837664636726682837</atom:id><openSearch:totalResults xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/">63</openSearch:totalResults><openSearch:startIndex xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/">1</openSearch:startIndex><openSearch:itemsPerPage xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/">25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/SoftwareEngisneering" /><feedburner:info uri="softwareengisneering" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2FSoftwareEngisneering" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FSoftwareEngisneering" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2FSoftwareEngisneering" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/SoftwareEngisneering" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FSoftwareEngisneering" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FSoftwareEngisneering" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FSoftwareEngisneering" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2FSoftwareEngisneering" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.feedburner.com%2FSoftwareEngisneering" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2FSoftwareEngisneering" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2FSoftwareEngisneering" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FSoftwareEngisneering" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FSoftwareEngisneering" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FSoftwareEngisneering" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2FSoftwareEngisneering" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.feedburner.com%2FSoftwareEngisneering" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><item><title>Emacs tip: Use 'view-lossage' to answer the question "How did that happen?"</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/YprNnvnFpEc/emacs-tip-use-view-lossage-to-answer.html</link><category>tips</category><category>emacs</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Wed, 10 Apr 2013 11:39:00 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-5217520383010496535</guid><description>Does it ever happen that you are thumping along in emacs, and suddenly you are in a mode or buffer that you never knew about before?&amp;nbsp; You must have unintentionally hit some keystroke that caused the change, but what was it?&lt;br /&gt;
&lt;br /&gt;
You can find the answer by typing &lt;code&gt;C-h l&lt;/code&gt; (that's a little "L").  This runs &lt;code&gt;view-lossage&lt;/code&gt;, which shows the last 100 characters typed.&lt;br /&gt;
&lt;br /&gt;
For instance, this morning I was suddenly staring at a blank buffer called "ChangeLog".  What is that thing?  To find out, I typed &lt;code&gt;C-h l&lt;/code&gt;.  A *Help* buffer opened with a few lines of symbols.  Here are the last couple lines: &lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;C-s F I X M E C-a C-n C-n C-n C-n C-n C-n C-n
C-n C-x 2 C-x o C-x V a r C-x u C-h l
&lt;/pre&gt;
&lt;br /&gt;
You start reading the lossage at the end.&amp;nbsp; So, at the end I can see the &lt;code&gt;C-h l&lt;/code&gt; from invoking &lt;code&gt;view-lossage&lt;/code&gt;.&amp;nbsp; Right before that, an undo (&lt;code&gt;C-x u&lt;/code&gt;) to get rid of the typing I had just done into the unknown ChangeLog buffer.&amp;nbsp; Right before that, &lt;code&gt;C-x V a r&lt;/code&gt;.&amp;nbsp; Ah, I meant to &lt;i&gt;search&lt;/i&gt; for "Var", but I must have hit &lt;code&gt;C-x&lt;/code&gt; instead of &lt;code&gt;C-s&lt;/code&gt;.&amp;nbsp; This is the culprit.&lt;br /&gt;
&lt;br /&gt;
So what do those keys do?&amp;nbsp; It opened a new buffer, but did it have some other harmful side-effect I want to know about?&amp;nbsp; Hit &lt;code&gt;C-h k&lt;/code&gt; to start the &lt;code&gt;describe-key&lt;/code&gt; function, and start typing &lt;code&gt;C-x&lt;/code&gt;, &lt;code&gt;v&lt;/code&gt;, &lt;code&gt;a.&lt;/code&gt;&amp;nbsp; Before I could type the 'r', the *Help* buffer showed up and explained that I had entered the keystroke for &lt;code&gt;vc-update-change-log&lt;/code&gt;, a function that seems like it was more useful back in the days of RCS than today, but which doesn't harm anything else.&amp;nbsp; Anyway, mystery solved!&lt;br /&gt;
&lt;br /&gt;
There tend to be two situations in which I call &lt;code&gt;view-lossage&lt;/code&gt;.&amp;nbsp; Number one is where I think, "Hmm, I don't know what I did, but it might be useful."&amp;nbsp; For that case, view-lossage lets you explore that functionality.&amp;nbsp; That was the case this morning with ChangeLog; I was curious about it but it turned out not to be useful to me.&amp;nbsp; Number two is where I think "I don't ever want that to happen again".&amp;nbsp; In that case, figure out the offending keystroke, and then disable it in your .emacs file, like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;(global-unset-key "\C-[\C-[") ;; prefix-command
(global-unset-key "\C-x\C-p") ;; mark-page
(global-unset-key "\C-x\C-n") ;; set-goal-column
&lt;/pre&gt;
&lt;br /&gt;
Those are typos I've made before that have annoying effects, so I just completely disable those keystrokes&amp;nbsp; (&lt;code&gt;mark-page&lt;/code&gt; is especially nasty: it sets the mark at the end of the file, and moves the point to the beginning of the file, so there's not always an easy way to jump back to where you were in the file).&lt;br /&gt;
&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=YprNnvnFpEc:2I7lkCkL8dg:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=YprNnvnFpEc:2I7lkCkL8dg:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=YprNnvnFpEc:2I7lkCkL8dg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=YprNnvnFpEc:2I7lkCkL8dg:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=YprNnvnFpEc:2I7lkCkL8dg:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/YprNnvnFpEc" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2013-04-10T11:39:47.347-07:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2013/04/emacs-tip-use-view-lossage-to-answer.html</feedburner:origLink></item><item><title>C++ Private Inheritance</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/ZWV1QrCRzCw/c-private-inheritance.html</link><category>c++</category><category>coding standards</category><category>tips</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Fri, 25 Jan 2013 17:17:00 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-6231408770186533369</guid><description>For a long time I believed private inheritance was such an arcane feature that it should be avoided.  In my &lt;a href="http://softwareengisneering.blogspot.com/2008/09/c-coding-standard-introduction.html" target="_blank"&gt;C++ Coding Standard&lt;/a&gt;, 8.2 stated "Use only public inheritance."  &lt;a href="http://softwareengisneering.blogspot.com/2008/09/c-coding-standard-inheritance.html" target="_blank"&gt;Here&lt;/a&gt; was my rationale:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;
You might find private or protected inheritance useful to save a few lines of code somewhere. But I claim you should just duplicate the lines of code, rather than couple together classes which are so different conceptually that public inheritance can't be used. They might be structurally the same today, but if they are conceptually different, that structural similarity may change over time and give you a huge headache.
&lt;/blockquote&gt;
&lt;br /&gt;
I think that rationale is pretty good, but now I've decided it might be worthwhile to use private inheritance in some cases.  For instance, it might make sense to inherit from some STL container class, and promote some of its lookup functions or subtypes to "public" with "using" declarations.  Like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;verbatim&gt;  class Foo : private std::map&amp;lt;int, Bar *&amp;gt; {

  public:
    typedef std::map&amp;lt;int, Bar *&amp;gt; Base;
    using Base::key_type;
    using Base::data_type;
    using Base::value_type;
    using Base::const_iterator;
    using Base::begin;
    using Base::end;
    using Base::empty;
    using Base::size;
    using Base::find;&lt;/verbatim&gt;&lt;/pre&gt;
&lt;br /&gt;
The likelihood of the structural change mentioned above is very low in this case, and the "using" declarations -- which I'll admit I didn't know could be used that way when I first wrote the standard -- allow you to reuse worthwhile parts of the base class in a very clean and foolproof manner.  Later if you realize there's another bit of functionality you want to expose publicly, you only have to write a one-liner, not a wrapper function.  Meanwhile, things you might not want exposed -- like operator[]() -- stay out of the interface.&lt;br /&gt;
&lt;br /&gt;
But the clincher for me is that you had better &lt;i&gt;not&lt;/i&gt; inherit publicly from a class like std::map.&amp;nbsp; Why?&amp;nbsp; Because it doesn't have a virtual destructor.&amp;nbsp; What if someone -- for whatever reason -- ends up with a pointer to a std::map which is actually one of your Foo objects, and wants to delete it?&amp;nbsp; Only the map destructor will be called.&amp;nbsp; If ~Foo() was supposed to delete its values, that won't happen.&amp;nbsp; Similarly, public inheritance means that someone could take a pointer to a Foo, and then use map's copy constructor or assignment operator to make a simple pointer copy of the Foo, perhaps unintentionally.&amp;nbsp; Then if the original was deleted, and deleted its values, the copy would hold stale pointers.&lt;br /&gt;
&lt;br /&gt;
Interestingly, I didn't seem very worried about that situation when I annotated the standard.&amp;nbsp; I &lt;a href="http://softwareengisneering.blogspot.com/2008/09/c-coding-standard-inheritance.html" target="_blank"&gt;wrote&lt;/a&gt; that you might sometimes break 8.4 -- "Destructors of base classes must be pure virtual (but implemented)." -- giving this &lt;b&gt;bad advice&lt;/b&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;
If you have a memory-sensitive class where subclasses will not be used 
polymorphically (or do not require polymorphic destruction), you can 
disregard the rule and get rid of the virtual table pointer.&lt;/blockquote&gt;
&lt;br /&gt;
That seems ridiculous now.&amp;nbsp; That is actually &lt;i&gt;exactly&lt;/i&gt; the use case for private inheritance:&amp;nbsp; you want to reuse some code, but not polymorphically.&lt;br /&gt;
&lt;br /&gt;
This all came to the fore today when I considered making a class 'public std::pair&lt;n n=""&gt;', so it could model an Edge in a &lt;a href="http://www.boost.org/doc/libs/1_52_0/libs/graph/doc/table_of_contents.html" target="_blank"&gt;Boost Graph Library&lt;/a&gt; edge_list&amp;lt;&amp;gt;, which requires 'first' and 'second' members (at least in the iterator class you instantiate edge_list&amp;lt;&amp;gt; with).&amp;nbsp; But recently a friend of mine had twitted me on another class I wrote that inherits publicly from an STL container, so I started to think about these issues.&lt;/n&gt;&lt;br /&gt;
&lt;br /&gt;
I'm still not sure how I'll implement my Edge class -- except that it &lt;i&gt;won't &lt;/i&gt;be public pair -- but I see that I need to change the coding standard someday soon, to reflect the reasonable usage of private inheritance.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=ZWV1QrCRzCw:SNXrTQE0ra0:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=ZWV1QrCRzCw:SNXrTQE0ra0:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=ZWV1QrCRzCw:SNXrTQE0ra0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=ZWV1QrCRzCw:SNXrTQE0ra0:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=ZWV1QrCRzCw:SNXrTQE0ra0:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/ZWV1QrCRzCw" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2013-01-25T17:17:32.655-08:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2013/01/c-private-inheritance.html</feedburner:origLink></item><item><title>Don't "Namespace" Filenames</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/GIuk8UVGq44/dont-namespace-filenames.html</link><category>negative</category><category>coding standards</category><category>style</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Wed, 19 Sep 2012 11:12:00 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-8088611630424548395</guid><description>When I first started this blog, I wrote up &lt;a href="http://softwareengisneering.blogspot.com/2008/10/obfuscated-directory-names.html"&gt;a rant&lt;/a&gt; about directory names that mislead about what their contents are.  At the same time, I complained about adding unnecessary morphemes to directory names, things like "db" or "model" or such-like.&lt;br /&gt;
&lt;br /&gt;
I've recently become annoyed with the habit of -- for want of a better term -- "namespacing" directory names and file names.  I'm not saying not to use good namespace discipline in source code.  What I mean is having a directory structure like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;  zoo/
    zoo_iface/
      zoo_cmds.hpp
      zoo_cmds.cpp
      ...
    zoo_model/
      zoo_cage.hpp
      zoo_animal.hpp
      ...
&lt;/pre&gt;
&lt;br /&gt;
Why does everything have to start with "zoo"?  Look at it this way:  if that was how we named people, then everyone's last name would be part of their first name and also part of their middle name.  Instead of calling someone Mary Jane Smith, we would know her as MarySmith JaneSmith Smith.  Some people make it even worse by prepending the full directory name onto the file name -- like "zoo_model_cage.hpp".  Poor Mary Jane would be MaryJaneSmith JaneSmith Smith.&lt;br /&gt;
&lt;br /&gt;
Of course, a source file name may be &lt;a href="http://softwareengisneering.blogspot.com/2008/09/c-coding-standard-source-files.html"&gt;dictated by its contents&lt;/a&gt; -- you're following our &lt;a href="http://softwareengisneering.blogspot.com/2008/09/c-coding-standard-introduction.html"&gt;C++ standard&lt;/a&gt;, right? -- so my ire is directed at redundant directory names more than filenames.&lt;br /&gt;
&lt;br /&gt;
This principle doesn't have to stop at source files.&amp;nbsp; It boggles my mind that raw bug testcases where I work start their life with names like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&amp;nbsp; /home/bugs/prod1_bugs/comp2_bugs/bug6003.tgz

&lt;/pre&gt;
&lt;br /&gt;
For crying out loud, I know this is a directory full of bugs, can't we just call each bug something like:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&amp;nbsp; /home/bugs/prod1/comp2/6003.tgz

&lt;/pre&gt;
&lt;br /&gt;
?&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=GIuk8UVGq44:24ime8PSZ7o:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=GIuk8UVGq44:24ime8PSZ7o:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=GIuk8UVGq44:24ime8PSZ7o:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=GIuk8UVGq44:24ime8PSZ7o:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=GIuk8UVGq44:24ime8PSZ7o:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/GIuk8UVGq44" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2012-09-19T11:12:00.328-07:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2012/09/dont-namespace-filenames.html</feedburner:origLink></item><item><title>Disabling Auto-Indent in Emacs</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/0NpQ62PkDSs/disabling-auto-indent-in-emacs.html</link><category>c++</category><category>tips</category><category>emacs</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Tue, 11 Sep 2012 10:02:00 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-657512606185559365</guid><description>I have to edit a C++ file at work whose indentation is so screwed up that any punctuation key I type ends up changing the indentation of the line I'm working on to something that is way out of line with the text right around it.  For sanity's sake I have to &lt;code&gt;M-x&amp;nbsp;set-variable&amp;nbsp;c-syntactic-indentation&amp;nbsp;nil&lt;/code&gt; when I'm working on that file.

The &lt;code&gt;c-syntactic-indentation&lt;/code&gt; variable does not start out buffer-local, meaning that for the sake of the one stupid file, I have turned off the very useful feature of syntactic indentation for every file I have open in that session.  So, if you are ever going to set it temporarily, make sure you have this line in your .emacs file:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;  (make-variable-buffer-local 'c-syntactic-indentation)&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
While you're at it, don't you want a shortcut for the set-variable?  I amused myself greatly this morning as I tried to think what shortcut I would assign this action to.  The obvious mnemonics I polled with &lt;code&gt;C-h&amp;nbsp;k&lt;/code&gt; were taken: I have &lt;code&gt;C-c&amp;nbsp;TAB&lt;/code&gt; set to &lt;code&gt;indent-region&lt;/code&gt;, &lt;code&gt;C-c&amp;nbsp;;&lt;/code&gt; to &lt;code&gt;comment-region&lt;/code&gt;, and &lt;code&gt;C-c&amp;nbsp;{&lt;/code&gt; set to a function to insert a skeleton class definition.&amp;nbsp; What to do?&amp;nbsp; I finally hit upon &lt;code&gt;C-c&amp;nbsp;(&lt;/code&gt;, and lo-and-behold I had already set that keystroke to toggle &lt;code&gt;c-syntactic-indentation&lt;/code&gt;, sometime in the distant past!  Here's the code:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;  (global-set-key "\C-c("
                  '(lambda ()
                     (interactive)
                     (setq c-syntactic-indentation (not c-syntactic-indentation))
                     (message "c-syntactic-indentation set to %s"
                              (if c-syntactic-indentation "t" "nil"))))
&lt;/pre&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=0NpQ62PkDSs:w7DTdTHBQ8Q:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=0NpQ62PkDSs:w7DTdTHBQ8Q:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=0NpQ62PkDSs:w7DTdTHBQ8Q:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=0NpQ62PkDSs:w7DTdTHBQ8Q:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=0NpQ62PkDSs:w7DTdTHBQ8Q:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/0NpQ62PkDSs" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2012-09-11T10:02:10.363-07:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2012/09/disabling-auto-indent-in-emacs.html</feedburner:origLink></item><item><title>Emacs: Scroll Other Window Up</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/SiFxpmH0vug/emacs-scroll-other-window-up.html</link><category>jargon</category><category>tips</category><category>emacs</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Fri, 01 Jun 2012 11:29:00 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-4042933393016348018</guid><description>It often happens that I have two related files open in one emacs frame, and I want to scroll around comparing them.&amp;nbsp; Of course to scroll back and forth in a single buffer, &lt;code&gt;C-v&lt;/code&gt; scrolls you down, and &lt;code&gt;M-v&lt;/code&gt; scrolls you up.  (In a perverse bit of emacs jargon, &lt;code&gt;C-v's&lt;/code&gt; function is called "scroll-up", since the text moves "up" relative to the fixed window -- even though every human wanting to look lower in the file thinks and says "scroll down, scroll down" -- and &lt;code&gt;M-v's&lt;/code&gt; function is called "scroll-down".)&lt;br /&gt;
&lt;br /&gt;
To keep two files synchronized as you peruse them, the power tool to use is &lt;code&gt;M-x ediff-buffers&lt;/code&gt;, which sets up an interactive diff session to step through the diffs.  Within ediff, a simple lowercase "v" scrolls lower in both files at once, and uppercase "V" scrolls higher.  Don't forget &lt;code&gt;M-x ediff-revision&lt;/code&gt; as a handy tool for comparing a version-controlled file to its latest revision, or for comparing two different revisions interactively.&lt;br /&gt;
&lt;br /&gt;
Ediff is great, but sometimes it is too heavy-handed for the eyeballing I'm trying to do.  For one thing, if one of the files contains a large section that is missing in the other, scrolling both files at once means striding through the section in one window while inching down a line at a time in the file that lacks it.  Also, navigating ediff can be tedious if there are a great number of changes or reordered chunks, and once your diffs no longer line up sensibly, ediff's highlighting is simply a nuisance.&lt;br /&gt;
&lt;br /&gt;
So there are the old standbys &lt;code&gt;C-v&lt;/code&gt; and &lt;code&gt;M-v&lt;/code&gt;, plus there is the handy &lt;code&gt;M-C-v&lt;/code&gt;, which scrolls lower in the other window.  That is, if I have a.txt and b.txt open in a single frame, and the cursor is in a.txt, then &lt;code&gt;M-C-v&lt;/code&gt; will show a lower chunk of b.txt, to keep up with &lt;code&gt;C-v&lt;/code&gt; in a.txt.  Until today, whenever I wanted to move &lt;i&gt;higher&lt;/i&gt; in b.txt, I didn't know of a single keystroke to do that, so I always just switched windows and used &lt;code&gt;M-v&lt;/code&gt;.  I could do &lt;code&gt;C-u - M-C-v&lt;/code&gt;, but I never liked that.&lt;br /&gt;
&lt;br /&gt;
Turns out there is a keystroke to scroll higher in b.txt without switching windows:  &lt;code&gt;M-C-S-v&lt;/code&gt; -- same keys as scrolling lower, plus the shift key.  Now, &lt;code&gt;M-C-v&lt;/code&gt; is a pretty ergonomic companion to &lt;code&gt;C-v&lt;/code&gt;.  I lean the base of my left hand on the Ctrl key, hit V with my left index finger, and keep my thumb poised over the Alt key to choose which window to scroll.  The shift key just does not fit in with this scheme.  With some effort, I can hold it with my left pinkie, but it's not comfortable.  So my new solution is to tie that command to &lt;code&gt;C-c M-C-v&lt;/code&gt;.  True, it's not a single keystroke, but unlike the &lt;code&gt;C-u&lt;/code&gt; solution above, it's all in the left hand, and close together without being cramped.  The .emacs line is:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;  (global-set-key "\C-c\M-\C-v" `scroll-other-window-down)
&lt;/pre&gt;
&lt;br /&gt;
Yes, the command to go higher in the file -- to scroll up as we humans say -- is "scroll-other-window-down".&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=SiFxpmH0vug:JbdAgZmnLyE:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=SiFxpmH0vug:JbdAgZmnLyE:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=SiFxpmH0vug:JbdAgZmnLyE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=SiFxpmH0vug:JbdAgZmnLyE:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=SiFxpmH0vug:JbdAgZmnLyE:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/SiFxpmH0vug" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2012-06-01T11:29:54.749-07:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2012/06/emacs-scroll-other-window-up.html</feedburner:origLink></item><item><title>gcc error: invalid use of member (did you forget the `&amp;' ?)</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/6ARNbhPgHys/gcc-error-invalid-use-of-member-did-you.html</link><category>gcc</category><category>tips</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Thu, 12 Jan 2012 20:03:00 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-592415034886633040</guid><description>Every time I have gotten the above compilation error, it has nothing to do with a missing ampersand.  Instead, it is missing function-call parentheses:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;  if (you_go &amp;&amp; use-&gt;yourMember) { // WRONG!
    this-&gt;isInvalid();
  }

  if (i_go &amp;&amp; use-&gt;myMember()) { // Oh yeah, the parens.
    continue;
  }
&lt;/pre&gt;&lt;br /&gt;
So don't use your member invalidly.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=6ARNbhPgHys:t-59HNecRyw:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=6ARNbhPgHys:t-59HNecRyw:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=6ARNbhPgHys:t-59HNecRyw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=6ARNbhPgHys:t-59HNecRyw:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=6ARNbhPgHys:t-59HNecRyw:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/6ARNbhPgHys" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2012-01-12T20:03:40.519-08:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2012/01/gcc-error-invalid-use-of-member-did-you.html</feedburner:origLink></item><item><title>Don't Avoid No-ops</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/9ffUJf95CIE/dont-avoid-no-ops.html</link><category>case analysis</category><category>style</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Fri, 11 Mar 2011 16:39:00 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-8318084716450228114</guid><description>A form of &lt;a href="http://softwareengisneering.blogspot.com/2008/08/eschew-case-analysis.html"&gt;spurious case analysis&lt;/a&gt; that seems to come up a lot in the code I have to work on right now falls under the category of "avoiding a no-op".  Well, don't add cruft to your code just to avoid a no-op.&lt;br /&gt;
&lt;br /&gt;
Here's the one that I see hundreds of:&lt;br /&gt;
&lt;pre&gt;  if (ptr != NULL) {
    delete ptr;
  }
&lt;/pre&gt;Instead of:&lt;br /&gt;
&lt;pre&gt;  delete ptr;
&lt;/pre&gt;But the line that caused me to post this today was this:&lt;br /&gt;
&lt;pre&gt;  if (!isalnum(str[i]) &amp;&amp; (str[i] != '_')) str[i] = '_';
&lt;/pre&gt;Why complicate the if condition just to make sure and not overwrite an underscore with an underscore?  In reading through this code I paused to consider when an underscore could occur, and whether something special had to happen, only to read a little further and see that someone was guarding against a no-op.  Good lord, just perform the no-op so I can read this more easily:&lt;br /&gt;
&lt;pre&gt;  if (!isalnum(str[i])) str[i] = '_';
&lt;/pre&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=9ffUJf95CIE:Vn3PsdZf0Nw:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=9ffUJf95CIE:Vn3PsdZf0Nw:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=9ffUJf95CIE:Vn3PsdZf0Nw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=9ffUJf95CIE:Vn3PsdZf0Nw:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=9ffUJf95CIE:Vn3PsdZf0Nw:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/9ffUJf95CIE" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2011-03-11T16:39:33.032-08:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2011/03/dont-avoid-no-ops.html</feedburner:origLink></item><item><title>Filename Expansion in Tcl</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/-Tg8Ij5H-V8/filename-expansion-in-tcl.html</link><category>negative</category><category>tips</category><category>tcl</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Thu, 27 Jan 2011 17:05:00 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-1970365816764543762</guid><description>Stupid, stupid, Tcl.  If you want to run a shell command with a glob filename, like &lt;code&gt;*.h&lt;/code&gt;, you can't just do:&lt;br /&gt;
&lt;pre&gt;exec ls -l *.h
&lt;/pre&gt;&lt;br /&gt;
You have to explicitly tell Tcl to expand the glob, because it will pass *.h to the shell literally.  But you also can't do:&lt;br /&gt;
&lt;pre&gt;exec ls -l [glob *.h]
&lt;/pre&gt;&lt;br /&gt;
because it will pass the entire list to the shell literally (thanks, Tcl, that's useful).  You get lucky and it works if there is exactly one file matched by the glob.  Otherwise &lt;code&gt;ls&lt;/code&gt; will complain that there's no file called "a.h b.h c.h".&lt;br /&gt;
&lt;br /&gt;
So what do you do?  Unfortunately, if you pull up the man page for &lt;code&gt;exec&lt;/code&gt; on the internet, it tells you a way to do this that is only syntactically valid for Tcl 8.5 or greater.  For those of us living in the past, the demonic incantation you must utter is:&lt;br /&gt;
&lt;pre&gt;eval [list exec ls -l] [glob *.h]
&lt;/pre&gt;&lt;br /&gt;
Don't use Tcl unless you have to.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=-Tg8Ij5H-V8:Hw7uP0SUyGc:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=-Tg8Ij5H-V8:Hw7uP0SUyGc:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=-Tg8Ij5H-V8:Hw7uP0SUyGc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=-Tg8Ij5H-V8:Hw7uP0SUyGc:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=-Tg8Ij5H-V8:Hw7uP0SUyGc:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/-Tg8Ij5H-V8" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2011-04-22T09:46:20.477-07:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2011/01/filename-expansion-in-tcl.html</feedburner:origLink></item><item><title>C++ Static No Longer Deprecated</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/i7RsqGrBowI/c-static-no-longer-deprecated.html</link><category>c++</category><category>tips</category><category>style</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Wed, 26 Jan 2011 12:00:00 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-3019935944870201478</guid><description>Wow, a long-held piece of geek trivia is no longer true.&lt;br /&gt;&lt;br /&gt;This &lt;a href="http://stackoverflow.com/questions/4726570/deprecation-of-the-static-keyword-no-more"&gt;Stack Overflow article&lt;/a&gt; points out that in a recent draft of the upcoming &lt;a href="http://en.wikipedia.org/wiki/C%2B%2B0x"&gt;C++0x&lt;/a&gt; revision to the C++ standard, file-scope &lt;code&gt;static&lt;/code&gt; declarations are no longer deprecated.  For, oh, 20 years, it's been one of those finer language points that you can whip out to show your sophistication and look down on the ignorant.  But between the August 2010 draft &lt;a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3126.pdf"&gt;(pdf)&lt;/a&gt; and the November 2010 draft &lt;a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3225.pdf"&gt;(pdf)&lt;/a&gt;, the section deprecating &lt;code&gt;static&lt;/code&gt; has been struck!&lt;br /&gt;&lt;br /&gt;If you're unfamiliar with the issue, it's that anonymous &lt;code&gt;namespaces&lt;/code&gt; provide a more general solution to the multiply-defined symbol problem.  Instead of:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  static int num = 0;&lt;br /&gt;  static int read_num() { return num; }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;the preferred C++ way to limit visibility of global objects to file scope was:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  namespace {&lt;br /&gt;&lt;br /&gt;  int num = 0;&lt;br /&gt;  int read_num() { return num; }&lt;br /&gt;&lt;br /&gt;  } // anonymous namespace&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The rationale is that you can put other symbols you wish to hide -- like class definitions -- in such a &lt;code&gt;namespace&lt;/code&gt;, but &lt;code&gt;static&lt;/code&gt; doesn't help you with those.  As the most general solution to the problem, &lt;code&gt;namespace&lt;/code&gt; wins and &lt;code&gt;static&lt;/code&gt; loses.  But I suppose that 20 years of failing to break people of the &lt;code&gt;static&lt;/code&gt; habit led to a recent change of heart.&lt;br /&gt;&lt;br /&gt;Suits me.  I had been consistently using anonymous namespaces for quite a while, both to be modern and especially since it does frequently come up that I want a type that is only used in one file.  But &lt;code&gt;static&lt;/code&gt; declarations are better for self-documenting the code, so I am happy to welcome them back.&lt;br /&gt;&lt;br /&gt;Only problem is, I need a new piece of C++ trivia to show off with.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=i7RsqGrBowI:SzeU_QpMsj8:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=i7RsqGrBowI:SzeU_QpMsj8:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=i7RsqGrBowI:SzeU_QpMsj8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=i7RsqGrBowI:SzeU_QpMsj8:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=i7RsqGrBowI:SzeU_QpMsj8:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/i7RsqGrBowI" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2011-01-26T12:19:39.885-08:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2011/01/c-static-no-longer-deprecated.html</feedburner:origLink></item><item><title>Emacs: Copy Environment Variable from Shell</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/cakehPqmFKU/emacs-copy-environment-variable-from.html</link><category>tips</category><category>emacs</category><category>shell</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Wed, 17 Nov 2010 08:54:00 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-6645149829144663324</guid><description>Sometimes I get annoyed when my emacs session has different environment variable settings than some shell buffer I have running in the session.  The most painful is when a Makefile depends on environment settings that I don't have in my .profile.  Command-name completion in a shell buffer can also be painful if you have changed your path.  And of course I'd like gdb to start up with the correct environment every time -- you can set the variables inside gdb, but that gets old on those days when gdb itself crashes again and again.&lt;br /&gt;
&lt;br /&gt;
I kept pasting &lt;code&gt;export FOO=bar&lt;/code&gt; into the *scratch* buffer and editing it into &lt;code&gt;(setenv "FOO" "bar")&lt;/code&gt; and eval'ing that.  After the 1000th time of doing that, I decided to automate it.  Turns out emacs already has an interactive function for copying an environment variable from the shell, but you have to type in the variable name.  I decided to write a little function to look for the last export, or the last &lt;code&gt;echo $FOO&lt;/code&gt;, and copy &lt;i&gt;that&lt;/i&gt; variable:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-size:75%; color:black"&gt;(defun engisneering-shell-copy-env-var ()
  (interactive)
  (let* ((expat "\\(export +\\([^=\n]+\\)=\\(.+\\)\\)")
         (echpat "\\(echo +\\$\\(.+\\)\n\\(.+\\)\\)")
         (cshpat "\\(setenv +\\([^ \n]+\\) +\\(.+\\)\\)")
         (patt (concat shell-prompt-pattern
                       "\\(" expat "\\|" echpat "\\|" cshpat "\\)")))
    (save-excursion
      (if (re-search-backward patt)
          (let* ((m (or (and (match-beginning 2) 3)
                        (and (match-beginning 5) 6) 9))
                 (var (buffer-substring (match-beginning m) (match-end m)))
                 (oldval (or (getenv var) " ")))
            (shell-copy-environment-variable var)
            (setq val (getenv var))
            (message "Old %s=%s; New %s=%s" var oldval var val))))))
&lt;/pre&gt;&lt;br /&gt;
Run this function inside your shell buffer, and it will search backwards for the last environment variable action and bring that variable setting into the emacs session.  It's also nice because it gives you a message in the minibuffer showing the change.  Add a &lt;code&gt;local-set-key&lt;/code&gt; -- I like &lt;code&gt;C-c C-v&lt;/code&gt; -- in your shell-mode-hook, and you're good to go.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=cakehPqmFKU:Jv8CMx0iJkA:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=cakehPqmFKU:Jv8CMx0iJkA:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=cakehPqmFKU:Jv8CMx0iJkA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=cakehPqmFKU:Jv8CMx0iJkA:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=cakehPqmFKU:Jv8CMx0iJkA:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/cakehPqmFKU" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2010-11-17T08:57:59.683-08:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2010/11/emacs-copy-environment-variable-from.html</feedburner:origLink></item><item><title>Let's Allocate Stuff!</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/oR7unbhT9PU/lets-allocate-stuff.html</link><category>c++</category><category>negative</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Wed, 22 Sep 2010 19:03:00 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-3124545604849968314</guid><description>Nobody's perfect, of course, but when there are &lt;i&gt;so&lt;/i&gt; many things wrong with a small piece of C++ code, it's hard to be placid.  How about:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;  std::vector&lt;std::string *&gt; v = new std::vector&lt;std::string *&gt;;
  // ...
    v-&gt;push_back(new std::string("..."));
  // ...
  std::ostream *str = get_me_a_stream(...);
  for (int i = 0; i &lt; v-&gt;size(); i++) {
    *str &lt;&lt; (*v)[i]-&gt;c_str();
  }
  delete str;
  // loop to delete v and its elements.
&lt;/pre&gt;&lt;br /&gt;
Ow, my head is spinning from all of these needless allocations.  Let's not wear out new and delete.&lt;br /&gt;
&lt;br /&gt;
Well, if you first learn C and then learn C++, your head might still be in Pointer Land.  But the unnecessary call to c_str() makes it hard for me to get any work done.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=oR7unbhT9PU:EgxNpAkBlf0:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=oR7unbhT9PU:EgxNpAkBlf0:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=oR7unbhT9PU:EgxNpAkBlf0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=oR7unbhT9PU:EgxNpAkBlf0:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=oR7unbhT9PU:EgxNpAkBlf0:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/oR7unbhT9PU" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2010-09-22T19:03:06.333-07:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2010/09/lets-allocate-stuff.html</feedburner:origLink></item><item><title>gcc: error: expected `)' before '&amp;' token</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/sleoJtM9z38/gcc-error-expected-before-token.html</link><category>c++</category><category>gcc</category><category>tips</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Sat, 14 Aug 2010 17:11:00 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-8233802266095528467</guid><description>Duplicate post here just to get two related error messages into page titles.  That's as much SEO as I know how to do.&lt;br /&gt;
&lt;br /&gt;
If you get this error from g++, and everything looks correct to you, maybe you are defining a constructor without qualifying it with the class name.  See the example on &lt;a href="http://softwareengisneering.blogspot.com/2010/08/gcc-error-expected-unqualified-id.html"&gt;this post&lt;/a&gt;.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=sleoJtM9z38:a0N88th0Fks:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=sleoJtM9z38:a0N88th0Fks:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=sleoJtM9z38:a0N88th0Fks:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=sleoJtM9z38:a0N88th0Fks:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=sleoJtM9z38:a0N88th0Fks:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/sleoJtM9z38" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2010-08-14T17:11:31.121-07:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2010/08/gcc-error-expected-before-token.html</feedburner:origLink></item><item><title>gcc: error: expected unqualified-id before ')' token</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/Ga7uxFiXXTw/gcc-error-expected-unqualified-id.html</link><category>c++</category><category>gcc</category><category>tips</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Sat, 14 Aug 2010 16:59:00 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-1268658945599984020</guid><description>I was scratching my head for a few minutes over the g++ error message in the title.  Google turned up a couple of red herrings, like &lt;a href="http://stackoverflow.com/questions/106117/gcc-expected-unqualified-id-before-token"&gt;this one&lt;/a&gt; at Stack Overflow where a clueless noob &lt;code&gt;#defined&lt;/code&gt; the name of his class.&lt;br /&gt;
&lt;br /&gt;
My mistake had been to define a constructor without putting the &lt;code&gt;Class::&lt;/code&gt; in front of it:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
    Class() // WRONG!!!
    : Super(), _duper()
    {
    }
&lt;/pre&gt;&lt;br /&gt;
instead of&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
    Class::Class()
    : Super(), _duper()
    {
    }
&lt;/pre&gt;&lt;br /&gt;
It wasn't as stupid as it sounds, I was cutting and pasting inlined functions into the .cpp file.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=Ga7uxFiXXTw:C7bno7_GIoU:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=Ga7uxFiXXTw:C7bno7_GIoU:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=Ga7uxFiXXTw:C7bno7_GIoU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=Ga7uxFiXXTw:C7bno7_GIoU:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=Ga7uxFiXXTw:C7bno7_GIoU:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/Ga7uxFiXXTw" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2010-08-14T17:58:23.204-07:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2010/08/gcc-error-expected-unqualified-id.html</feedburner:origLink></item><item><title>Can't Locate Object Method via Package</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/HU0BE5ZE6xQ/cant-locate-object-method-via-package.html</link><category>tips</category><category>perl</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Wed, 14 Jul 2010 12:31:00 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-65937677953479212</guid><description>I recently got a confusing Perl error message for a line of code that I thought was a simple assignment to a hash member:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;code&gt;Can't locate object method "patterns" via package "objdir(/[^ ]*)?" (perhaps you forgot to load "objdir(/[^ ]*)?"?) at ./filter.pl line 24.&lt;br /&gt;
&lt;/code&gt;&lt;/blockquote&gt;&lt;br /&gt;
A Google search turned up many forum entries asking about the message, but they all had to do with open-source projects where there was indeed a package method call that had gone wrong.&lt;br /&gt;
&lt;br /&gt;
After I rubbed my eyes long enough, it was obvious what I had done:  left the '$' off the front of the hash reference.  I had typed:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;    patterns{"objdir(/[^ ]*)?"} = "dirs/objs"; # WRONG!
&lt;/pre&gt;&lt;br /&gt;
instead of:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;    $patterns{"objdir(/[^ ]*)?"} = "dirs/objs";
&lt;/pre&gt;&lt;br /&gt;
I even had &lt;code&gt;use strict; use warnings;&lt;/code&gt; on, but only got the error message.  Anyway, since Google didn't help me out, let's see if this page with the error text in the title floats to the top and helps someone else out someday.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=HU0BE5ZE6xQ:vfFZX5IraYI:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=HU0BE5ZE6xQ:vfFZX5IraYI:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=HU0BE5ZE6xQ:vfFZX5IraYI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=HU0BE5ZE6xQ:vfFZX5IraYI:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=HU0BE5ZE6xQ:vfFZX5IraYI:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/HU0BE5ZE6xQ" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2010-07-14T12:31:12.820-07:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2010/07/cant-locate-object-method-via-package.html</feedburner:origLink></item><item><title>Blessed Mother of Commented-out Code</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/esUU8x7IcuU/blessed-mother-of-commented-out-code.html</link><category>negative</category><category>dead code</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Fri, 18 Jun 2010 14:31:00 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-7432322333016795444</guid><description>It's the little things in life that give pleasure, isn't it?  Like the lovely comment below, which has adorned a source file at my company for nearly sixteen (16) years now (meaning the file is at least 5 years older than the company).&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;/*****************************#if (0) //[
// Marked code has been deleted   -- XXXX (18 August, 1994)
// No need to check whether the value is X/X/X
// Only the size is to be checked which has been done
[[[ DELETED

      char  val;

      val=tolower(*((char*) var)-&gt;getValue());
      if ((val != 'X') &amp;&amp; (val != 'X') &amp;&amp; (val != 'X'))
          return 0;
]]]
   #endif //]
*************************************/
&lt;/pre&gt;&lt;br /&gt;
There are many facets to this beautiful gem.  First you'll notice that there is a nice C++-style &lt;code&gt;//&lt;/code&gt; comment -- complete with the date and the signature of Mr. XXXX -- itself commented out by a C-style &lt;code&gt;/*&lt;/code&gt; comment.  Too bad the dead code isn't commented with &lt;code&gt;//&lt;/code&gt;, so that my &lt;code&gt;grep&lt;/code&gt; for &lt;code&gt;tolower&lt;/code&gt; would have stood out as unnecessary.&lt;br /&gt;
&lt;br /&gt;
But look, really the &lt;code&gt;/*&lt;/code&gt; is there to comment out an &lt;code&gt;#if 0&lt;/code&gt;.  The guy must have wanted emacs to colorize the dead code as a comment -- I don't think emacs had font-lock back then, but there was the hilit19 package.&lt;br /&gt;
&lt;br /&gt;
Still, you can't be too careful, so let's also wrap that code up in a &lt;code&gt;[[[DELETED ... ]]]&lt;/code&gt;, in case there is some human that can't read the C comments and the if-0, but who will understand what "triple-bracket DELETED" means.&lt;br /&gt;
&lt;br /&gt;
Finally, it appears the conditional was originally written as &lt;code&gt;#if (0) [ ... ]&lt;/code&gt; -- was that ever legal C? -- but when that wouldn't compile, the brackets had to be commented out, because every character in this file is &lt;i&gt;too precious to ever delete&lt;/i&gt;.  This must be the bad code afterlife.  You can check out anytime you like, but you can never leave.&lt;br /&gt;
&lt;br /&gt;
How did all this happen?  Is it an accumulation of different commenting-out strategies that occurred over time?  Or is it just an unfortunate snapshot of one man's frenzied efforts to remove 3 lines of code without actually deleting anything?  Sadly, we can only speculate on what happened, because these lines entered our repository in exactly this condition over 10 years ago.&lt;br /&gt;
&lt;br /&gt;
I love deleting dead code, but I can't touch this one.  It's an antique.  And so ugly that it's beautiful.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=esUU8x7IcuU:si8NAkn6v9g:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=esUU8x7IcuU:si8NAkn6v9g:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=esUU8x7IcuU:si8NAkn6v9g:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=esUU8x7IcuU:si8NAkn6v9g:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=esUU8x7IcuU:si8NAkn6v9g:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/esUU8x7IcuU" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2010-06-18T14:56:22.529-07:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2010/06/blessed-mother-of-commented-out-code.html</feedburner:origLink></item><item><title>Csh Skips Last Line in Script</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/37U9MThGzrA/csh-skips-last-line-in-script.html</link><category>negative</category><category>csh</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Thu, 10 Jun 2010 16:55:00 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-6667768817381878814</guid><description>Oh, joy.&amp;nbsp; I've found another thing to &lt;a href="http://softwareengisneering.blogspot.com/2009/10/csh-dumbness.html"&gt;hate about csh&lt;/a&gt;.&amp;nbsp; If the last line of your script doesn't have a newline after it, &lt;i&gt;that line won't be executed&lt;/i&gt;.&amp;nbsp; It will be silently ignored.&amp;nbsp; That isn't very useful.&lt;br /&gt;
&lt;br /&gt;
If emacs knows you are editing a shell script, it will automatically put a newline at the end if you didn't do it yourself.&amp;nbsp; But if you have an ordinary text file that you will run with source, it better have a newline at the end.&amp;nbsp; You can get emacs to either ensure that or warn you about it by adding one of the following lines to your .emacs file:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;;; Quietly add a newline if missing.
  (setq require-final-newline t)

  ;; Ask if you want a newline at end of file.
  (setq require-final-newline 'ask)
&lt;/pre&gt;&lt;br /&gt;
Googling for this problem, I found another &lt;a href="http://www.grymoire.com/Unix/CshTop10.txt"&gt;nice csh rant&lt;/a&gt;.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=37U9MThGzrA:o7wSoSov2P0:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=37U9MThGzrA:o7wSoSov2P0:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=37U9MThGzrA:o7wSoSov2P0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=37U9MThGzrA:o7wSoSov2P0:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=37U9MThGzrA:o7wSoSov2P0:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/37U9MThGzrA" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2010-06-10T16:57:45.188-07:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2010/06/csh-skips-last-line-in-script.html</feedburner:origLink></item><item><title>Tcl Case Analysis Lunacy</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/uemm0RhWTZc/tcl-case-analysis-lunacy.html</link><category>negative</category><category>case analysis</category><category>tcl</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Wed, 28 Apr 2010 11:50:00 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-6560951406728726831</guid><description>This goes way back to the roots of this blog.  &lt;a href="http://softwareengisneering.blogspot.com/2008/08/tcl-is-toy-language.html"&gt;Complaining about Tcl&lt;/a&gt;, and complaining about code that breaks down into unnecessary and confusing &lt;a href="http://softwareengisneering.blogspot.com/2008/08/eschew-case-analysis.html"&gt;case analysis&lt;/a&gt; -- those topics were the first three posts here.&lt;br /&gt;
&lt;br /&gt;
Unsurprisingly, the toy language that is Tcl is serving me up some ridiculous case analysis.  It has to do with the C++-side of a Tcl integration.  When you look at the internals of the language objects created by the Tcl interpreter, some things that are conceptually the same have different internal representations.  It's bad enough that I have to succumb to case analysis to figure out what's what:  but on the other side of that wall, Tcl had to do some case analysis to put them all in different representations!  Bad, naughty Tcl.&lt;br /&gt;
&lt;br /&gt;
Here's what's bugging me.  When you look at a &lt;code&gt;Tcl_Obj&lt;/code&gt; over in the C world, it has a &lt;code&gt;typePtr&lt;/code&gt; member to distinguish different types of things:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;A simple name like &lt;code&gt;A&lt;/code&gt; has a &lt;code&gt;NULL&lt;/code&gt; typePtr.&lt;/li&gt;
&lt;li&gt;So does a list of things in braces, like &lt;code&gt;{ A B }&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A name with some special characters like &lt;code&gt;A[0]&lt;/code&gt; has type "string".&lt;/li&gt;
&lt;li&gt;So does a list of things in braces which extends over a few lines, like:&lt;br /&gt;
&lt;pre&gt;{ A \
      B }
&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;An explicit list like &lt;code&gt;[list A]&lt;/code&gt; has type "list".&lt;/li&gt;
&lt;li&gt;A quoted string like &lt;code&gt;"A B"&lt;/code&gt; has &lt;code&gt;NULL&lt;/code&gt;.  At least I think so.  I lost track.&lt;br /&gt;
&lt;/ul&gt;So obviously there are a bunch of &lt;code&gt;if&lt;/code&gt; statements in the back-end tangling stuff up like this.  But it's nearly impossible to untangle it on the C side.&lt;br /&gt;
&lt;br /&gt;
Stupid Tcl.  Stupid case analysis.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=uemm0RhWTZc:KBXMGfxb3aU:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=uemm0RhWTZc:KBXMGfxb3aU:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=uemm0RhWTZc:KBXMGfxb3aU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=uemm0RhWTZc:KBXMGfxb3aU:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=uemm0RhWTZc:KBXMGfxb3aU:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/uemm0RhWTZc" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2011-03-11T16:40:29.362-08:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2010/04/tcl-case-analysis-lunacy.html</feedburner:origLink></item><item><title>Don't Give Variables Negative Names</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/ZeSctbNun78/dont-give-variables-negative-names.html</link><category>negative</category><category>style</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Wed, 10 Mar 2010 22:23:00 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-2584012281797189358</guid><description>Sometimes programmers get caught up in the absence of something.  Don't let that leak over into the name of a variable or data member:&lt;br /&gt;
&lt;pre&gt;bool Job::acceptable(const JobCandidate &amp;applicant) const
{
  bool noFelonyConvictions = findFelonyConvictions(applicant);
  return noFelonyConvictions &amp;&amp; qualified(applicant);
}
&lt;/pre&gt;The &lt;code&gt;noFelonyConvictions&lt;/code&gt; variable documents the code in a readable way, but it gets silly if the code ever changes so that you have to initialize it, or if someone ever wants to know if there &lt;i&gt;are&lt;/i&gt; felony convictions.  Things become less readable:&lt;br /&gt;
&lt;pre&gt;  bool noFelonyConvictions = true;
  if (applicant.findRecords(FELONY)) {
    noFelonyConvictions = false;
  }
  return applicant.qualified(!noFelonyConvictions);
&lt;/pre&gt;It all makes more sense if you name the variable &lt;code&gt;felonyConvictions&lt;/code&gt;, which initializes naturally enough to false, can be set to true if one is found, and can be negated to show absence.  Also, if you later become interested in the number of convictions, there will be fewer code changes if the variable changes from a &lt;code&gt;bool&lt;/code&gt; to an &lt;code&gt;int&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
Whenever you notice yourself putting a "no" into a variable name, get rid of it.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=ZeSctbNun78:Ygu6aq2eECY:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=ZeSctbNun78:Ygu6aq2eECY:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=ZeSctbNun78:Ygu6aq2eECY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=ZeSctbNun78:Ygu6aq2eECY:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=ZeSctbNun78:Ygu6aq2eECY:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/ZeSctbNun78" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2010-03-10T22:27:02.868-08:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2010/03/dont-give-variables-negative-names.html</feedburner:origLink></item><item><title>How to Undeclare a bash Function</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/8S4CGggDinw/how-to-undeclare-bash-function.html</link><category>bash</category><category>tips</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Thu, 04 Feb 2010 17:47:00 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-3165032496881257158</guid><description>It took me a few minutes to figure this out, so I thought I might as well pass it along.&lt;br /&gt;
&lt;br /&gt;
If you've declared a bash function, and then decided you don't really want it, either because you went ahead and implemented it as a script somewhere, or you gave it a bad name or something, you undeclare it like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;  $ unset -f myfunc
&lt;/pre&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=8S4CGggDinw:sD-8W6x9TpA:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=8S4CGggDinw:sD-8W6x9TpA:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=8S4CGggDinw:sD-8W6x9TpA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=8S4CGggDinw:sD-8W6x9TpA:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=8S4CGggDinw:sD-8W6x9TpA:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/8S4CGggDinw" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2010-02-04T17:47:56.903-08:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2010/02/how-to-undeclare-bash-function.html</feedburner:origLink></item><item><title>Nice Code Structure</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/6KwmN3J4RuE/nice-code-structure.html</link><category>c++</category><category>negative</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Mon, 01 Feb 2010 16:29:00 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-2527614379265305248</guid><description>Here's a brilliant one I just ran across at work (variables changed to protect the... to protect someone):&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;  for (i = 0; i &lt; lim; i++) {
    if (someCondition(n[i])) {
      warn("you can't do that");
      continue;
    }
    switch (n[i].type()) {
      default:
        nn = 0;
        warn("we're ignoring this");
        break;
    }
    orig-&gt;doSomethingWith(nn);
    delete nn;
  }
&lt;/pre&gt;&lt;br /&gt;
How do you like that &lt;code&gt;switch&lt;/code&gt; with only a &lt;code&gt;default&lt;/code&gt; branch?  Pretty cool, huh?  Almost is nice is the &lt;code&gt;delete&lt;/code&gt; that only ever sees a &lt;code&gt;NULL&lt;/code&gt;.  Then when I realized &lt;code&gt;doSomethingWith()&lt;/code&gt; is a no-op if it gets a &lt;code&gt;NULL&lt;/code&gt;, I felt even luckier.&lt;br /&gt;
&lt;br /&gt;
Look, if you're making such a big change to some code that you take out &lt;i&gt;all&lt;/i&gt; the branches of a &lt;code&gt;switch&lt;/code&gt;, isn't it worth a couple minutes to clean this up and show what is really happening?  After all, the code really does this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;  for (i = 0; i &lt; lim; i++) {
    if (someCondition(n[i])) {
      warn("you can't do that");
    }
    else {
      warn("we're ignoring this");
    }
  }
&lt;/pre&gt;

It probably makes sense to only give the second warning, since who cares if you can't do it, when really it would only be ignored anyway.  And at that point you might wonder why you need to give the same warning &lt;code&gt;lim&lt;/code&gt; times.&lt;br /&gt;
&lt;br /&gt;
Ugly code kills.  Kill ugly code.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=6KwmN3J4RuE:yeJb6dmxou8:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=6KwmN3J4RuE:yeJb6dmxou8:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=6KwmN3J4RuE:yeJb6dmxou8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=6KwmN3J4RuE:yeJb6dmxou8:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=6KwmN3J4RuE:yeJb6dmxou8:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/6KwmN3J4RuE" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2010-02-01T16:29:22.629-08:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2010/02/nice-code-structure.html</feedburner:origLink></item><item><title>Emacs vs. Nicer dirs</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/kAgHaeZ_P8U/emacs-vs-nicer-dirs.html</link><category>tips</category><category>emacs</category><category>shell</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Fri, 11 Dec 2009 09:43:00 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-1799461363142636897</guid><description>In the last post I described a &lt;a href="http://softwareengisneering.blogspot.com/2009/11/nicer-pushd-popd-and-dirs.html"&gt;nicer version&lt;/a&gt; of the shell &lt;code&gt;dirs&lt;/code&gt; command that labels each directory with its position, so that you can &lt;code&gt;pushd&lt;/code&gt; directly to the one you want.&lt;br /&gt;&lt;br /&gt;One problem with it is that emacs shell-mode generally uses &lt;code&gt;dirs&lt;/code&gt; to track which directory you're in.  And you do want it to track directories for you.  Our nicer version of &lt;code&gt;dirs&lt;/code&gt; produces output that isn't readable to emacs.&lt;br /&gt;&lt;br /&gt;Of course the natural solution is:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; (setq shell-dirstack-query "command dirs")&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;to pick up the shell's builtin &lt;code&gt;dirs&lt;/code&gt;.  Sadly, you can't just throw that line into your .emacs file, because shell-mode sets &lt;code&gt;shell-dirstack-query&lt;/code&gt; every time you start a new shell.  It sets it &lt;span style="font-style: italic;"&gt;unconditionally and globally&lt;/span&gt;, which is a ridiculous design flaw, but that's how it goes.  There is no hook that runs after it sets the value, either.&lt;br /&gt;&lt;br /&gt;So you're stuck with needing a workaround:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Name your command something other than &lt;code&gt;dirs&lt;/code&gt; .&lt;/li&gt;&lt;li&gt;Use a flag on your new &lt;code&gt;dirs&lt;/code&gt; to get the nicer behavior.&lt;/li&gt;&lt;li&gt;Write your own emacs function to start a shell:&lt;/li&gt;&lt;/ol&gt;&lt;pre&gt;&lt;br /&gt;  (defun engisneering-shell ()&lt;br /&gt;    (interactive)&lt;br /&gt;    (shell)&lt;br /&gt;    (setq shell-dirstack-query "command dirs"))&lt;br /&gt;&lt;/pre&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=kAgHaeZ_P8U:u9SgFdquT2w:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=kAgHaeZ_P8U:u9SgFdquT2w:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=kAgHaeZ_P8U:u9SgFdquT2w:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=kAgHaeZ_P8U:u9SgFdquT2w:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=kAgHaeZ_P8U:u9SgFdquT2w:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/kAgHaeZ_P8U" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2009-12-11T09:54:48.490-08:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2009/12/emacs-vs-nicer-dirs.html</feedburner:origLink></item><item><title>Nicer pushd, popd, and dirs</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/99Dqn5KJz4w/nicer-pushd-popd-and-dirs.html</link><category>bash</category><category>tips</category><category>shell</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Tue, 17 Nov 2009 16:38:00 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-6847961066189305331</guid><description>Writing up the safer, friendlier &lt;a href="http://softwareengisneering.blogspot.com/2009/10/bash-vs-which.html"&gt;bash &lt;code&gt;which&lt;/code&gt;&lt;/a&gt; command reminded me of another wrapper function that's handy to have.  If you use &lt;code&gt;pushd/popd&lt;/code&gt; to keep a stack of directories in your shell window, sometimes you want to switch to a directory far down the stack.  If you want to switch to the third directory down, you do &lt;code&gt;pushd +3&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;The problem is, you have to count along the list of directories, since &lt;code&gt;dirs, pushd,&lt;/code&gt; and &lt;code&gt;popd&lt;/code&gt; all just spit out a one-line list of the stack, like this:&lt;pre&gt;&lt;br /&gt;  $ dirs&lt;br /&gt;  /usr/local/share ~ ~/work ~/tmp&lt;br /&gt;&lt;/pre&gt;Not an impossible task, but it can get annoying if you have some long paths in there, especially once your stack gets past two or three deep.  Why not have &lt;code&gt;dirs&lt;/code&gt; print one directory per line, and label them with their depths?  To do so, add this function to your &lt;code&gt;.bashrc&lt;/code&gt; file:&lt;pre&gt;&lt;br /&gt;  function dirs {&lt;br /&gt;      ds=(`command dirs`)&lt;br /&gt;      i=0&lt;br /&gt;      while [ "${ds[$i]}" != "" ]; do&lt;br /&gt;          echo $i: ${ds[$i]};&lt;br /&gt;          i=$((i+1));&lt;br /&gt;      done&lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;Now you get more readable output:&lt;pre&gt;&lt;br /&gt;  $ dirs&lt;br /&gt;  0: /usr/local/share&lt;br /&gt;  1: ~&lt;br /&gt;  2: ~/work&lt;br /&gt;  3: ~/tmp&lt;br /&gt;&lt;/pre&gt;If you want to remove &lt;code&gt;~/work&lt;/code&gt; from the stack, just do &lt;code&gt;popd +2&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;Since &lt;code&gt;pushd&lt;/code&gt; and &lt;code&gt;popd&lt;/code&gt; also print the directory stack, let's add the same style of output to them:&lt;pre&gt;&lt;br /&gt;  function pushd {&lt;br /&gt;      if command pushd $@ &gt; /dev/null; then&lt;br /&gt;          dirs&lt;br /&gt;      fi&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  function popd {&lt;br /&gt;      if command popd $@ &gt; /dev/null; then&lt;br /&gt;          dirs&lt;br /&gt;      fi&lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;One final note.  In case some wacky systemwide file has aliased these commands to something else, add the following unaliasing code to the top of your .bashrc:&lt;pre&gt;&lt;br /&gt;  for func in dirs pushd popd; do&lt;br /&gt;      if alias $func &gt; /dev/null 2&gt;&amp;1 ; then unalias $func; fi&lt;br /&gt;  done&lt;br /&gt;&lt;/pre&gt;Otherwise, your functions will be hidden (aliases take precedence).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;PS: emacs shell-mode has a conflict with this dirs:&lt;/span&gt; here's how to &lt;a href="http://softwareengisneering.blogspot.com/2009/12/emacs-vs-nicer-dirs.html"&gt;fix it&lt;/a&gt;.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=99Dqn5KJz4w:qM1Lw-YESX4:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=99Dqn5KJz4w:qM1Lw-YESX4:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=99Dqn5KJz4w:qM1Lw-YESX4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=99Dqn5KJz4w:qM1Lw-YESX4:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=99Dqn5KJz4w:qM1Lw-YESX4:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/99Dqn5KJz4w" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2009-12-11T09:57:32.255-08:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2009/11/nicer-pushd-popd-and-dirs.html</feedburner:origLink></item><item><title>Keep from Killing Emacs Shell Buffers</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/1hGgS_oYJmM/keep-from-killing-emacs-shell-buffers.html</link><category>tips</category><category>emacs</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Mon, 02 Nov 2009 10:05:00 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-7758925682850841169</guid><description>If you're someone who lives in emacs like I do, then you probably rely on shell buffers (&lt;code&gt;M-x shell&lt;/code&gt;) to interact with the operating system.  That way you can search through output and edit history commands in a natural way that a mere terminal doesn't allow.&lt;br /&gt;&lt;br /&gt;But occasionally I've been left kicking the wall after accidentally killing a shell buffer that had lots of work in it that I still needed.  It really hurts when you accidentally kill a buffer where you're waiting for a long-running process to finish.  To prevent industrial accidents like that, add a guard to &lt;code&gt;kill-buffer-hook&lt;/code&gt; in your .emacs file:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  (add-hook 'kill-buffer-hook&lt;br /&gt;    '(lambda()&lt;br /&gt;       (and&lt;br /&gt;         (string= "Shell" mode-name)&lt;br /&gt;         (or&lt;br /&gt;           (yes-or-no-p&lt;br /&gt;             (format "Kill buffer `%s'? " (buffer-name)))&lt;br /&gt;           (error "Aborted")))))&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If you really &lt;i&gt;do&lt;/i&gt; want to kill the shell buffer, type "yes", and you're done.  But it will save you some grief if you just hit &lt;code&gt;C-x k&lt;/code&gt; in the wrong buffer.&lt;br /&gt;&lt;br /&gt;What's more common for me is that my eyes are on a file that I want to refresh or replace with &lt;code&gt;C-x C-v (find-alternate-file)&lt;/code&gt;, but the cursor is in a shell buffer.  In that case, emacs will indeed load the alternate file, and you'll be asked "Kill buffer ` **lose**'?"  Say no, then you'll have &lt;code&gt;C-x b&lt;/code&gt; to " **lose**" (note the leading space), and rename the shell buffer to "*shell*" or whatever you had previously named it.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=1hGgS_oYJmM:4QYqalinMEA:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=1hGgS_oYJmM:4QYqalinMEA:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=1hGgS_oYJmM:4QYqalinMEA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=1hGgS_oYJmM:4QYqalinMEA:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=1hGgS_oYJmM:4QYqalinMEA:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/1hGgS_oYJmM" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2009-11-02T11:07:14.375-08:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2009/11/keep-from-killing-emacs-shell-buffers.html</feedburner:origLink></item><item><title>Bash vs. Which</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/SAm8gX3n_Ds/bash-vs-which.html</link><category>bash</category><category>tips</category><category>shell</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Mon, 26 Oct 2009 13:03:00 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-5099015712087970393</guid><description>The Unix &lt;code&gt;which&lt;/code&gt; command is useful for searching your &lt;code&gt;$PATH&lt;/code&gt; to find which version of an executable is going to run.  But did you know that it doesn't always tell you the truth?  For instance, it doesn't tell you when the command you're asking about is hidden by a shell builtin (or function, keyword, or alias):&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  $ which echo&lt;br /&gt;  /usr/bin/echo&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;which&lt;/code&gt; found /usr/bin/echo on your path, but &lt;code&gt;echo&lt;/code&gt; is a shell builtin (at least in bash), so that's what will get run, not the one on the path.  The GNU man page for &lt;code&gt;which&lt;/code&gt; presents workarounds that will pick up functions and aliases, but shell builtins still slip through the cracks.  The situation is even weirder on Solaris, where &lt;code&gt;which&lt;/code&gt; is a &lt;b&gt;csh&lt;/b&gt; shell-script, that sources your &lt;code&gt;.cshrc&lt;/code&gt; file as part of its operation -- very strange if your shell is bash.&lt;br /&gt;&lt;br /&gt;Clearly, &lt;code&gt;which&lt;/code&gt; is not to be trusted.  The easiest workaround, if you use bash, is the &lt;code&gt;type&lt;/code&gt; builtin:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  $ type -a echo&lt;br /&gt;  echo is a shell builtin&lt;br /&gt;  echo is /bin/echo&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;A slightly nicer workaround is to make a &lt;code&gt;bash&lt;/code&gt; function for &lt;code&gt;which&lt;/code&gt;, that uses &lt;code&gt;type&lt;/code&gt; to do the right thing.  I also like &lt;code&gt;which&lt;/code&gt; to do an &lt;code&gt;ls -l&lt;/code&gt; where applicable.  Here's what I have in my .bashrc:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  if alias which &gt; /dev/null 2&gt;&amp;1; then unalias which; fi&lt;br /&gt;&lt;br /&gt;  function which {&lt;br /&gt;      hash -r&lt;br /&gt;      t=`type -t $@`&lt;br /&gt;&lt;br /&gt;      if [ -z "${t%%file*}" ]; then&lt;br /&gt;          for p in `type -p $@`; do&lt;br /&gt;              ls -l ${p};&lt;br /&gt;          done&lt;br /&gt;      else&lt;br /&gt;          type $@;&lt;br /&gt;      fi&lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now &lt;code&gt;which&lt;/code&gt; gives you much more information:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  $ which -a wish&lt;br /&gt;  lrwxrwxrwx  1 root  root  13 Dec 23 2008 /usr/local/bin/wish -&gt; /usr/bin/wish*&lt;br /&gt;  lrwxrwxrwx  1 root  root   7 Jan  8 2007 /usr/bin/wish -&gt; wish8.3*&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The unalias protects you in case some systemwide .bashrc or .profile aliases which in some way (unlikely, but good hygiene anyway).  The call to &lt;code&gt;hash&lt;/code&gt; clears the hashed function list, so that any changes to your PATH are reflected.  The reason for the &lt;code&gt;if&lt;/code&gt; statement in the function, is that we certainly want to report builtins, functions, etc., but if there are none, we can use &lt;code&gt;type -p&lt;/code&gt; to make it easier to pass the filenames to &lt;code&gt;ls -l&lt;/code&gt;.  If there are builtins or such, we just punt and give the unaltered &lt;code&gt;type&lt;/code&gt; output.&lt;br /&gt;&lt;br /&gt;You can pass &lt;code&gt;-a&lt;/code&gt; to this &lt;code&gt;which&lt;/code&gt; if you want to see all the matches for the command, in order of precedence.&lt;br /&gt;&lt;br /&gt;Note that this has to be a function, not a script, because running the script will source your .bashrc, which might change the PATH (all PATH changes should be in .profile, but sometimes people do it in .bashrc).&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=SAm8gX3n_Ds:Mk528DnzbEo:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=SAm8gX3n_Ds:Mk528DnzbEo:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=SAm8gX3n_Ds:Mk528DnzbEo:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=SAm8gX3n_Ds:Mk528DnzbEo:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=SAm8gX3n_Ds:Mk528DnzbEo:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/SAm8gX3n_Ds" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2009-11-17T16:26:00.409-08:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2009/10/bash-vs-which.html</feedburner:origLink></item><item><title>Csh Stupidity</title><link>http://feedproxy.google.com/~r/SoftwareEngisneering/~3/hPFRBL46pyk/csh-dumbness.html</link><category>negative</category><category>csh</category><category>shell</category><author>noreply@blogger.com (Bill Night)</author><pubDate>Fri, 02 Oct 2009 16:54:00 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-837664636726682837.post-8489798223027707983</guid><description>One of the great things about the Linux era, is that bash seems to be taking over as the preferred shell to use, instead of csh/tcsh.  The projects at my current job began during the SunOS era, so when I started there a couple years ago I went with the flow and let the sysadmin set up my default as tcsh just like everyone else there uses.  When I was getting started, no one had a reasonable .profile or .bashrc I could use, so I went with tcsh so I could use the tribal .cshrc.&lt;br /&gt;
&lt;br /&gt;
In terminals, the first command I run is "bash"; most of my work is in an emacs shell window, so my .emacs says &lt;code&gt;(setq shell-file-name "/bin/bash")&lt;/code&gt; -- actually there's an (if) in there to choose cygwin's bash if I happen to be on Windows.  I do a lot of shell programming at the command line, and I simply can't live with csh-style programming.&lt;br /&gt;
&lt;br /&gt;
A few days ago I was working on my .cshrc file, and I noticed how dim-witted csh's if-else handling is.  The classic anti-csh diatribe is &lt;a href="http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/"&gt;Csh Programming Considered Harmful&lt;/a&gt;, which is an entertaining read, but there's some insanity that isn't even covered in that worthy rant.  Let me start by presenting a correct csh script:&lt;br /&gt;
&lt;pre&gt;setenv FOO hello
if ($FOO == hello) then
echo hi
else if ($FOO == goodbye) then
echo see ya
endif
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Source that script, and the output is:&lt;br /&gt;
&lt;pre&gt;hi
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Various typos can have effects on this script that range from annoying to silent but deadly.  Here's an annoying one:  put the second &lt;code&gt;if&lt;/code&gt; on a different line from the &lt;code&gt;else&lt;/code&gt;.  The output is:&lt;br /&gt;
&lt;pre&gt;hi
else: endif not found.
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Well, at least you got an error message telling you something is up, although requiring two keywords to be on the same line is a level of stupidity worthy of Tcl.  What if you do the opposite, and have too many &lt;code&gt;endifs&lt;/code&gt;?  Well, the output is just "hi", with no error message.  I suppose that doesn't bite too much, until later when you nest another &lt;code&gt;if&lt;/code&gt; into the script, and it suddenly gets closed by one of your stealth extra &lt;code&gt;endifs&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
But here's a bad one.  Take the original script.  Add an &lt;code&gt;else&lt;/code&gt; at the beginning, and an &lt;code&gt;endif&lt;/code&gt; at the end.  Seems like an &lt;code&gt;else&lt;/code&gt; without an accompanying &lt;code&gt;if&lt;/code&gt; should get a syntax error, but it doesn't.  The extra &lt;code&gt;endif&lt;/code&gt; -- which might have been there because we always had an extra one, but never got an error about it -- closes the weird &lt;code&gt;else&lt;/code&gt;.  And guess what?  The script runs with no errors, and &lt;i&gt;no output&lt;/i&gt;.  The &lt;code&gt;else&lt;/code&gt; is kind of a "if not true".  How can this be a good thing?&lt;br /&gt;
&lt;br /&gt;
I did these experiments with &lt;code&gt;csh&lt;/code&gt; and &lt;code&gt;tcsh&lt;/code&gt; on RedHat.  Avoid &lt;code&gt;csh&lt;/code&gt;.  Long live &lt;code&gt;bash&lt;/code&gt;!&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=hPFRBL46pyk:2Gj71jaPV5k:3QFJfmc7Om4"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=hPFRBL46pyk:2Gj71jaPV5k:3QFJfmc7Om4" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=hPFRBL46pyk:2Gj71jaPV5k:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SoftwareEngisneering?a=hPFRBL46pyk:2Gj71jaPV5k:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SoftwareEngisneering?i=hPFRBL46pyk:2Gj71jaPV5k:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareEngisneering/~4/hPFRBL46pyk" height="1" width="1"/&gt;</description><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2010-06-10T16:56:13.793-07:00</atom:updated><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://softwareengisneering.blogspot.com/2009/10/csh-dumbness.html</feedburner:origLink></item></channel></rss>
