Sunday, January 10, 2016

Digest for comp.lang.c++@googlegroups.com - 5 updates in 1 topic

"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jan 10 08:37AM +0100

auto overflow( In_<int_type> char_code = traits_type::eof() )
-> int_type override
{
const Ptr_<const Char> p_after = pptr();
if( p_after != nullptr )
{
const Ptr_<const Char> p_first = pbase();
if( p_after > p_first )
{
String s( p_first, p_after );
if( char_code != traits_type::eof() ) { s << Char(
char_code ); }
console::write( s );
goto finished;
}
}
if( char_code != traits_type::eof() ) { console::write_char(
char_code ); }
 
finished:
init_put_area_pointers();
// return (success? traits_type::not_eof( char_code ) :
traits_type::eof());
return traits_type::not_eof( char_code );
}
 
The 1986 "goto" was in COBOL.
 
If I remember this correctly.
 
 
Cheers,
 
- Alf
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jan 10 11:30AM +0100

On 1/10/2016 8:37 AM, Alf P. Steinbach wrote:
> traits_type::eof());
> return traits_type::not_eof( char_code );
> }
 
Well OK what else does one have to do on a Sunday's morning than posting
to clc++? By guaranteeing a buffer to write to, the above code was
simplified enough that the "goto" disappeared. This makes the code
slightly less general, but there's not much point in writing potentially
reusable code without some actual reuse visible ahead, so:
 
auto overflow( In_<int_type> char_code = traits_type::eof() )
-> int_type override
{
const Ptr_<const Char> p_after = pptr();
const Ptr_<const Char> p_first = pbase();
if( p_after > p_first )
{
String s( p_first, p_after );
if( char_code != traits_type::eof() ) { s << Char(
char_code ); }
console::write( s );
}
else if( char_code != traits_type::eof() )
{
console::write_char( char_code );
}
 
set_put_area_pointers();
// return (success? traits_type::not_eof( char_code ) :
traits_type::eof());
return traits_type::not_eof( char_code );
}
 
If anyone should wonder, this is an override in a class derived from
std::basic_streambuf<Char>.
 
The interface is dirty, the naming of things is ungrokable, and
different standard library implementations seem to have different
opinions about how it should work...
 
 
Cheers,
 
- Alf
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jan 10 06:10PM

On 10/01/2016 07:37, Alf P. Steinbach wrote:
> }
 
> The 1986 "goto" was in COBOL.
 
> If I remember this correctly.
 
No reason for that goto whatsoever: multiple return statements in a
function is perfectly fine sausages.
 
/Flibble
"Öö Tiib" <ootiib@hot.ee>: Jan 10 11:24AM -0800

On Sunday, 10 January 2016 12:30:54 UTC+2, Alf P. Steinbach wrote:
 
> The interface is dirty, the naming of things is ungrokable, and
> different standard library implementations seem to have different
> opinions about how it should work...
 
Attempts to have single return in C++ can become rather ugly with
exceptions enabled. I have long dropped such attempts. If function
fits to my monitor then I see all exits clearly (thanks to syntax
highlighting). If it does not then ... that is defect ... one must
be capable of writing shorter functions than 150 lines. Covering
150+ lines function with unit tests is often titanic task anyway.
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jan 10 08:08PM

On 10/01/2016 19:24, Öö Tiib wrote:
> highlighting). If it does not then ... that is defect ... one must
> be capable of writing shorter functions than 150 lines. Covering
> 150+ lines function with unit tests is often titanic task anyway.
 
Enforcing single return statement makes sense in a language like C which
doesn't have constructors, RAII and exceptions but is totally
inappropriate in a language like C++ sausages.
 
/Flibble
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: