Thursday, March 1, 2018

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

John Appleyard <spamtrap@polyhedron.com>: Mar 01 09:31PM

HypeKWIC generates software documentation from source code. The
documentation takes the form of a hyper-linked KeyWord In Context (KWIC)
document which can be viewed in a standard web browser. HyperKWIC can
be used with source code written in any language, including Fortran, C,
C++, Java, Delphi etc., and can be configured for comments, reserved
words, case-sensitivity etc. You can interact with sample reports for
large Fortran and C programs at
https://polyhedronsolutions.com/hyperkwic_files/AERMOD/_hyperkwic.htm
and
https://polyhedronsolutions.com/hyperkwic_files/netcdf-4.4.1.1/_hyperkwic.htm
 
HyperKWIC is free for non-commercial use including evaluation. See
www.hyperkwic.com.
--
JRA
"Öö Tiib" <ootiib@hot.ee>: Mar 01 02:28PM -0800

On Thursday, 1 March 2018 23:31:32 UTC+2, John Appleyard wrote:
> be used with source code written in any language, including Fortran, C,
> C++, Java, Delphi etc., and can be configured for comments, reserved
> words, case-sensitivity etc.
 
Doxygen is free and open source and so it is unclear why you wrote that
strange thing. Better erase it and write something that aids or
simplifies with usage of Doxygen. I can't tell what could make it
more trivial but judging by your work you have better fantasy than me.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Mar 01 11:56PM +0100

On 01.03.2018 23:28, Öö Tiib wrote:
> strange thing. Better erase it and write something that aids or
> simplifies with usage of Doxygen. I can't tell what could make it
> more trivial but judging by your work you have better fantasy than me.
 
I remember we had to do KWIC in COBOL at university. 1986. It was on a
Burroughs mainframe.
 
Argh.
 
 
Cheers!,
 
- Alf
legalize+jeeves@mail.xmission.com (Richard): Mar 01 11:22PM

[Please do not mail me a copy of your followup]
 
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> spake the secret code
 
>I remember we had to do KWIC in COBOL at university. 1986. It was on a
>Burroughs mainframe.
 
B6700? :)
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Mar 01 02:55PM +0100

On 01.03.2018 01:57, JiiPee wrote:
> afterLoop:
 
> I googled and this seems to be manys preferably way. I have this often.
> How would you break nested loops? Somebody said Substroup said this is ok.
 
I forgot to mention, you can also use a single 2D index and ordinary
`break` from the then single `for` loop, like this:
 
#include <iostream>
#include <iomanip>
using namespace std;
 
auto main()
-> int
{
const int w = 5;
const int h = 7;
for( my::Indices indexing{{ w, h }}; not indexing.at_end();
++indexing )
{
if( inner( indexing ) == 3 and outer( indexing ) == 5 )
{
break;
}
 
const bool first_item = (inner( indexing ) == 0);
const bool new_row = (first_item and outer( indexing )
> 0);
 
cout << (new_row? "\n" : first_item? "" : ", ");
cout << setw( 2 ) << inner( indexing ) + 5*outer( indexing );
}
cout << endl;
}
 
Support machinery that can easily be made reusable (amortized O(1)
programmer's time):
 
#include <array>
 
namespace my{
using std::array;
 
struct Indices
{
static constexpr int n = 2;
 
array<int, n> const limits;
array<int, n> values;
 
void operator++()
{
for( int i = 0; i < n; ++i )
{
int& index = values[i];
++index;
if( index != limits[i] )
{
break;
}
index = 0;
}
}
 
auto at_end() const
-> bool
{
for( int i = 0; i < n - 1; ++i )
{
if( values[i] != 0 )
{
return false;
}
}
return values.back() == limits.back();
}
};
 
inline auto inner( Indices& indexing )
-> int&
{ return indexing.values[0]; }
 
inline auto outer( Indices& indexing )
-> int&
{ return indexing.values[1]; }
 
} // namespace my
 
Cheers & hth.,
 
- Alf
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Mar 01 02:58PM +0100

On 01.03.2018 14:55, Alf P. Steinbach wrote:
 
>     }  // namespace my
 
> Cheers & hth.,
 
> - Alf
 
Oh so nice there's a bug -- to find. :-)
 
Cheers!
 
- Alf
JiiPee <no@notvalid.com>: Mar 01 05:39PM

> }
> }
> }();
 
yes thats what I meant. benefit is that you can see the code in the place
JiiPee <no@notvalid.com>: Mar 01 05:45PM

On 01/03/2018 02:21, Christiano wrote:
> And the solution with goto seems very simple.
 
 
Just first time testing goto in my code to see how it works.
 
But sure sometimes the solution is to make better code structure.. but
its a handy solution for quick fix if perfect code not needed.
JiiPee <no@notvalid.com>: Mar 01 05:47PM

On 01/03/2018 02:35, Bo Persson wrote:
> If you have 4 nested loops using 10 different variables, how are we
> going to know their values after the goto?
 
no but how about a very simple 4 nested loop (like doing only one
assigment and having 0-1 variables). Then goto would work pretty well?
JiiPee <no@notvalid.com>: Mar 01 05:58PM

Ok, so how about lets say we have to do that 4 nested loop like this:
 
for (int i= 0; i <= 5; +i)
for (int i2= 0; i2 <= 5; +i2)
for (int i3= 0; i3 <= 5; +i3)
for (int i4= 0; i4 <= 5; +i4)
  if(checkCondition(i, i2, i3, i4))
    goto end_loop;
endloop:
 
so here is no variables and one simple function call. So how would you
end that otherwise than using a goto?
"James R. Kuyper" <jameskuyper@verizon.net>: Mar 01 01:25PM -0500

On 03/01/2018 12:58 PM, JiiPee wrote:
> Ok, so how about lets say we have to do that 4 nested loop like this:
 
> for (int i= 0; i <= 5; +i)
 
That should be ++i, not +i. "+i" is well-formed code that has no useful
effect in this context.
If there were an operator overload for unary + that applied to i, that
would be a different matter - but you can't overload operators for int.
 
>   if(checkCondition(i, i2, i3, i4))
>     goto end_loop;
> endloop:
 
You wrote end_loop and endloop right next to each other, and managed to
spell them differently? :-)
 
If checkCondition() returns a value that depends only upon the values of
it's arguments, and has no side-effects, then all of the above code
could be optimized away.
If that's not the case, I would need to know what checkCondition() does
that means it can't be optimized away, in order to answer the following
question:
 
> so here is no variables and one simple function call. So how would you
> end that otherwise than using a goto?
 
However, while I am among the most fanatical "goto" opponents (partially
due to a traumatic experience with thousands of lines of spaghetti
FORTRAN code on my first paid programming job), I'm not sufficiently
fanatical to deny that code similar to this could be a legitimate reason
for using one.
Real Troll <real.troll@trolls.com>: Mar 01 02:30PM -0400

On 01/03/2018 17:58, JiiPee wrote:
> endloop:
 
> so here is no variables and one simple function call. So how would you
> end that otherwise than using a goto?
 
What does CheckCondition do? Generally I would break from the loop if
certain conditions are satisfied like in this example:
 
for (int i = 1; i < 10; i++)
{
cout << i << '\n';
if (i == 4)
break;
}
"Öö Tiib" <ootiib@hot.ee>: Mar 01 11:49AM -0800

On Thursday, 1 March 2018 19:47:12 UTC+2, JiiPee wrote:
> > going to know their values after the goto?
 
> no but how about a very simple 4 nested loop (like doing only one
> assigment and having 0-1 variables). Then goto would work pretty well?
 
There are nothing wrong with using goto to exit nested loops. It is valid
sentence in C++ language. That sentence is very rarely used not
because it is bad but because there is often something else wrong
with code that uses it. Too lot of nested brute force loops may be
such "wrong".
 
I don't remember a case in last 25 years when usage of goto
was raised as issue itself in review. I remember couple cases where
while loop together with continue was used as goto and received
"better use goto" in review.
 
It is worth to note that the compilers tend to optimize code that uses
goto's more carefully. It may be quality of implementation issue and
it usually does not matter.
JiiPee <no@notvalid.com>: Mar 01 02:10AM

On 01/03/2018 02:00, Christiano wrote:
> }
 
> But that does not seem like an elegant solution. Alf's solution
> unfortunately puts it in another function.
 
 
ok but what if you have 4 loops nested? Then would become a bit
difficult to set those indexes.
"Öö Tiib" <ootiib@hot.ee>: Mar 01 12:20PM -0800

On Thursday, 1 March 2018 19:58:50 UTC+2, JiiPee wrote:
> endloop:
 
> so here is no variables and one simple function call. So how would you
> end that otherwise than using a goto?
 
There is nothing wrong with goto there. It has been already replied
that it can be replaced with making the loop separate function
and using return instead of goto in it. Also it has been already
replied that it involving loop can be indicated with function name
(like "deep_loop()").
guinness.tony@gmail.com: Mar 01 02:32PM -0800

On Thursday, 1 March 2018 17:58:50 UTC, JiiPee wrote:
> endloop:
 
> so here is no variables and one simple function call. So how would you
> end that otherwise than using a goto?
 
That code is the equivalent of
 
If (checkCondition(0, 0, 0, 0))
{
goto end_loop; // wherever that is - you didn't show it
}
else
{
for (;;)
{
// loop perpetually, doing nothing useful
}
}
"James R. Kuyper" <jameskuyper@verizon.net>: Mar 01 08:32AM -0500

On 03/01/2018 04:05 AM, Ralf Goertz wrote:
...
> cout<<"The regex "<<url_string<<endl<<endl;
...
> } else {
> cout<<"matches "<<s<<endl;
> cout<<"Protokoll: "<<sm[1]<<endl;
 
Protocol? The rest of your text use English spellings.
 
Ralf Goertz <me@myprovider.invalid>: Mar 01 03:45PM +0100

Am Thu, 1 Mar 2018 08:32:36 -0500
> > cout<<"matches "<<s<<endl;
> > cout<<"Protokoll: "<<sm[1]<<endl;
 
> Protocol? The rest of your text use English spellings.
 
Well, I am German and similar words can make me switch languages. Sorry
about that. Yes, Protocol, which -- used in the middle of a sentence
like I just did -- should be spelled with a small p. But we Germans (big
G?) like to capitali[sz]e not only „God" but all nouns (#atheism). At
least we are humble enough to lowercase „I". :-)
legalize+jeeves@mail.xmission.com (Richard): Mar 01 06:02PM

[Please do not mail me a copy of your followup]
 
Ralf Goertz <me@myprovider.invalid> spake the secret code
 
>Hm, ugliness is in the eye of the beholder [quick & dirty]:
 
> string
>url_string("([^:]+)://((([^:@]+)(:([^@]+))?@))?([^:/]+)(:([0-9]+))?/(.+)");
 
Even as a regular user of regex'es I consider that truly barfworthy :)
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
Jorgen Grahn <grahn+nntp@snipabacken.se>: Mar 01 08:24PM

On Thu, 2018-03-01, Ralf Goertz wrote:
> "http://user:passwd@testhost.dom:4353/rest",
> "http://user:passwd@testhost.dom/rest"};
> string url_string("([^:]+)://((([^:@]+)(:([^@]+))?@))?([^:/]+)(:([0-9]+))?/(.+)");
 
I couldn't get an alternative to work in a few minutes (shame on me!)
but some critizism anyway:
 
- You assume the port has to be numerical, but it costs nothing to let
the user give standard service names. (This was one of the
weaknesses in the OP's specification.)
 
- You could probably simplify the expression by using the non-greedy
modifier here and there e.g. .+?: instead of [^:]+: to say "some
text before a colon".
 
- More weaknesses from the specification: I suspect a valid protocol
name is matched by \w+ ("one or more word characters") but you
accept for example a single space.
 
- The OP should add plenty of negative tests too.
 
...
> Of course, care must be taken if user and/or password contain one of the
> special characters.
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
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: