Saturday, October 4, 2014

Digest for comp.lang.c++@googlegroups.com - 17 updates in 4 topics

comp.lang.c++@googlegroups.com Google Groups
Unsure why you received this message? You previously subscribed to digests from this group, but we haven't been sending them for a while. We fixed that, but if you don't want to get these messages, send an email to comp.lang.c+++unsubscribe@googlegroups.com.
"Charles J. Daniels" <chajadan@gmail.com>: Oct 04 09:58AM -0700

So I've been playing with my coding style, aiming to make things more meaningful, a la "self documenting code". I'm enjoying it.
 
Over and over I find myself adding or subtracting string positions (from string.find() or whatnot), and often either adding or subtracting a 1. Every time I have to figure it out in my head, and then any time I read it I would have to do it again to verify, or figure it out later.
 
I have a handful of "meaningfulness" constructs around now. I was documenting one after being up all time, and tickled myself, twice!
 
 
 
/**
* A meaningful way to indicate an active position beyond a
* starting position, specifically due to stepping just past
* the given string.
* @code
* wstring joke(L"knock knock abracadabra");
* wstring whosThere(L"abra");
* auto punchlinePosition = joke.find(whosThere) + After(whosThere);
* wstring whosThereWho = joke.substr(punchlinePosition);
* @endcode
* @param string The string being stepped over, or at minimum
a string of equivalent length
* @return The number of positions moved to step over the string
*/
template <class charT>
typename basic_string<charT>::size_type After(basic_string<charT> string) {
return string.length();
}
 
 
/**
* A meaningful way to actively consider a position beyond a starting
* position, specifically the end character of some string under
* consideration.
* @code
* wstring dangling(L"sentences shouldn't end with the word of");
* wstring preposition(L"of");
* bool badGrammer =
* dangling.find(preposition) + Through(preposition)
* == dangling.lastPosition();
* @endcode
* @param string The string to look at the end of, or at minimum
* a string of equivalent length
* @return The number of positions moved to step to the end
* of the string
*/
template <class charT>
typename basic_string<charT>::size_type Through(basic_string<charT> string) {
return string.length() - 1;
}
 
:-p lol
 
I'll be curious to see if this coding style sticks, or goes fad for me. But the idea of having position manipulations readily apparent seems like a keeper for me.
 
(If you try to run those doc examples, lastPosition() is just length() - 1)
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Oct 04 11:14AM -0700

On Saturday, October 4, 2014 12:58:58 PM UTC-4, Charles J. Daniels wrote:
> [snip]
 
Jesus Christ is the way, the truth, and the life. He commands all men
everywhere to repent. No one will enter into Heaven unless they come
to Him, humble themselves, ask forgiveness, and be saved.
 
There is a way which seems right unto a man, Charles, but the ends
thereof are the ways of death.
 
Choose life. Learn of Jesus Christ and let the truth set you free.
 
Best regards,
Rick C. Hodgin
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Oct 04 08:11PM +0100

On 04/10/2014 17:58, Charles J. Daniels wrote:
 
> :-p lol
 
> I'll be curious to see if this coding style sticks, or goes fad for me. But the idea of having position manipulations readily apparent seems like a keeper for me.
 
> (If you try to run those doc examples, lastPosition() is just length() - 1)
 
Such functions which simply duplicate other functionality just add noise
in my opinion .. str.length() means more to me than After(str) given
that I understand the *Standard* Library and not your code.
 
/Flibble
jacob navia <jacob@spamsink.net>: Oct 04 10:05PM +0200

Le 04/10/2014 20:14, Rick C. Hodgin a écrit :
 
> Choose life. Learn of Jesus Christ and let the truth set you free.
 
> Best regards,
> Rick C. Hodgin
 
This is a wondeful example of a religious person.
 
When asked about a good naming convention, he will answer his religious
babble without trying to address the question at all.
 
Question:
What time is it please?
 
Answer:
> Jesus Christ is the way, the truth, and the life. He commands all men
> everywhere to repent. No one will enter into Heaven unless they come
> to Him, humble themselves, ask forgiveness, and be saved.
 
Q: What is the standard C++ function to calculate the cubic root?
 
A: Jesus Christ is the way, the truth, and the life. He commands all
men everywhere to repent. No one will enter into Heaven unless they
come to Him, humble themselves, ask forgiveness, and be saved.
 
Wat a bunch of morons!
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Oct 04 01:35PM -0700

You have value, very special value. You are
important and your life means something.
You are a beautiful creation of God, endowed
with unique and special traits.
 
Jesus teaches us who we are. He shows us
the unique and special creations we are.
All of us. All who will hear.
 
The love in store for those who overcome is
worth all the ridicule, all the scorn. It is toward
Him, and His goals for all of us (loving one
another, helping one another, lifting and
encouraging one another) that we strive. He
guides the way, and He is the epitome of all such
efforts and endeavors.
 
Jesus teaches us all things. The closer you
pursue that knowledge, the more He gives
you. It never ceases to increase with pursuit.
 
I love people too much to not share this most
wonderful revelation, and free gift of unending,
eternal life, with Him, because of Him.
 
Do you want to enter into Heaven? Do you
care about your eternal soul? All I ask is that
you learn of Jesus Christ. I testify that He is
real, alive, and is more amazing than anything
you've ever encountered, or ever will ever
encounter.
 
Eternal life is a free gift from God, one made
possible by Jesus alone because of His atoning
death on the cross.
 
Best regards,
Rick C. Hodgin
"Öö Tiib" <ootiib@hot.ee>: Oct 04 02:01PM -0700

On Saturday, 4 October 2014 19:58:58 UTC+3, Charles J. Daniels wrote:
> So I've been playing with my coding style, aiming to make things
> more meaningful, a la "self documenting code". I'm enjoying it.
 
It is most important ... that you yourself enjoy it.
 
> * auto punchlinePosition = joke.find(whosThere) + After(whosThere);
> * wstring whosThereWho = joke.substr(punchlinePosition);
> * @endcode
 
If to try last two lines of your example with various different values
of 'joke' and 'whosThere' then we see that punchlinePosition has
most of the time value 'whosthere.length()-1'. That is because
'some_string.find(other_string)' returns most of the time
'string::npos' (that is required to be 'SIZE_MAX').
 
> typename basic_string<charT>::size_type After(basic_string<charT> string) {
> return string.length();
> }
 
Since example of its usage was broken I suspect that it is not good
idea to use it. Same with your other function whose example does not
even compile for that 'lastPosition'.
 
> I'll be curious to see if this coding style sticks, or goes fad for
> me. But the idea of having position manipulations readily apparent
> seems like a keeper for me.
 
In practice we can't throw aside error handling for sake of
readability. So write realistic examples of usage first and measure
the "meaningfulness" from those.
 
Aliasing lengthy constructs is often good idea but purpose of
aliasing 'str.size()' with 'After(str)' and 'str.size()-1' with
'Through(str)' is confusing for me.
 
With years I have also found that code that contains
some pointer, iterator or position math may be complex
to read. I add either comment or move the whole arithmetic
to separate little function.
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Oct 04 10:47PM +0100

On 04/10/2014 21:35, Rick C. Hodgin wrote:
> important and your life means something.
> You are a beautiful creation of God, endowed
> with unique and special traits.
 
[snip]
 
Evolution is proof that your god doesn't exist and that you are a
deluded idiot.
 
/Flibble
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Oct 04 03:20PM -0700

On Saturday, October 4, 2014 5:47:23 PM UTC-4, Mr Flibble wrote:
> [snip]
 
Mr Flibble, you're running full-speed into a brick wall. I would
save you from that end by warning you of the existence of the wall.
 
What is it that you're offended by? Is it that Jesus teaches, and
even commands us, to love one another? Is that He teaches us to
help one another? That if we have two of something, we should give
one of them to the one who has none? That we should seek peace and
not fighting? That we should look out for our neighbor as ourself?
 
Which part of Jesus' teachings are so offensive and obtuse that the
person following them would be considered anything other than someone
in pursuit of all of those things that any person seeking a right
relationship with those around them would pursue?
 
It is because we say the name Jesus that you are offended. You know
that He is God Almighty and that He has the power of Life and Death
in His hand. And you are angry because you do not want that life,
and yet you know it is real.
 
He will save you too. All you have to do is believe, and ask.
There are no barriers between you and eternal life except for
those you personally erect yourself. Jesus has done everything
else to make it happen. He's reaching out with both arms to draw
you to His free offer. He is ready, willing, and able to receive
you.
 
I urge you, Mr Flibble ... do not delay. You will find a peace
you never knew was possible. A love within yourself that brings
you to tears. And a desire for those around you to also experience
that which you will then experience for the first time. It is
more profound than any thing which has come to you at any point
prior in your life.
 
The lyrics were penned for a reason:
 
"Amazing Grace, how sweet the sound, that saved a
wretch like me. I once was lost, but now I'm found.
Was blind, but now I see."
 
We are all wretches, Mr Flibble. It is Jesus who restores us,
and makes us whole. Seek to learn of Him. You will be forever
grateful that you did.
 
Best regards,
Rick C. Hodgin
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Oct 04 11:50PM +0100

On 04/10/2014 23:20, Rick C. Hodgin wrote:
 
[snip]
 
> We are all wretches, Mr Flibble. It is Jesus who restores us,
> and makes us whole. Seek to learn of Him. You will be forever
> grateful that you did.
 
Evolution is proof that Jesus doesn't exist and that you are a deluded
idiot.
 
/Flibble
"Charles J. Daniels" <chajadan@gmail.com>: Oct 04 04:07PM -0700

On Saturday, October 4, 2014 12:11:32 PM UTC-7, Mr Flibble wrote:
 
> in my opinion .. str.length() means more to me than After(str) given
 
> that I understand the *Standard* Library and not your code.
 
> /Flibble
 
I definitely understand the perspective. I can't help but notice the foreignness myself, not because the code I'm producing is unreadable, in many ways it's very very readable, but it doesn't have the "how we usually do it " pop. I do think there is something to be said for constructs that specify the why and not the what. I somewhat suspect that I'll throw out a million constructs and then some will stick.
 
Something like this is very straight-forward due to commonness:
 
int max;
If (a > b) {
max = a;
} else {
max = b;
}
 
But when using an if-else to select between two possible values for a variable to take on, I'm liking this lately:
 
int max = Choose(a, b, a > b);
 
I recognize I could use
 
int max = a > b ? a : b
 
but every time I see Choose(), it screams to me "one or the other", and I'm looking to make my code scream more :-p
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Oct 05 12:17AM +0100

On 05/10/2014 00:07, Charles J. Daniels wrote:
 
> I recognize I could use
 
> int max = a > b ? a : b
 
> but every time I see Choose(), it screams to me "one or the other", and I'm looking to make my code scream more :-p
 
No, again you use the Standard Library that everyone understands: std::max.
 
Only create new functions that add to or change semantics of already
existing functions; if the only difference is the NAME of the function
then what you think is a good name others might think is just
non-standard noise.
 
/Flibble
Luca Risolia <luca.risolia@linux-projects.org>: Oct 04 02:05AM +0200

> Actually I need someone programming engineering software,
> who would like to read the tutorial and tell me
> what is missing for his/her software application needs.
 
It would be useful if the library supported all the base units of SI
via literal operators, for example:
 
using namespace measures::si;
auto length = 10_m; // 10 meters (relative measure)
"Öö Tiib" <ootiib@hot.ee>: Oct 04 06:34AM -0700

> (but not theoretical physics) software, not small micro-controllers,
> for which C is generally preferred to C++. And I found
> very useful the "decltype" keyword, that I used a lot.
 
You seemingly say that inside industrial devices or vehicles
(be it bottle washer, crane or ship) there are some sort of
weak 8 bit micro-controllers? No, there are typically piles
of quite powerful processors in all equipment especially where
it has to deal with temperatures, pressures, rotation speeds,
distances, voltages and just name it.
 
Claiming that software for those must be written in C is like
claiming that engineering or scientific analysis software has
to be written in Fortran.

> in electron-volts, or force (not mass) measured in kilograms?
> In addition, having all magnitudes and units
> application-programmer defined keeps small the code base.
 
Boost.Units doesn't remove opportunity to define your
own exotic units. However on common case we measure things
with standard units and so these are not bad to have as part
of library. More defining and declaring work for user means
more tyops and more inconvenience.
 
> "one-dimension absolute measure" and "vect1" means
> "one-dimension relative measure", the latter expression
> is more understandable than the former one.
 
All what I said is that I would avoid enforcing my users to
learn meaning of unknown in most problem domains
abbreviations but your mileage may wary there.
 
> But as my library is still in development,
> I accept suggestions for a renaming.
 
What I suggested is to use "relative measure" or "relative
quantity" typed out literally. Note that "one-dimensional"
feels irrelevant for temperature. In what problem domain we
have three-dimensional temperatures? A single value is
indeed technically an array of values with one element but
we usually do not emphasize on that.
 
 
> point2<inches> p(10, 12);
> p += vect2<inches>(3, 8);
> cout << p << endl; // It outputs: 13 20"
 
That is too far from math that is needed for dealing
with engines pulling around objects that are attached to
each other in real or emulated world (IOW scientific and
engineering applications).
 
> How can you do that using Boost.Units or another units library
> combined with a vector algebra package?
 
My impression is that *none* of those linear algebra libraries
and "measures" or "quantities" libraries are designed to play
well together. My suggestion was to do something that stands out
of pack in that respect.
 
> while interfacing it with other libraries,
> you lose unit checking, as other libraries
> sometime perform unit-forbidden operations.
 
Similarly linear algebra library gives compile time
error if you try to multiply 4x4 matrix with 3x3 matrix.
 
> However, you can interface Cpp-Units with other libraries.
 
I can interface between anything be it Haskell or Fortran
or Javascript; after all it is C++ (read One Ring) that I
wield. However it is *inconvenient*. Why it must be always
so inconvenient? Why must I always squeeze the bits out of
one library thru badly documented loopholes and then pluck
them into other? Especially when both proudly claim being
meant for my "convenience" of writing scientific and
engineering applications. :D
Ronald <rlc@vlinder.ca>: Oct 04 10:19PM


> Claiming that software for those must be written in C is like
> claiming that engineering or scientific analysis software has
> to be written in Fortran.
I can second that: I've been working on embedded devices for over a decade
now and while I've worked with micro-controllers that required very small
footprints, by far most devices I've seen had quite powerful processors,
and all could be programmed in C++.
 
For me, the important part of an engineering units library would be that it
upholds the "zero overhead" principle: if behind the scenes a "Volt" is
simply a float (or a double), it should take no more place than that float
and should be no more costly to work with. Ideally, it would also know, at
compile-time, that Volts multiplied by Amperes give a Watts, and that it
doesn't make sense to add them; that a dimensionless value divided by
seconds would give Hertz, etc., with compile-time checks for the operations
that make sense and no run-time overhead.
 
That, btw, is something C cannot do (its type system is too weak).
 
<snip>
 
rlc
MikeCopeland <mrc2323@cox.net>: Oct 03 10:12PM -0700

In article <c93ednFphb3U2@mid.individual.net>, ian-news@hotmail.com
says...
> > scalar index for this process, even though I'm using an iterator to
> > traverse the vector.
 
> What made you reach that conclusion?
 
The fact that using the iterator invalidates itself, so deleting via
a scalar index would work better. (Perhaps I'm confused...once again.)
 
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
Ian Collins <ian-news@hotmail.com>: Oct 04 10:58PM +1300

MikeCopeland wrote:
 
>> What made you reach that conclusion?
 
> The fact that using the iterator invalidates itself, so deleting via
> a scalar index would work better. (Perhaps I'm confused...once again.)
 
I think you are (confused). Look up the delete method for containers.
See what it returns and look at the examples posted of how to use it.
 
--
Ian Collins
Ronald <rlc@vlinder.ca>: Oct 04 12:35AM

> Googling i found that puting the def. value both in the header AND the
> implementation file is what's usually causing this error.
 
> I hope i wake up to a solution.... thank you
 
Probably you have something like
class C
{
public :
void foo(int I = 0);
};
 
void C::foo(int I = 0)
{}
 
and it chokes on the second I = 0
 
If so, remove the = 0
 
If that is not your problem, post code.
 
rlc
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: