Thursday, November 19, 2015

Digest for comp.lang.c++@googlegroups.com - 4 updates in 3 topics

Gareth Owen <gwowen@gmail.com>: Nov 19 10:34PM


> Unnecessary functional decomposition can often increase a program's
> complexity and in this case it is only necessary due to a shortcoming
> in the language's syntax sausages.
 
Quite.
 
Very few would suggest that the inner loop of
 
for(int r=0; r < rows;++r){
for(int c=0; c < cols;++c){
total += frobincate(arr[r][c]);
}
}
 
be refactored into a subroutine due to it inordinate length.
 
It may be that the lack of a multi-level break means that such
refactoring is the least of several evils in Mr Flibble's premature-exit
use-case, but lets not pretend that's a good thing.[0]
 
Similarly, using a lambda is a nice trick, but it would be better if the
trick were not necessary.
 
Personally, I prefer both the goto, and the
 
class NonLocalExit {};
 
try {
...
if(found) throw NonLocalExit;
...
}
catch(const NonLocalExit& e) {}
 
idiom.
Ian Collins <ian-news@hotmail.com>: Nov 20 11:53AM +1300

Gareth Owen wrote:
> }
> }
 
> be refactored into a subroutine due to it inordinate length.
 
No, but that wasn't the original form, was it? The original code was
looking for something, which in my opinion makes it an ideal candidate
for an extract method refactoring.
 
> It may be that the lack of a multi-level break means that such
> refactoring is the least of several evils in Mr Flibble's premature-exit
> use-case, but lets not pretend that's a good thing.[0]
 
I think it is. What would be clearer in the code flow, a nested loop
with a clunky exit mechanism or a call to an appropriately named function?
 
Let the compiler sort out the exit strategy when it inlines the function!
 
> ...
> }
> catch(const NonLocalExit& e) {}
 
That's a terrible abuse of exceptions!
 
--
Ian Collins
nobody <nobody@nowhere.nohow>: Nov 19 02:29PM -0800

> under gcc. Needless to say, I don't always (are really ever) care
> about files that begin with 'a'. I am interested in, say, files that
> end in ".txt" but I don't understand what's needed here.
 
If you do it the C way you would use a string comparison:
 
int filter(const dirent * filterpattern)
{
if (strstr(filterpattern->d_name, ".txt"))
return 1;
else
return 0;
}
 
The strstr function returns a pointer to the first occurance of 2nd argument
in the first argument, otherwise NULL. Since we don't care about this pointer
we simply flag it as found or not.
 
> more extensively than in the Wirthian languages.
 
> Thanks,
> Rob
 
Lots of unnecessary included headers here.
 
> #include <ctime>
> #include <string>
> using namespace std;
--^^^^^^^^^^^^^^^^^^^^^
We'll let this one slide.
 
> char * CurrentPathName;
 
> CurrentPathName = getcwd(pathname,MAXPATHLEN);
> if (pathname == NULL )
-------^^^^^^^^^
I think you meant to write CurrentPathName not pathname here.
 
> cout << "Error getting path" << endl;
> exit(0);
> }
 
 
filterpattern is unused and not needed, discard this line and the declaration.
 
Robert Wessel <robertwessel2@yahoo.com>: Nov 19 04:24PM -0600

On Thu, 19 Nov 2015 15:41:13 GMT, scott@slp53.sl.home (Scott Lurndal)
wrote:
 
>moved to a separate header file when circular dependencies exist).
 
>Multiline functions within the class definition seriously impair
>readability, IMO.
 
 
They do, but that's a trade-off like everything else. OTOH, it should
*not* be a tradeoff when considering code size and optimization,
assuming a semi-competent compiler and link time code generation.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: