Sunday, December 18, 2016

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

Gareth Owen <gwowen@gmail.com>: Dec 18 09:15PM

>> number of times, looking for a pivot value, without changing the
>> order of the algorithm.
 
> Nah.
 
Mathematics is not a strength.
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Dec 18 09:49PM

On 18/12/2016 21:15, Gareth Owen wrote:
>>> order of the algorithm.
 
>> Nah.
 
> Mathematics is not a strength.
 
The bullshit branches of Mathematics are indeed not a strength mate
because I see them for what they are: nonsense; they should be an
adjunct to mathematics not a part of mathematics. There is no negative
zero; and division by zero is undefined.
 
/Flibble
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Dec 18 09:51PM

On 18/12/2016 21:49, Mr Flibble wrote:
> because I see them for what they are: nonsense; they should be an
> adjunct to mathematics not a part of mathematics. There is no negative
> zero; and division by zero is undefined.
 
And whilst on the subject of bullshit mathematics: a countable infinity
is unbounded just like an uncountable one.
 
/Flibble
Gareth Owen <gwowen@gmail.com>: Dec 18 09:52PM

> because I see them for what they are: nonsense; they should be an
> adjunct to mathematics not a part of mathematics. There is no negative
> zero; and division by zero is undefined.
 
Mathematics is not a strength is it. Simple maths - junior school maths
- you're ok with. Harder stuff you just dismiss.
 
Tell us again how linked lists change the order of quicksort.
Show your working.
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Dec 18 09:56PM

On 18/12/2016 21:52, Gareth Owen wrote:
>> zero; and division by zero is undefined.
 
> Mathematics is not a strength is it. Simple maths - junior school maths
> - you're ok with. Harder stuff you just dismiss.
 
No I don't dismiss the harder stuff; I dismiss bollocks such as
projective geometry. It isn't mathematics it is an abstraction of
mathematics.
 
 
> Tell us again how linked lists change the order of quicksort.
 
See my other reply.
 
> Show your working.
 
Fuck off you self important cunt.
 
/Flibble
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Dec 18 10:04PM

On 18/12/2016 21:56, Mr Flibble wrote:
 
> No I don't dismiss the harder stuff; I dismiss bollocks such as
> projective geometry. It isn't mathematics it is an abstraction of
> mathematics.
 
As I can read you like a book and anticipate your next reply: yes the
complex plane is an abstraction and no I don't think complex number
theory is bullshit. This is not the same kind of abstraction as made
with projective geometry.
 
/Flibble
Paavo Helde <myfirstname@osa.pri.ee>: Dec 19 12:22AM +0200

On 19.12.2016 0:04, Mr Flibble wrote:
> complex plane is an abstraction and no I don't think complex number
> theory is bullshit. This is not the same kind of abstraction as made
> with projective geometry.
 
So, how do you tell apart which abstractions are good and which are bad?
In my naivety I have always thought all the maths is abstractions,
basically about the same kind ...
Gareth Owen <gwowen@gmail.com>: Dec 18 10:52PM


> No I don't dismiss the harder stuff; I dismiss bollocks such as
> projective geometry. It isn't mathematics it is an abstraction of
> mathematics.
 
What a terrifically, splendiferously meaningless statement.
Mathematics is not a strength, is it?
 
>> Tell us again how linked lists change the order of quicksort.
 
> See my other reply.
 
Offered no evidence or subject knowledge to back up your assertion.
Clearly mathematics is not a strength.
 
>> Show your working.
 
> Fuck off you self important cunt.
 
Now you just sound like Jerry Stuckle (albeit with a more enjoyably
Anglo-Saxon vocabulary). Maybe best stick to saying "sausages" and
pissing off fundies, yeah?
 
Clearly, that is where you true abilities lie.
sgihal56@gmail.com: Dec 18 12:12PM -0800

I been tasked to port an old scientific program to C++. I am new to C++ and OOP programming and could use some help in designing a set of classes to handle the input tables. The program data is provided via a set of about 100 ASCII input data tables (not to be confused with database tables). The program can handle multiple versions of each table (the exact number of each table is provided). Each table has data that has no relationship to any other table. Each table has a fixed maximum number of independent variables (1, 2, or 3) although many tables can be provided at less than the maximum. For example, a 3-D table can be input as a 2-D table if one parameter is not available. The format of each table is similar but there will be a need to handle special situations. The class(s) will have methods to allocate the array of structures to hold the number of each table, method to allocate the array to hold the data of a specific table (one of the structure members), method to read and write the tables and final a method for table lookup.
 
How many classes do you think is required to handle the input? Any other thoughts or suggestions on the class design would really be appreciated….
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Dec 18 10:24PM +0100

> I been tasked to port an old scientific program to C++.
 
Then it matters what language it was written in originally.
 
 
> I am new to C++ and OOP programming and could use some help in
> designing a set of classes to handle the input tables.
 
The C++ standard library lacks a 2D array class and you need that.
 
There's one in the Boost library but as I recall it's designed for speed
rather than safety.
 
Oh look, there a simple one in the SO C++ documentation!
 
<url:
http://stackoverflow.com/documentation/c%2b%2b/3017/arrays/10246/a-dynamic-size-matrix-using-stdvector-for-storage#t=201612182117279263232>
 
[code]
// A dynamic size matrix using std::vector for storage.
 
//--------------------------------------------- Machinery:
#include <algorithm> // std::copy
#include <assert.h> // assert
#include <initializer_list> // std::initializer_list
#include <vector> // std::vector
#include <stddef.h> // ptrdiff_t
 
namespace my {
using Size = ptrdiff_t;
using std::initializer_list;
using std::vector;
 
template< class Item >
class Matrix
{
private:
vector<Item> items_;
Size n_cols_;
 
auto index_for( Size const x, Size const y ) const
-> Size
{ return y*n_cols_ + x; }
 
public:
auto n_rows() const -> Size { return items_.size()/n_cols_; }
auto n_cols() const -> Size { return n_cols_; }
 
auto item( Size const x, Size const y )
-> Item&
{ return items_[index_for(x, y)]; }
 
auto item( Size const x, Size const y ) const
-> Item const&
{ return items_[index_for(x, y)]; }
 
Matrix(): n_cols_( 0 ) {}
 
Matrix( Size const n_cols, Size const n_rows )
: items_( n_cols*n_rows )
, n_cols_( n_cols )
{}
 
Matrix( initializer_list< initializer_list<Item> > const& values )
: items_()
, n_cols_( values.size() == 0? 0 : values.begin()->size() )
{
for( auto const& row : values )
{
assert( Size( row.size() ) == n_cols_ );
items_.insert( items_.end(), row.begin(), row.end() );
}
}
};
} // namespace my
 
//--------------------------------------------- Usage:
using my::Matrix;
 
auto some_matrix()
-> Matrix<int>
{
return
{
{ 1, 2, 3, 4, 5, 6, 7 },
{ 8, 9, 10, 11, 12, 13, 14 },
{ 15, 16, 17, 18, 19, 20, 21 }
};
}
 
#include <iostream>
#include <iomanip>
using namespace std;
auto main() -> int
{
Matrix<int> const m = some_matrix();
assert( m.n_cols() == 7 );
assert( m.n_rows() == 3 );
for( int y = 0, y_end = m.n_rows(); y < y_end; ++y )
{
for( int x = 0, x_end = m.n_cols(); x < x_end; ++x )
{
cout << setw( 4 ) << m.item( x, y ); // ← Note: not
`m[y][x]`!
}
cout << '\n';
}
}
[/code]
 
 
 
> members), method to read and write the tables and final a method for
> table lookup.
 
> How many classes do you think is required to handle the input?
 
One.
 
 
> Any other thoughts or suggestions on the class design would really be
> appreciated….
 
For ordinary main processor execution it's a good idea to use
`std::vector` to handle the memory management for you.
 
Depending on what you're doing you might find `std::valarray` useful.
It's a 1990's design for doing operations possibly in parallel on all
items of an array or arrays. However, I have yet to see it used and I
have not used it myself (it's a bit complex here and there), and I don't
think that's the way to go if you want to leverage GPU processing.
 
I guess some others will chime in with suggestions about what to use for
GPU processing, which you probably will want to use.
 
 
Cheers & hth.,
 
- Alf
Louis Krupp <lkrupp@nospam.pssw.com.invalid>: Dec 18 02:24PM -0700


>I been tasked to port an old scientific program to C++. I am new to C++ and OOP programming and could use some help in designing a set of classes to handle the input tables. The program data is provided via a set of about 100 ASCII input data tables (not to be confused with database tables). The program can handle multiple versions of each table (the exact number of each table is provided). Each table has data that has no relationship to any other table. Each table has a fixed maximum number of independent variables (1, 2, or 3) although many tables can be provided at less than the maximum. For example, a 3-D table can be input as a 2-D table if one parameter is not available. The format of each table is similar but there will be a need to handle special situations. The class(s) will have methods to allocate the array of structures to hold the number of each table, method to allocate the array to hold the data of a specific table (one of the structure members), method to read
>and write the tables and final a method for table lookup.
 
>How many classes do you think is required to handle the input? Any other thoughts or suggestions on the class design would really be appreciated….
 
Can you give an example of what you're talking about? If you were
going to write a detailed statement of the problem to be solved, what
would that look like?
 
Is the old program still running? What language does it use? Can you
post the source or, if it's too long, a link to the source?
 
Louis
sgihal56@gmail.com: Dec 18 02:13PM -0800

The original program was written in Fortran 66 and is still operational. Management has directed us to start migrating our old codes to C++. The source code is proprietary (sorry). All tables are stored in single dimensional arrays (common for old code) so a 2D array is not necessary. There are separate table lookup functions for single, double and triple independent variables.
 
Alf...how would I design a single class to handle 1, 2, and 3 independent variables? Would the class contain code specific to each number of independent variables? Would I pass the table number (used to identify the tables) so the class can determine how many independent variables are required?
 
Thanks again for the help.
Paavo Helde <myfirstname@osa.pri.ee>: Dec 19 12:17AM +0200

> I been tasked to port an old scientific program to C++. I am new to C++ and OOP programming and could use some help in designing a set of classes to handle the input tables. The program data is provided via a set of about 100 ASCII input data tables (not to be confused with database tables). The program can handle multiple versions of each table (the exact number of each table is provided). Each table has data that has no relationship to any other table. Each table has a fixed maximum number of independent variables (1, 2, or 3) although many tables can be provided at less than the maximum. For example, a 3-D table can be input as a 2-D table if one parameter is not available. The format of each table is similar but there will be a need to handle special situations. The class(s) will have methods to allocate the array of structures to hold the number of each table, method to allocate the array to hold the data of a specific table (one of the structure members), method to read
and write the tables and final a method for table lookup.
 
> How many classes do you think is required to handle the input? Any other thoughts or suggestions on the class design would really be appreciated….
 
The first question is why this program needs to be ported to C++? If it
is just for not having to deal with multiple compilers, then find and
use an automatic converter from the original language the C, then rename
the resulting files from .c to .cpp, and voila, you are done!
 
I see another misconception in your post, apparently you think that C++
and OOP are somehow synonymous. They are not, C++ supports OOP indeed,
but there are many other methodologies it supports. It might well be
that there appear a couple of classes in a decent port of an old
library, but it is not given that the classes would play a central role
there.
sgihal56@gmail.com: Dec 18 02:29PM -0800

Paavo,
 
Converters tend to generate horrible code. In addition to porting the code to C++, we also plan on a major update to the program overall architecture to make it much easier to maintain and modify.
 
What would be nice is to see a UML diagram of what a table class would contain. At this point I am just look for a top level class overview to see how it might work....Thanks
Louis Krupp <lkrupp@nospam.pssw.com.invalid>: Dec 18 03:49PM -0700


>The original program was written in Fortran 66 and is still operational. Management has directed us to start migrating our old codes to C++. The source code is proprietary (sorry). All tables are stored in single dimensional arrays (common for old code) so a 2D array is not necessary. There are separate table lookup functions for single, double and triple independent variables.
 
>Alf...how would I design a single class to handle 1, 2, and 3 independent variables? Would the class contain code specific to each number of independent variables? Would I pass the table number (used to identify the tables) so the class can determine how many independent variables are required?
 
>Thanks again for the help.
 
Are you talking about table lookup? Is a table with three independent
variables a way to represent a function f(x, y, z), with each row of
the table containing values for x, y, z and f, and do you want to
search the table for x, y and z and then return f?
 
Or do you need, say, linear interpolation, where the table gives you
f(1, 2, 3) and f(2, 2, 3) and you need to compute f(1.5, 2, 3)?
 
Can you give any examples of what the program does? Or would that risk
revealing proprietary information?
 
You might try converting the program by hand to a C-like subset of
C++, getting it to work and verifying it by comparing test output to
the original, and then refactoring as needed.
 
Louis
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Dec 18 11:51PM +0100

> codes to C++. The source code is proprietary (sorry). All tables are
> stored in single dimensional arrays (common for old code) so a 2D
> array is not necessary.
 
Oh sorry, I read "tables" as "two dimensional collections of numbers".
 
The "one" class comment was for representing the input in that situation.
 
 
> single, double and triple independent variables.
 
> Alf...how would I design a single class to handle 1, 2, and 3
> independent variables?
 
Now I gather we're talking processing, not representing the input.
 
"Handle" is a verb, and classes are generally not doers. In general a
class collects related operations on some state. So wherever the current
code has umpteen functions that all operate on some particular state
passed as a first or last argument, that is a candidate for a class with
that state as state, and those functions as member functions.
 
A class can simplify things by restricting access. In particular, if
there is a general assumption about the state that the current code
needs to check in many places because the state could have been modified
in a bad way, then a class lets you restrict modification to only good
ways. If the common assumption (called a class invariant) is established
by every constructor, and is maintained by every public operation, then
it's guaranteed and does not need to be checked.
 
A class can also simplify things by just reducing clutter.
 
For example, a point p is less clutter than three individual variables
x, y and z, and it can support clean notation for e.g. calculating
distances, moving a point a given distance, and so on.
 
 
> number of independent variables? Would I pass the table number (used
> to identify the tables) so the class can determine how many
> independent variables are required?
 
I think much more information is needed for me and others to get a
sufficiently clear picture of things to make concrete recommendations.
 
But on the level of general advice, what I remember from my consulting
days about what was most important and difficult to make others aware
of, you need to think seriously and up front about ERROR HANDLING.
 
In modern C++ this is done in two main ways:
 
• Logic errors such as precondition breaches (breach of contract) are
generally detected by assertions, using e.g. `assert` and
`static_assert`. Essentially, where this is done one prefers a crash to
a possibly more orderly processing, because the process state might be
completely fouled up.
 
• Failures, such as failure to obtain a resource, is reported to calling
code via exceptions (the `throw` statement), and cleanup where an
exception passes through some code is done automatically by object
destructors. The C++ cleanup strategy is called RAII. Do read up on it.
 
Due to the way failures are handled, with exceptions, dynamic memory
management is generally best delegated to standard containers such as
`std::vector`, and/or to smart pointers such as `std::unique_ptr` and
`std::shared_ptr`. Then the container or smart pointer owns the memory,
and is responsible for deallocation, reallocation etc. Your code should
have no raw pointers that /own/ memory.
 
 
Cheers!,
 
- Alf
ruben safir <ruben@mrbrklyn.com>: Dec 18 04:48AM -0500

Why can't the threads library handle object methods that are not static
to the class
 
 
such as std::thread paint(read_chunk);
paint.detach();
 
 
where read_chunk is an method of an object of class Images.
 
| gcc -M *.cpp >make.deps
|| g++ -Wall -ggdb -pg -pthread -o png_proj.o -c png_proj.cpp
|| png_proj.cpp: In member function 'void png_proj::Image::read_chunk()':
png_proj.cpp|160 col 32| error: invalid use of non-static member function
'void png_proj::Image::read_chunk()'
|| std::thread paint(read_chunk);
|| ^
png_proj.cpp|109 col 7| note: declared here
|| void Image::read_chunk ( )
"Öö Tiib" <ootiib@hot.ee>: Dec 18 03:09AM -0800

On Sunday, 18 December 2016 11:49:07 UTC+2, ruben safir wrote:
 
> such as std::thread paint(read_chunk);
> paint.detach();
 
> where read_chunk is an method of an object of class Images.
 
Again some voodoo trying-out nonsense that we can't even
copy-paste and run? :-/ The 'std::thread' *can* use non-static
methods. However the caller has to supply arguments (starting
from 'this') to it.
 
#include <thread>
#include <iostream>
 
struct Reader
{
void read_chunk()
{
std::cout << "quod erat demonstrandum" << std::endl;
}
};
 
int main()
{
std::thread paint(&Reader::read_chunk, Reader());
paint.join();
}
 
See? It is easy peasy.
ruben safir <ruben@mrbrklyn.com>: Dec 18 09:36AM -0500

On 12/18/2016 06:09 AM, Öö Tiib wrote:
> paint.join();
> }
 
> See? It is easy peasy.
 
if you call it like that it loses its context of the object that
instantated it which, especially in this case, it needs in order to do
its job.
"Öö Tiib" <ootiib@hot.ee>: Dec 18 07:54AM -0800

On Sunday, 18 December 2016 16:36:32 UTC+2, ruben safir wrote:
 
> if you call it like that it loses its context of the object that
> instantated it which, especially in this case, it needs in order to do
> its job.
 
Reading comprehension problem detected. Nah, just drop programming.
There are easier jobs. Programming is not for you, sorry.
ruben safir <ruben@mrbrklyn.com>: Dec 18 11:08AM -0500

On 12/18/2016 10:54 AM, Öö Tiib wrote:
>> its job.
> Reading comprehension problem detected. Nah, just drop programming.
> There are easier jobs. Programming is not for you, sorry.
 
 
there is a big difference between
 
CLASS::Method
 
and
 
object->method
which can be
this->method
"Öö Tiib" <ootiib@hot.ee>: Dec 18 09:01AM -0800

On Sunday, 18 December 2016 18:08:09 UTC+2, ruben safir wrote:
 
> object->method
> which can be
> this->method
 
Large difference. That '::NAMESPACE::CLASS::method' is member funtion's
fully qualified name and so can be used as expression of that type.
That 'pointer->method' however is a sub-fragment of some expression and
means nothing on its own.
Note that you still fail to post coherent questions what about it
does confuse you.
Vir Campestris <vir.campestris@invalid.invalid>: Dec 18 09:40PM

On 18/12/2016 14:36, ruben safir wrote:
 
> if you call it like that it loses its context of the object that
> instantated it which, especially in this case, it needs in order to do
> its job.
 
You're missing the second parameter to the function. Perhaps if he'd written
 
Reader foo;
std::thread paint(&reader::read_chunk, &foo);
 
it would have made more sense to you. You can pass args to the function,
which may include a pointer to an object of the type. I prefer to pass a
pointer to a static member function for the first parameter which takes
a pointer to an object of the class and invokes a corresponding
non-static member.
 
Andy
Paul <pepstein5@gmail.com>: Dec 18 03:38AM -0800

The code below outputs 5 -3 using gcc C++ 11 (exact details of compiler
omitted).
When I write int min = -3; I would expect the compiler to interpret this
as meaning (int std::min = 3). Since that doesn't make any sense, I would
expect a compilation error.
Is it a rule of C++ that variable definitions are allowed to clash with function names? Or is the below code not robust to all compilers?
 
Thank you,
Paul
 
 
#include <iostream>
#include <algorithm>
using namespace std;
 
int main()
{
cout << min(5,7) << " ";
int min = -3;
cout << min;
return 0;
}
"Öö Tiib" <ootiib@hot.ee>: Dec 18 06:11AM -0800

On Sunday, 18 December 2016 13:38:41 UTC+2, Paul wrote:
> When I write int min = -3; I would expect the compiler to interpret this
> as meaning (int std::min = 3). Since that doesn't make any sense, I would
> expect a compilation error.
 
C++ name lookup is so complex that major compiler vendors struggled long
time to implement it. Such basics like you ask about were OK but I knew
at least one name lookup defect in each until 2008 or so.
 
> Is it a rule of C++ that variable definitions are allowed to clash
> with function names? Or is the below code not robust to all compilers?
 
The names 'min' are from different scope so there are no clash. Instead
name from local scope hides the less local name. Let me vandalize your
code to explain:
 
#include <iostream>
#include <algorithm>
using namespace std; // <- you dig your own hole here

int main()
{
cout << min(5,7) << " ";
int min /* from here std::min is hidden */ = -3;
// so we can't use it unqualified anymore:
// cout << min(42,7) << " ";
cout << std::min(42,7) << " "; // <- we have to qualify it

cout << min << std::endl;
return 0;
}
 
However ... why to name several things with same name? Did you
run out of names?
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: