There was a programming-"contest" on comp.lang.c and I wanted to show
the simpler code in C, here it is:
#include <iostream>
#include <sstream>
#include <iomanip>
#include <optional>
#include <algorithm>
using namespace std;
static optional<size_t> parse( const char *str );
int main( int argc, char **argv )
{
-a-a-a-aif( argc < 3 )
-a-a-a-a-a-a-a return EXIT_FAILURE;
-a-a-a-aoptional<size_t>
-a-a-a-a-a-a-a pRows = parse( argv[1] ),
-a-a-a-a-a-a-a pCols = parse( argv[2] );
-a-a-a-aif( !pRows || !pCols )
-a-a-a-a-a-a-a return EXIT_FAILURE;
-a-a-a-asize_t rows = *pRows, cols = *pCols;
-a-a-a-aoptional<size_t> pClip( rows * cols );
-a-a-a-aif( argc >= 4 && !(pClip = parse( argv[3] )) )
-a-a-a-a-a-a-a return EXIT_FAILURE;
-a-a-a-asize_t clip = min( *pClip, rows * cols );
-a-a-a-astreamsize width = (ostringstream() << clip).str().length();
-a-a-a-afor( size_t row = 1; row <= min( rows, clip ); ++row )
-a-a-a-a{
-a-a-a-a-a-a-a bool head = true;
-a-a-a-a-a-a-a for( size_t value = row; value <= clip; value += rows, head =
false )
-a-a-a-a-a-a-a-a-a-a-a cout << " "sv.substr( head, !head ) << right << setw( width ) << value;
-a-a-a-a-a-a-a cout << endl;
-a-a-a-a}
}
static optional<size_t> parse( const char *str )
{
-a-a-a-aistringstream iss( str );
-a-a-a-asize_t ret;
-a-a-a-aiss >> ret;
-a-a-a-aif( !iss || !iss.eof() )
-a-a-a-a-a-a-a return nullopt;
-a-a-a-areturn ret;
}
C++ really rocks since you've to deal with much less details than in C.
Concerning your subject; it wouldn't appear to me to use the term
"beauty" in context of C++. C++ inherited so much ugly syntax and
concepts (from "C") and it added yet more syntactic infelicities.
(And I'm saying that as someone who liked to program in C++, also professionally, for many many years.)
Am 12.03.2026 um 09:32 schrieb Janis Papanagnou:
Concerning your subject; it wouldn't appear to me to use the term
"beauty" in context of C++. C++ inherited so much ugly syntax and
concepts (from "C") and it added yet more syntactic infelicities.
(And I'm saying that as someone who liked to program in C++, also
professionally, for many many years.)
My perception of beauty is just as subjective as your perception of the
ugly aspects of C++. I like the span of lowleven means in C++ that are inherited from C to higher level abstractions C++ has inherited from
other more moderrn language.
And if you don't the subjektive part of beauty or ugly parts of this
language C++ is several times more effective than C, i.e. you need
only a fraction of the code size while mostly maintaining the same performance.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 65 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 08:06:21 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
1 files (1,366K bytes) |
| Messages: | 264,936 |