Thursday, June 15, 2017

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

Vir Campestris <vir.campestris@invalid.invalid>: Jun 15 09:39PM +0100

On 12/06/2017 22:46, Alf P. Steinbach wrote:
> But re the technical, you can view `auto` as `decltype` + `std::decay`.
 
It was the technical stuff I was looking for.
 
It bit me because I assumed that because the function returned a
reference, auto would be a reference. I'll admit I was being lazy - I've
been writing C the last few years, and the coding standards where I used
to work said "Only use auto when there is no choice".
 
Thank you.
Andy
"Öö Tiib" <ootiib@hot.ee>: Jun 15 07:43AM -0700

On Wednesday, 14 June 2017 14:53:48 UTC+3, JiiPee wrote:
> };
> so it is fixed part of it. Its the points the player gets in one/current
> game. Its there (currently) only for the purpose of the current game.
 
Yes that is what I wrote that may be is not made in convenient way
for features that I can imagine. Player can be in lot of games during
his career. Player may be interested how well he did in games of the
past. But if the points are in player then those will be overwritten by
next game.
 
 
> > that is in "0..many to one" relation with "game" and "0..many to one"
> > relation with player. Think about it bit deeper. Getting those entities
> > and relations right is quite important for making software successfully.
 
Note that here you ignored most important part of what I wrote.
 
> But a good topic to discuss, after I think about it.
> Well it works pretty well like it is, but always good to make things
> more logical.
 
It is not bad logic. It is wrong abstraction layer. We do not expect
a "game" to "hack bits of player" but to "provide context for playing".
Interacting with game technically can result that some subset of bits
of player change but it is not responsibility of game to deal with those
bits.
woodbrian77@gmail.com: Jun 14 09:25PM -0700


> With "I've been working on the railroad" playing in the background,
> I ask for some ideas on how to improve my repo. Thank you in
> advance.
 
I have a line like this:
 
for(int32_t n=marshalling_integer{buf}.operator()();n>0;--n)T{buf}; // taken from a class template
 
that uses this class:
 
https://github.com/Ebenezer-group/onwards/blob/master/marshalling_integer.hh
 
 
Do you think I should add an operator> and a decrement operator to
marshalling_integer so I can rewrite the line above like this:
 
for(marshalling_integer n{buf};n>0;--n)T{buf};
 
?
 
A second question involves some middle code from this file:
https://github.com/Ebenezer-group/onwards/blob/master/tiers/middle_front.mdl
 
-out -max_length=cmw::udp_packet_max -no_inline (bool,::std::string_view)
-out -max_length=cmw::udp_packet_max -no_inline (bool,cmw::string_join)
 
string_join is a type that has two string_view members:
 
#pragma once
#include"marshalling_integer.hh"
#include"SendBuffer.hh"
#include<string_view>
 
namespace cmw{
class string_join{
::std::string_view s1;
::std::string_view s2;
 
public:
string_join (::std::string_view str1
,::std::string_view str2):s1(str1),s2(str2){}
 
void Marshal (SendBuffer& buf,bool=false)const{
marshalling_integer(s1.length()+s2.length()).Marshal(buf);
buf.Receive(s1.data(),s1.length());//Use low-level Receive
buf.Receive(s2.data(),s2.length());
}
};
}
 
The marshal function doesn't marshal each string_view individually,
but adds up the length of the first string and the second and marshals
that.
 
Here's a version of that class that uses std::initializer_list:
 
#pragma once
#include"marshalling_integer.hh"
#include"SendBuffer.hh"
#include<string_view>
#include<initializer_list>
 
namespace cmw{
class string_join{
::std::initializer_list<::std::string_view> in;
 
public:
string_join (::std::initializer_list<::std::string_view> lst):in(lst){}
 
void Marshal (SendBuffer& buf,bool=false)const{
int totLen=0;
for(auto sv:in)totLen+=sv.length();
marshalling_integer(totLen).Marshal(buf);
for(auto sv:in)buf.Receive(sv.data(),sv.length());//Use low-level Receive
}
};
}
 
The version that uses std::initializer_list caused my text segment to increase
by 60 bytes. I guess it may have to do with the differences in the Marshal
implementations. Can you suggest a change to the implementation that
might help? If I get this version working better, I'll be able to remove one
of the above lines in my middle file.
 
 
Brian
Ebenezer Enterprises
http://webEbenezer.net
woodbrian77@gmail.com: Jun 14 10:05PM -0700

> implementations. Can you suggest a change to the implementation that
> might help? If I get this version working better, I'll be able to remove one
> of the above lines in my middle file.
 
I took it another step and tried using the new version of string_join
for the cases where I just have one string_view. That resulted in the
text segment decreasing by 136 bytes. (Well, surprisingly I also had to
#if 0 out the generated function that took a string_view.) I'll do some
more testing, but will probably go with this version of string_join and be
able to get rid of one of the lines of middle code. I guess the name
string_join isn't the greatest for the cases I just have one string_view.
 
 
Brian
Ebenezer Enterprises
http://webEbenezer.net
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jun 15 07:31AM +0200

> marshalling_integer so I can rewrite the line above like this:
 
> for(marshalling_integer n{buf};n>0;--n)T{buf};
 
> ?
 
I would just write
 
for( int n = marshalling_integer{buf}(); n > 0; --n )
{
(void*)T{ buf };
}
 
It's a different emphasis.
 
Mostly personal choice but you solicited opinions. :)
 
 
> implementations. Can you suggest a change to the implementation that
> might help? If I get this version working better, I'll be able to remove one
> of the above lines in my middle file.
 
In the words of Andrei & Herb, though they were ¹talking about something
else:
 
"Don't fret the small stuff."
 
 
Cheers & hth.,
 
- Alf
 
Links:
¹
https://www.safaribooksonline.com/library/view/c-coding-standards/0321113586/ch01.html
David Brown <david.brown@hesbynett.no>: Jun 15 09:41AM +0200


>>> With "I've been working on the railroad" playing in the background,
>>> I ask for some ideas on how to improve my repo. Thank you in
>>> advance.
 
I have no interest in your marshalling library - it is simply not
something I would have use for. And I have not attempted to read your
code or understand it. However, I can still give you ideas for improvement.
 
If you were to present this code for review where I work, you'd be send
straight back to your desk in seconds - the rest of review meeting would
be cancelled and no one would read your code.
 
Take a look at your keyboard. What is the biggest key there? The space
key. What is the second biggest key? The enter or return key. These
are the two most important keys on the keyboard. Until you have learned
to use them, your code is worthless because it is illegible.
 
And drop the "::" prefix on std.
 
 
<https://google.github.io/styleguide/cppguide.html#Horizontal_Whitespace>
 
<https://en.wikipedia.org/wiki/Indent_style>
 
 
If you want other people to use your code, it makes a lot of sense to
use a formatting style that is popular with many people.
Christian Gollwitzer <auriocus@gmx.de>: Jun 15 09:45AM +0200

Am 15.06.17 um 09:41 schrieb David Brown:
> to use them, your code is worthless because it is illegible.
 
> If you want other people to use your code, it makes a lot of sense to
> use a formatting style that is popular with many people.
 
To be a bit less polemic, indentation is something which can be improved
automatically. There is the classic GNU "indent" program which supports
a large number of options (however it works much better for pure C than
C++). Some editors (emacs, vim, sublime) and big IDEs like Eclipse or
Visual Studio also feature an automatic indenter. So this shouldn't be a
big obstacle and an easy to fix thing.
 
Christian
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jun 15 10:20AM +0200

On 15-Jun-17 9:45 AM, Christian Gollwitzer wrote:
> C++). Some editors (emacs, vim, sublime) and big IDEs like Eclipse or
> Visual Studio also feature an automatic indenter. So this shouldn't be a
> big obstacle and an easy to fix thing.
 
There also AStyle (Artistic Style), which is a freestanding program
that's also, I think, available as a Notepad++ extension.
 
That's my usual recommendation when this issue arises, but only because
it's the only one I know apart from VS. :)
 
VS, Visual Studio, has an explicitly invokable formatter that for some
inexplicable reason is not in the menus by default.
 
 
Cheers!,
 
- Alf
David Brown <david.brown@hesbynett.no>: Jun 15 10:34AM +0200

On 15/06/17 09:45, Christian Gollwitzer wrote:
> C++). Some editors (emacs, vim, sublime) and big IDEs like Eclipse or
> Visual Studio also feature an automatic indenter. So this shouldn't be a
> big obstacle and an easy to fix thing.
 
Certainly such tools are useful for converting existing code. And a
good editor is very helpful when writing code - things like automatic
indentation are particularly handy. But a programmer really should
learn to write code in a legible manner in the first place.
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: