On 31/05/2017 8:13 AM, Steve Smith wrote:
Eventually, the big problem with OOP is designing an intelligent class
hierarchy to solve a particular problem. And that is where so many go
wrong. The real world of applications rarely comes up with something as
obvious as Thing: Animal/Vegetable/Mineral. Animal: Cat/Dog.
I would argue that deep class hierarchies are a bad code smell. I would
advise any wannabe C++ developer to get a copy of "Design Patterns" by
the gang of four.
It was written in 1994 but still stands strong today. It emphasizes
composition over inheritance and it's legacy can be seen today in
runtimes like the Java JRE.
As you say, language semantics are secondary to good design and that
book is a classic that changed the way the industry thought about OOP
based up experience.
And then you can get into templates, and whatever new & crazy stuff they've
thought of recently. It's a whole new world, lots of fun, but it gets a
long long way away from what you're probably used to in assembly (or C for
that matter). But again, a subset of C++ is useful and valuable; you don't
have to (and it's probably insane to) use every feature.
sas
On Tue, May 30, 2017 at 12:18 PM, Kirk Wolf <k...@dovetail.com> wrote:
We use a small subset of C++ (better C) on z/OS:
classes (encapsulation) (but very little use of inheritance)
RIAA
exceptions
better type checking
improved syntax (like late declaration of variables)
inlining of functions in class header (and very little use of function
macro)
Kirk Wolf
Dovetailed Technologies
http://dovetail.com
On Tue, May 30, 2017 at 7:22 AM, David Crayford <dcrayf...@gmail.com>
wrote:
This might bewilder you some more because C++ is a tricky language for a
beginner. It''s a simple thin wrapper class around C stdio that provides
RAII and some return value checks that throw exception when errors occur.
If you can work this out you're well on your way to being competent. It's
mainly meant as a demonstrator for constructors/destructors which are
fundamental to C++ programming.
#include <iostream>
#include <string>
#include <stdexcept>
#include <cstdio>
class File
{
public:
// default constructor
File() : m_file( 0 ) {}
// constructor - opens the file
File( const std::string & filename, const std::string & mode )
: m_file( 0 )
{
std::cout << "constructor\n";
open( filename, mode );
}
// move constructor - takes ownership of the underlying file object
File( File && rhs ) : m_file(0)
{
std::cout << "move constructor\n";
m_file = rhs.m_file;
rhs.m_file = 0;
}
// destructor
~File()
{
close();
}
public:
// opens a file
void open( const std::string & filename, const std::string & mode )
{
std::cout << "opening file " << filename << "\n";
m_file = fopen( filename.c_str(), mode.c_str() );
if (!m_file) throw std::runtime_error( "Error opening file: " +
std::string( strerror( errno ) ) );
}
// closes the files
void close()
{
if (m_file)
{
std::cout << "closing file\n";
fclose( m_file );
m_file = 0;
}
}
// reads from the file
int read( void * buffer, size_t size )
{
return fread( buffer, 1, size, m_file );
}
// writes to the file
int write( const void * buffer, size_t size )
{
int bytesWritten = fwrite( buffer, 1, size, m_file );
if (bytesWritten == 0) // I/O error
{
throw std::runtime_error( std::string( "Error writing to
file:
" + std::string( strerror( errno ) ) ) );
}
return bytesWritten;
}
private:
FILE * m_file; // file handle
};
// factory function to demonstrate change of ownership
File openFile( const std::string filename, const std::string & mode )
{
File file( filename, mode );
return file;
}
int main( int argc, char * argv[] )
{
try
{
// open the files
File input = openFile( "DD:INPUT", "rb, type=record, noseek" );
File output( "DD:OUTPUT", "wb, type=record" );
// copy the input file to the output file
size_t bytesRead;
char buffer[32768];
while ( ( bytesRead = input.read( buffer, sizeof buffer ) ) )
{
output.write( buffer, bytesRead );
}
// <<<<< destructors run here when the file objects go out of
scope
}
catch (std::exception & e)
{
std::cout << e.what() << "\n";
}
return 0;
}
On 30/05/2017 4:32 AM, Steve Beaver wrote:
Does anyone have a complete piece of C++ code that runs under MVS or
Linux that I can study? 99% of the stuff I write is HLASM and to a
point I
find C++ bewildering.
TIA
Steve
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN