Saturday, July 8, 2017

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

"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jul 08 05:59AM +0200

On 08-Jul-17 12:00 AM, Ian Collins wrote:
> [snip]
> In general, idiomatic is good, superfluous verbosity is bad!
 
On further reflection I think you're right here.
 
So I went trough all (the very few) classes in /stdlib/ and removed
those pesky redundant `private:` at top of each.
 
This works well with a convention of putting private implementation
stuff first in the class. :)
 
 
 
> int n;
> };
 
> ?
 
No, because a `struct` is by convention used for a plain old POD, with
only one access level applied to the whole thing, namely public access.
 
So, I don't buy this argument, but still you do have a point, I think.
 
 
Cheers!,
 
- Alf
Christian Gollwitzer <auriocus@gmx.de>: Jul 08 06:55AM +0200

Am 07.07.17 um 13:08 schrieb Alf P. Steinbach:
 
> I've just implemented the following declaration for Windows and Linux:
 
> <url:
> https://github.com/alf-p-steinbach/stdlib/blob/master/source/extension/process_command_line.declarations.hpp>
 
In plain English, what on earth does this code do? Why is it needed?
I am reading that it gets you the command line arguments as a
std::vector<string>. In both Linux & OSX the command line arguments come
as the arguments to main, so what are these functions good for?
 
I'd do:
 
std::vector<string> cmdline_args;
int main (int argc, const char *argv[]) {
for (int i = 0; i < argc; i++) {
cmdline_args.push_back(argv[i]);
}
 
// do your stuff here
}
 
 
 
Christian
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jul 08 05:57AM +0100

On 08/07/2017 04:59, Alf P. Steinbach wrote:
 
> On further reflection I think you're right here.
 
> So I went trough all (the very few) classes in /stdlib/ and removed
> those pesky redundant `private:` at top of each.
 
An egregious change to a library with an egregious name.
 
 
> This works well with a convention of putting private implementation
> stuff first in the class. :)
 
Hardly a convention if most people put private stuff AFTER public stuff.
 
/Flibble
Ian Collins <ian-news@hotmail.com>: Jul 08 05:09PM +1200

On 07/ 8/17 04:55 PM, Christian Gollwitzer wrote:
> for (int i = 0; i < argc; i++) {
> cmdline_args.push_back(argv[i]);
> }
 
Why the complexity?
 
std::vector<std::string> args {argv, argv+argc};
 
--
Ian
Gareth Owen <gwowen@gmail.com>: Jul 08 07:09AM +0100


> Data does not form part of the interface because data that forms part
> of the class invariant (that which the interface guarantees) cannot be
> public.
 
Mostly true for complex classes, but don't tell me that a simple POD class
like
 
struct Point {
int x;
int y;
int z;
};
 
is improved by private data and public accessor functions.
That'd be some Steinbach-esque obfuscation.
Christian Gollwitzer <auriocus@gmx.de>: Jul 08 08:46AM +0200

Am 08.07.17 um 07:09 schrieb Ian Collins:
>> }
 
> Why the complexity?
 
> std::vector<std::string> args {argv, argv+argc};
 
Because of my ignorance of this constructor and tricky pointer arithmetics.
 
Thanks - that is even better.
 
 
Christian
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jul 08 10:22AM +0200

On 08-Jul-17 6:55 AM, Christian Gollwitzer wrote:
 
>> <url:
>> https://github.com/alf-p-steinbach/stdlib/blob/master/source/extension/process_command_line.declarations.hpp>
 
> In plain English, what on earth does this code do?
 
It gets you UTF-8 encoded command line arguments, in a portable way.
 
The encoding is important for characters outside ASCII's A through Z.
 
 
Cheers & hth.,
 
- Alf
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jul 08 10:26AM +0200

On 08-Jul-17 8:09 AM, Gareth Owen wrote:
> };
 
> is improved by private data and public accessor functions.
> That'd be some Steinbach-esque obfuscation.
 
If you point out where you find something of mine obfuscated, I'll try
to clear it up for you.
 
In spite of that silly name calling.
 
 
Cheers!,
 
- Alf
Gareth Owen <gwowen@gmail.com>: Jul 08 10:50AM +0100


> If you point out where you find something of mine obfuscated, I'll try
> to clear it up for you.
 
auto main -> int
 
when *literally* *everyone* *else* writes
 
int main()
 
Gratutious, unhelpful, unidiomatic = obfuscated.
 
> In spite of that silly name calling.
 
Your code is obfuscated. Its not name call out your obfuscating
affectations as gratuitous obfuscation (and, make no mistake,
 
"auto main -> int"
 
is an affectation - it has no benefit whatsover for anyone besides
making you feel smarter, and everyone else roll their eyes at the
idiocy).
Ian Collins <ian-news@hotmail.com>: Jul 08 10:07PM +1200

On 07/ 8/17 08:22 PM, Alf P. Steinbach wrote:
 
>> In plain English, what on earth does this code do?
 
> It gets you UTF-8 encoded command line arguments, in a portable way.
 
> The encoding is important for characters outside ASCII's A through Z.
 
On my desktop (Solaris) it "just works"..
 
#include <vector>
#include <string>
#include <iostream>
 
int main( int argc, char** argv )
{
std::vector<std::string> args {argv, argv+argc};
 
for( auto arg: args )
{
std::cout << arg << std::endl;
}
 
return 0;
}
 
./a.out €
./a.out

 
--
Ian
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jul 08 02:15PM +0100

On 08/07/2017 07:09, Gareth Owen wrote:
> };
 
> is improved by private data and public accessor functions.
> That'd be some Steinbach-esque obfuscation.
 
That data doesn't contribute to an invariant so it's fine.
 
/Flibble
Manfred <noname@invalid.add>: Jul 08 03:26PM +0200

On 7/8/2017 12:07 PM, Ian Collins wrote:
 
> ./a.out €
> ./a.out
> €
 
That's because it is a good desktop.
(On Fedora Linux it "just works" too)
On Windows (Win10):
 
C:>arg è
arg
Φ
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jul 08 04:16PM +0200

On 08-Jul-17 11:50 AM, Gareth Owen wrote:
 
> is an affectation - it has no benefit whatsover for anyone besides
> making you feel smarter, and everyone else roll their eyes at the
> idiocy).
 
Well, I can't (or will not) help you with that social issue, sorry.
 
If it had been something technical, something unclear to you, as you
indicated, then I'd gladly help out in spite of the foul behavior
exhibited above.
 
 
Cheers!,
 
- Alf
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jul 08 04:31PM +0100

On 08/07/2017 15:16, Alf P. Steinbach wrote:
 
> If it had been something technical, something unclear to you, as you
> indicated, then I'd gladly help out in spite of the foul behavior
> exhibited above.
 
You are honestly saying that
 
auto main()
 
isn't a mental OCD tick?
 
Nobody on this entire planet EXCEPT YOU writes:
 
auto main()
 
EVERYBODY ELSE on this entire planet writes:
 
int main()
 
/Flibble
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jul 08 04:37PM +0100

On 08/07/2017 16:31, Mr Flibble wrote:
 
> auto main()
 
> EVERYBODY ELSE on this entire planet writes:
 
> int main()
 
.. so it is hardly surprising that you use 'auto' in other inappropriate
places too.
 
/Flibble
Gareth Owen <gwowen@gmail.com>: Jul 08 05:53PM +0100


> Well, I can't (or will not) help you with that social issue, sorry.
 
Unreadable, correct code *is* a social issue.
Ian Collins <ian-news@hotmail.com>: Jul 09 08:59AM +1200

On 07/ 9/17 02:16 AM, Alf P. Steinbach wrote:
>> making you feel smarter, and everyone else roll their eyes at the
>> idiocy).
 
> Well, I can't (or will not) help you with that social issue, sorry.
 
You may not appreciate his tone, but he is spot on with this one. You
may well be the only C++ programmer on the planet who writes
 
auto main() -> int
 
int main() is so idiomatic anything else is obfuscation. Not only is it
obfuscation, it's more typing!
 
--
Ian
"Öö Tiib" <ootiib@hot.ee>: Jul 08 02:38PM -0700

On Saturday, 8 July 2017 23:59:57 UTC+3, Ian Collins wrote:
 
> auto main() -> int
 
> int main() is so idiomatic anything else is obfuscation. Not only is it
> obfuscation, it's more typing!
 
Yes, everybody agree with "int main()" being idiomatic in C++ and that Alf
adds some redundant characters there but it is still valid C++ what he
writes. Sort of like that "::std" of woodbrian is valid C++.

Note that the new "wannabe better C++" languages tend to have return
type of function indicated at end, so it is sort of "trendy" what Alf does.
 
Swift:
func greet(person: String) -> String {
let greeting = "Hello, " + person + "!"
return greeting
}
 
Go:
func add(x int, y int) int {
return x + y
}
 
Rust:
fn add_one(x: i32) -> i32 {
x + 1
}
Christian Gollwitzer <auriocus@gmx.de>: Jul 08 11:39PM +0200

Am 08.07.17 um 15:26 schrieb Manfred:
 
> C:>arg è
> arg
> Φ
 
That's exactly the point. It must be fixed for Windows, maybe, because
that is a stupid OS. For almost anything else it "just works" - why does
Alf muck around with /proc/self and tokenize the stream etc.? That makes
absolutely no sense.
 
Christian
Ian Collins <ian-news@hotmail.com>: Jul 09 11:20AM +1200

On 07/ 9/17 09:38 AM, Öö Tiib wrote:
> fn add_one(x: i32) -> i32 {
> x + 1
> }
 
Maybe, but in C++ main is a bit of an oddball in requiring an explicit
return type.
 
I consider the use of auto fine when a suffix return isn't required (C++
is more elegant than these other languages in that regard) but outside
of template code, it is more trouble than it is worth.
 
 
--
Ian
jacobnavia <jacob@jacob.remcomp.fr>: Jul 09 12:19AM +0200

This program reads words from a file and shows the words and their
positions.
 
1 #include <fstream>
2 #include <iostream>
3 #include <string>
4 #include <map>
5 #include <vector>
6
7 int main(int argc, char **argv)
8 {
9 if (argc == 2) {
10 std::map<std::string, std::vector<size_t>> positions;
11
12 std::ifstream fin(argv[1]);
13 std::string word;
14 while (fin >> word)
15 positions[word].push_back((size_t)fin.tellg() -
word.length());
16 fin.close();
17
18 for (auto &pair : positions) {
19 std::cout << pair.first;
20 for (auto &pos : pair.second)
21 std::cout << " " << pos;
22 std::cout << "\n";
23 }
24 }
25 }
 
The problem here is that the scanner considers that
"word" and "word,word" are two different words.
 
Apparently just searches the first non blank character.
 
How can we change the >> operator to call a user defined function to
scan the characters?
 
My C++ knowledge doesn't go that far.
Ian Collins <ian-news@hotmail.com>: Jul 09 11:16AM +1200

On 07/ 9/17 10:19 AM, jacobnavia wrote:
 
> Apparently just searches the first non blank character.
 
> How can we change the >> operator to call a user defined function to
> scan the characters?
 
I would treat this as an input filtering problem and provide a custom
stream buf to convert punctuation to whitespace before the stream
operator sees it.
 
--
Ian
Bonita Montero <Bonita.Montero@gmail.com>: Jul 08 10:38PM +0200

What I't to find to be cooler would be a string-class with a template
parameter that specifies an amount of static storage in the class up
to which the string-content will be assigned to. And If the string is
larger, it would be allocated on the heap. Of course such a class would
be useful almost only for stack-allocated string because it would blow
up objects that contain such strings on heap.
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: