I would agree with some of what you say Steve, but I've used C++ for over 25 years and I still don't like it much :-)
Other languages that I have used intensely like Smalltalk and Java eventually fade into the background after you master them. The people that I know that like C++ the most seem to appreciate its endless complexity. That said, a subset of C++ with some tiny assembler routines is for us the best choice for most of what we write on z/OS. Kirk Wolf Dovetailed Technologies http://dovetail.com On Tue, May 30, 2017 at 7:13 PM, Steve Smith <[email protected]> wrote: > C++ is my favorite language (I was historically a PL/I fan), but it's a > deep pool to get into. Decent object-oriented programming requires > learning a whole bunch of new ways to do things, and think about things. > There are many layers now of functionality, and there's no serious "Learn > C++ In Seven Days" book any more. The language has grown and expanded > quite a bit past where my knowledge and experience ends. > > But I definitely agree that's it's useful as "enhanced C". But as you > learn more, you can implement more and better patterns... try not to rush > it too much, and free advice: write, don't read (code). There may be a > 1000 ways to do things wrong in assembler, but there's billions in C++. So > be careful about the examples you emulate. The founder of C++ said > something like "You can shoot yourself in the foot with any language, but > with C++, it'll blow your leg clean off." > > 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. > > 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 <[email protected]> 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 <[email protected]> > > 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 [email protected] with the message: INFO > IBM-MAIN > > >> > > > > > > ---------------------------------------------------------------------- > > > For IBM-MAIN subscribe / signoff / archive access instructions, > > > send email to [email protected] with the message: INFO IBM-MAIN > > > > > > > ---------------------------------------------------------------------- > > For IBM-MAIN subscribe / signoff / archive access instructions, > > send email to [email protected] with the message: INFO IBM-MAIN > > > > > > -- > sas > > ---------------------------------------------------------------------- > For IBM-MAIN subscribe / signoff / archive access instructions, > send email to [email protected] with the message: INFO IBM-MAIN > ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO IBM-MAIN
