- Combining constructors - 4 Updates
- Perhaps you are not understanding the nature of Allah or God ! - 4 Updates
- Multi-compare operators - 4 Updates
- testing a piece of inline code - 1 Update
- int8_t and char - 3 Updates
- testing a piece of inline code - 1 Update
Paul <pepstein5@gmail.com>: Sep 28 01:59PM -0700 I have a class A which implements an instantiation of class B with some default parameters. class B in turn depends on other classes. So my design looks like this. class B { public: B(const C&); protected: void implementInBaseClass(); }; class A : public B { public: A(); void someFunction(); }; A::A() : B(C(D(OtherParams))) {} void A::someFunction() { implementInBaseClass; } This code works fine, but I lack the vocab to explain the design. It looks similar to the strategy design pattern. In particular I don't know the term for combining constructors as in B(C(D(E(F(params)))))... where B, C, D, E, F are classes. If you think this idea looks bad and have other ideas, that is welcome too. Thank you, Paul |
Paul <pepstein5@gmail.com>: Sep 28 02:03PM -0700 On Friday, September 28, 2018 at 10:00:05 PM UTC+1, Paul wrote: > too. > Thank you, > Paul Sorry but it's difficult to avoid typos when I'm not using a compiler. I meant void A::someFunction() { implementInBaseClass(); } |
"Öö Tiib" <ootiib@hot.ee>: Sep 28 03:00PM -0700 On Saturday, 29 September 2018 00:03:41 UTC+3, Paul wrote: > { > implementInBaseClass(); > } May be I am wrong but such "A(B(C(D())))" feel like attempt of art ... designing and drawing various ornaments. Is it useful for something unknowable, or maybe it is not I can't know. It is sure that it is not an algorithm. Solving problems does not work like that. We do not throw up code patterns to see if it maybe helps with something but instead we take real problem and try to invent an algorithm to solve it. Different algorithms solve different problems. So, take actual practical goal to solve. To solve it write algorithm that has input (may be just constant test input) data and output (may be just assert that output of algorithm is correct). In context of such algorithms also patterns start to make sense. ;) |
Paul <pepstein5@gmail.com>: Sep 28 03:44PM -0700 On Friday, September 28, 2018 at 11:00:38 PM UTC+1, Öö Tiib wrote: > that has input (may be just constant test input) data and output > (may be just assert that output of algorithm is correct). In > context of such algorithms also patterns start to make sense. ;) class B { public: B(const C&); protected: void implementInBaseClass(); }; class A : public B { public: A(); void someFunction(); }; A::A() : B(C(D(OtherParams))) {} void A::someFunction() { implementInBaseClass(); } The above is certainly not an algorithm but nobody ever said it was. It's also not a chocolate biscuit. It is a design pattern, though. So I was asking the name of the design pattern. Paul |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Sep 28 09:35PM +0100 On 28/09/2018 11:57, Rick C. Hodgin wrote: >> doesn't exist, .. . > Allah is the generic name for "god," but it's also the proper name for > the god of Islam. Wrong you ignorant fuckwit: "Arabic-speakers of all Abrahamic faiths, including Christians and Jews, use the word "Allah" to mean "God".[10] The Christian Arabs of today have no other word for "God" than "Allah".[31] (Even the Arabic-descended Maltese language of Malta, whose population is almost entirely Roman Catholic, uses Alla for "God".) Arab Christians, for example, use the terms Allāh al-ab (الله الأب) for God the Father, Allāh al-ibn (الله الابن) for God the Son, and Allāh al-rūḥ al-quds (الله الروح القدس) for God the Holy Spirit. (See God in Christianity for the Christian concept of God.)" -- https://en.wikipedia.org/wiki/Allah > If you knew more about Islam and Christianity, you would realize that > the god of Islsm and the God of Israel, are unrelated. It reveals itself. It appears it is I who knows more about this subject than you and I am an atheist. > Have you ever heard of gifted students with so much potential, but they don't > apply themselves to study so they wash out? It is obvious who didn't pay enough attention in school and it isn't me. You are a classic case of the Dunning-Kruger Effect. Get a clue you bigoted ignorant cretin. /Flibble -- "Suppose it's all true, and you walk up to the pearly gates, and are confronted by God," Bryne asked on his show The Meaning of Life. "What will Stephen Fry say to him, her, or it?" "I'd say, bone cancer in children? What's that about?" Fry replied. "How dare you? How dare you create a world to which there is such misery that is not our fault. It's not right, it's utterly, utterly evil." "Why should I respect a capricious, mean-minded, stupid God who creates a world that is so full of injustice and pain. That's what I would say." |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Sep 28 02:39PM -0700 On Friday, September 28, 2018 at 4:35:42 PM UTC-4, Mr Flibble wrote: > الابن) for God the Son, and Allāh al-rūḥ al-quds (الله الروح القدس) for > God the Holy Spirit. (See God in Christianity for the Christian concept of > God.)" -- https://en.wikipedia.org/wiki/Allah Wikipedia is not a good source for definitive religious content. It is compromised by people who have an agenda against legitimate teachings. > > the god of Islsm and the God of Israel, are unrelated. It reveals itself. > It appears it is I who knows more about this subject than you and I am an > atheist. I watch an Arabic Christian pastor each week. He is Pastor JD Farag on YouTube. He has spoken many times about the use of the word "allah" for God and what it means. But the God of the Bible is not just "God." He has revealed His names. He is Jehovah. His Son's name is Yeshua (Jesus). And He has a host of other names which describe His attributes, including "I AM" (called "The Great I AM"). Names of God in the Bible: https://www.jesusfilm.org/blog-and-stories/names-of-god.html Adonai: https://www.youtube.com/watch?v=x9P5q_xo2a0 Ancient Of Days: https://www.youtube.com/watch?v=5m04UJ6BCrI Elohim: https://www.youtube.com/watch?v=pIf6j-WeyFw El Elyon: https://www.youtube.com/watch?v=-3i9j-GpMco El Olam: https://www.youtube.com/watch?v=5tr5VwH90a4 El Roi: https://www.youtube.com/watch?v=JQRkfr-mcHs El Shaddai: https://www.youtube.com/watch?v=DuXB1a3NBCw Jehovah Jireh: https://www.youtube.com/watch?v=yy2FFM9Kjqw https://www.youtube.com/watch?v=C6WexG9uAJI&t=1m54s Jehovah Nissi: https://www.youtube.com/watch?v=C6WexG9uAJI&t=2m2s Jehovah Raah (Rohi) Jehovah Rapha Jehovah Sabaoth Jehovah Shalom Jehovah Shammah Jehovah Tsidkenu Jehovah Mekoddishkem YHWH (Yahweh or Jehovah) He has more than one name. It would be beyond foolish to call the God of the Bible "Allah." It would be correct to refer to the "allah" of the Bible by His proper names, but even then it is only where the language uses that name. Much to learn you still have, young padawan. > It is obvious who didn't pay enough attention in school and it isn't me. > You are a classic case of the Dunning-Kruger Effect. Get a clue you > bigoted ignorant cretin. If I am mistaken on any of the things I teach I will gladly apologize and make the appropriate corrections. Will you also do the same? -- Rick C. Hodgin |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Sep 28 10:43PM +0100 On 28/09/2018 22:39, Rick C. Hodgin wrote: > to refer to the "allah" of the Bible by His proper names, > but even then it is only where the language uses that name. > Much to learn you still have, young padawan. ORLY? https://simple.wikipedia.org/wiki/Names_of_God_in_Islam Now fuck off you demented ignorant stupid fuckwit. /Flibble -- "Suppose it's all true, and you walk up to the pearly gates, and are confronted by God," Bryne asked on his show The Meaning of Life. "What will Stephen Fry say to him, her, or it?" "I'd say, bone cancer in children? What's that about?" Fry replied. "How dare you? How dare you create a world to which there is such misery that is not our fault. It's not right, it's utterly, utterly evil." "Why should I respect a capricious, mean-minded, stupid God who creates a world that is so full of injustice and pain. That's what I would say." |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Sep 28 03:00PM -0700 On Friday, September 28, 2018 at 5:43:34 PM UTC-4, Mr Flibble wrote: > ORLY? > ... Names_of_God_in_Islam > Now .. you demented ignorant stupid .. . Islam came into existence in the 600s. Satan is only an imitator, Leigh. He's not an originator. God had many names, so he imitated God when he invented Islam to deceive people into following a false religion. The good news is, the only people who will follow Islam are those who are lost. The rest will come out from the deception, turn to Jesus, ask forgiveness and be saved. This is happening to the Muslim world in miraculous and many ways daily. Some devout Muslims report seeing im- ages of Jesus appear before them, and they convert, even at the risk of being killed, or having their family be killed. If you want to know the truth, it's before you. All you have to do is seek it. I used to be an atheist too, Leigh. Atheists are not immune to the pull of God when He draws you in to save you. No one is immune. The only people not being saved are those who are not being saved. -- Rick C. Hodgin |
"Öö Tiib" <ootiib@hot.ee>: Sep 28 10:37AM -0700 On Friday, 21 September 2018 17:19:36 UTC+3, bitrex wrote: > 1990s and I can't say it ever occurred to me to write a test like if ( a > < b < c ) I'd probably just write (a < b && b < c) by force of habit. > the former is very high-school math-y vs. Boolean logic. Note that the '(a < b && b < c)' is likely sub-optimal code when those are integer or pointer values and it is meant as a check if that 'b' is inside of some fixed range 'a' to 'c' (that is quite frequent purpose of that expression). Issue is that implementations tend to generate two branches there. Sometimes these are generated even when the a and c are known compile time. Branches are quite expensive on modern out-of-order hardware. |
scott@slp53.sl.home (Scott Lurndal): Sep 28 06:22PM >frequent purpose of that expression). Issue is that implementations >tend to generate two branches there. Sometimes these are generated >even when the a and c are known compile time. Modern compilers understand that and generate optimal code if requested (e.g. -O3): $ cat /tmp/a.c #include <string.h> #include <stdio.h> int main(int argc, const char **argv) { unsigned long a = strtoul(argv[1], NULL, 0); unsigned long b = strtoul(argv[2], NULL, 0); unsigned long c = strtoul(argv[3], NULL, 0); if (a < b && b < c) return 1; return 0; } gcc 4.6 without -O: 40054b: 48 8b 45 e8 mov -0x18(%rbp),%rax 40054f: 48 3b 45 f0 cmp -0x10(%rbp),%rax 400553: 73 11 jae 400566 <main+0xa2> 400555: 48 8b 45 f0 mov -0x10(%rbp),%rax 400559: 48 3b 45 f8 cmp -0x8(%rbp),%rax 40055d: 73 07 jae 400566 <main+0xa2> 40055f: b8 01 00 00 00 mov $0x1,%eax 400564: eb 05 jmp 40056b <main+0xa7> 400566: b8 00 00 00 00 mov $0x0,%eax 40056b: c9 leaveq 40056c: c3 retq gcc 4.6 with -O3 (no branches): 40051e: 48 8b 1c 24 mov (%rsp),%rbx 400522: 48 39 c5 cmp %rax,%rbp 400525: 0f 92 c0 setb %al 400528: 49 39 ec cmp %rbp,%r12 40052b: 48 8b 6c 24 08 mov 0x8(%rsp),%rbp 400530: 0f 92 c2 setb %dl 400533: 4c 8b 64 24 10 mov 0x10(%rsp),%r12 400538: 48 83 c4 18 add $0x18,%rsp 40053c: 21 d0 and %edx,%eax 40053e: 0f b6 c0 movzbl %al,%eax 400541: c3 retq > Branches are quite expensive on modern out-of-order hardware. And modern out-of-order hardware has quite effective branch prediction for most workloads. |
jameskuyper@alumni.caltech.edu: Sep 28 11:30AM -0700 On Friday, September 28, 2018 at 1:37:30 PM UTC-4, Öö Tiib wrote: > On Friday, 21 September 2018 17:19:36 UTC+3, bitrex wrote: ... > tend to generate two branches there. Sometimes these are generated > even when the a and c are known compile time. Branches are quite > expensive on modern out-of-order hardware. Could you demonstrate this, at high optimization levels? This involves several lower level questions: 1. What does the generated code look like when this problem comes up? 2. What is the better code you'd want to be generated? 3. What is the alternative way of writing equivalent C code for this purpose that will cause the better code to be generated? 4. Can you identify a particular compiler, with particular options selected, including high optimization levels, which produces the poorer code for if(a < b && b < c), but produces the better code for your preferred alternative? Naively, if your alternative C code is in fact equivalent, I'd expect any decent C compiler, at least when high optimization levels are selected, to generate the same better code for either form of the C code. |
"Öö Tiib" <ootiib@hot.ee>: Sep 28 01:23PM -0700 > 2. What is the better code you'd want to be generated? > 3. What is the alternative way of writing equivalent C code for this > purpose that will cause the better code to be generated? Most often we use [start end) ranges in C and C++. It is really implementation detail if we store representation of such range as start and end or as start and length since the length is end - start. For such ranges a point is in range when (1) start <= point and point < end. Also the point is in range when (2) (unsigned)(point - start) < length. The formula (2) did generate better code that did run quicker on iOS device than formula (1). I surely checked that it was also better in particular case (lot of verifying if points were in ranges or not) on Mac. > selected, including high optimization levels, which produces the poorer > code for if(a < b && b < c), but produces the better code for your > preferred alternative? I noticed that few years ago. With Clang of XCode for iOS, processor was perhaps ARMv7-A. Not sure if it was Objective-C or C++ but in given context these are all likely just front end to same compiler. Efficiency was important since it is good idea not to drain the battery of handheld device with processing. So I did bit more detailed profiling and bench-marking than usually needed. I can dig around in archives and for particular benchmarks and see what it shows with current compilers. > any decent C compiler, at least when high optimization levels are > selected, to generate the same better code for either form of the C > code. That is what I often say myself. But sometimes there can be that even most mundane expressions can be tinkered into somewhat more fitting with the context of usage, platform and compiler. |
Jorgen Grahn <grahn+nntp@snipabacken.se>: Sep 28 07:01PM On Fri, 2018-09-28, Stefan Ram wrote: >>I have about 30 lines of code which I need to test. > To "test" means: to test whether the piece of code fulfills > written specifications. Not necessarily. See e.g. exploratory testing. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
Ralf Goertz <me@myprovider.invalid>: Sep 28 05:13PM +0200 m Fri, 28 Sep 2018 03:16:25 -0700 (PDT) > typedef of some other integral type and also does not promote or > convert into those out of blue because it is required to be enum > class: enum class byte : unsigned char {}; But that doesn't help either if you are interested in an 8 bit integral type with formatted input. One could probably overload the appropriate operators oneself, but std::byte doesn't even have arithmetics or did I miss something? By the way, on Tuesday 11:37:27 -0700 (PDT) you said in this thread: > Mathematical operations are not defined for "short int" and shorter > integral types in C++. What do you mean by that? I can certainly add to short ints. #include <iostream> int main() { short int i1(7), i2(8); i1+=i2; std::cout<<i1<<std::endl; } compiles fine and prints 15 |
jameskuyper@alumni.caltech.edu: Sep 28 08:36AM -0700 On Friday, September 28, 2018 at 11:14:03 AM UTC-4, Ralf Goertz wrote: > m Fri, 28 Sep 2018 03:16:25 -0700 (PDT) > schrieb Öö Tiib <ootiib@hot.ee>: ... > int main() { > short int i1(7), i2(8); > i1+=i2; According to the standard, that code does not add two short ints. Both i1 and i2 get promoted to int, then they are added, producing a result of type 'int', then that result is converted back to short int. If it makes no difference for the observable behavior, an implementation for a platform that has hardware support for adding short ints will probably optimize the code to use that support - but that's not how the C standard defines the behavior. |
"Öö Tiib" <ootiib@hot.ee>: Sep 28 09:28AM -0700 On Friday, 28 September 2018 18:14:03 UTC+3, Ralf Goertz wrote: > type with formatted input. One could probably overload the appropriate > operators oneself, but std::byte doesn't even have arithmetics or did I > miss something? The std::byte has all bitwise arithmetic operators defined. What you mean by "formatted input"? Sure, when our use case needs something extra or different then that can be written. The std::byte is good precedent. Since standard library took to use enum class for it they now have to patch up all the defects in those like that one ... https://wg21.cmeerw.net/cwg/issue2338 ... and so it is potentially becoming good tool for making whatever type-safe integral types you need in C++. > > Mathematical operations are not defined for "short int" and shorter > > integral types in C++. > What do you mean by that? I can certainly add to short ints. James Kuyper gave perfect answer to that. Note that exactly because of such magical silent promotions and conversions sometimes some code will give unexpected diagnostics or results. |
ram@zedat.fu-berlin.de (Stefan Ram): Sep 28 02:38PM >I have about 30 lines of code which I need to test. To "test" means: to test whether the piece of code fulfills written specifications. So, make sure you write down those specs first! For those 30 lines. It's better to make a function out of those 30 lines, but if that's "not possible", you can leave them where they are and /copy/ them into a function just for the purpose of testing (or use tools, like the preprocessor, to do this automatically, so that you always edit only a single copy of those 30 lines). With means like »__attribute__ ((always_inline))« and today's optimizing compilers, there's rarely a reason not to structure code using functions. |
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:
Post a Comment