Coding: Fleeting Thoughts

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Jplus
Posts: 1721
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: Netherlands

Re: Coding: Fleeting Thoughts

Postby Jplus » Thu Jul 10, 2014 8:44 pm UTC

Was that the solution? Otherwise I would suggest checking whether your allcaps names aren't interfering with some nonstandard predefined macro.
"There are only two hard problems in computer science: cache coherence, naming things, and off-by-one errors." (Phil Karlton and Leon Bambrick)

coding and xkcd combined

(Julian/Julian's)

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Thu Jul 10, 2014 10:04 pm UTC

Xenomortis is correct. It's a similar issue to why you need typename. At the line state = ATTACKING;, nothing is explicitly dependent on a template parameter and thus state is looked up in the context of the definition of the function and outside the context of any instantiation. Because there's no guarantee that enveloped_signal<SomeType> will have a state variable for any specific concrete SomeType, the compiler isn't allowed to find the parent class's state. Changing it to this->state makes the expression dependent on this, which has a type enveloped_signal<T> which is dependent on T, and hence lookup for that expression is delayed until instantiation time. At that point the compiler knows what the value of T is, so it knows what signal<T> has and, assuming that T is such that it uses the primary signal template, can find signal<T>::state.

It's a direct consequence of the (IMO dumb) two-phase lookup rules.

User avatar
Diadem
Posts: 5654
Joined: Wed Jun 11, 2008 11:03 am UTC
Location: The Netherlands

Re: Coding: Fleeting Thoughts

Postby Diadem » Fri Jul 11, 2014 7:57 am UTC

Note that this will happily compile in Visual Studio. MSVC doesn't seem to compile templated code at all until it's been instantiated. I think this is the most sensible approach. I'm not entirely sure which is more in line with the official standard though.

One downside is that you can have blatantly illegal code in a project that still compiles, as long as it's in unused templated functions. So your code more easily accumulates hidden defects.
It's one of those irregular verbs, isn't it? I have an independent mind, you are an eccentric, he is round the twist
- Bernard Woolley in Yes, Prime Minister

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Fri Jul 11, 2014 9:27 am UTC

As suggested by Evan, MSVC compiles it happily because it doesn't implement two-phase lookup fully, using delayed lookup instead.
The standard mandates two-phase though, and so isn't strictly compliant.
Image

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Fri Jul 11, 2014 12:21 pm UTC

Sometimes I wish the only exception handling we had was a simple try-catch at the highest possible level...
Image

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Coding: Fleeting Thoughts

Postby ahammel » Fri Jul 11, 2014 3:51 pm UTC

I just ran A Python script which used subprocess to call another Python script. When the second script threw an unhandled exception containing the parameters passed to the second script and the exit code.

Spoiler:
Image
He/Him/His/Alex
God damn these electric sex pants!

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6579
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Fri Jul 11, 2014 4:52 pm UTC

I wrote a VBScript that called VBScripts before, although it was more of a poor-mans multithreading utility.
Summum ius, summa iniuria.

User avatar
Jplus
Posts: 1721
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: Netherlands

Re: Coding: Fleeting Thoughts

Postby Jplus » Fri Jul 11, 2014 7:46 pm UTC

ahammel wrote:I just ran A Python script which used subprocess to call another Python script. When the second script threw an unhandled exception containing the parameters passed to the second script and the exit code.

ParseError
"There are only two hard problems in computer science: cache coherence, naming things, and off-by-one errors." (Phil Karlton and Leon Bambrick)

coding and xkcd combined

(Julian/Julian's)

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Coding: Fleeting Thoughts

Postby ahammel » Fri Jul 11, 2014 7:49 pm UTC

ahammel wrote:I just ran A Python script which used subprocess to call another Python script. When the second script threw an unhandled exception, the first script threw another unhandled exception containing the parameters passed to the second script and the exit code.
He/Him/His/Alex
God damn these electric sex pants!

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Fri Jul 11, 2014 11:49 pm UTC

Seems like you've re-invented shellscripting.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Xanthir
My HERO!!!
Posts: 5410
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Sat Jul 12, 2014 5:47 am UTC

Xenomortis wrote:Sometimes I wish the only exception handling we had was a simple try-catch at the highest possible level...

The web allows nearly that, with window.onerror. ^_^
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Sat Jul 12, 2014 2:11 pm UTC

Xanthir wrote:
Xenomortis wrote:Sometimes I wish the only exception handling we had was a simple try-catch at the highest possible level...

The web allows nearly that, with window.onerror. ^_^


If nothing else, it's very true for arithmetic errors C/UNIX I guess. Only way of dealing with them (besides checking) is to listen to SIGFPE. Although there isn't really much in terms of recovery possible I think.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
phlip
Restorer of Worlds
Posts: 7572
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby phlip » Mon Jul 14, 2014 1:34 am UTC

Code: Select all

ON ERROR GOTO ErrHandler

Spoiler:

Code: Select all

ON ERROR RESUME NEXT

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

0xD34D
Posts: 6
Joined: Fri Jul 11, 2014 1:48 am UTC
Location: USA

Re: Coding: Fleeting Thoughts

Postby 0xD34D » Mon Jul 14, 2014 2:49 am UTC

FT: I wish I knew some assembly things, and how to use gdb, but learning ASM is hell and I haven't found a tutorial on gdb.

Can anyone suggest anything that will help me understand ASM in a way that might help me to write better C programs, since, after all, C is the main language I am trying to learn right now.

Fancy
Posts: 57
Joined: Sun Jul 13, 2014 7:23 pm UTC

Re: Coding: Fleeting Thoughts

Postby Fancy » Mon Jul 14, 2014 5:41 am UTC

I'm really fighting with myself over which notation to use in the following situation. Anyone have input on it? I personally prefer the second, less-common form.

Code: Select all

int main(int argc, int *argc[])    /*the more common of the two...or*/
int main(int argc, int **argc)     /*the one I prefer*/


From what I understand, the second one is less common, but is it really frowned upon or is it just a personal preference? I also prefer pointer notation over array notation...are these bad habits that I need to break ASAP?
With many little strokes a large tree is felled.
-Japanese Proverb

User avatar
Link
Posts: 1407
Joined: Sat Mar 07, 2009 11:33 am UTC
Location: ᘝᓄᘈᖉᐣ
Contact:

Re: Coding: Fleeting Thoughts

Postby Link » Mon Jul 14, 2014 7:28 am UTC

Fancy wrote:I'm really fighting with myself over which notation to use in the following situation. Anyone have input on it? I personally prefer the second, less-common form.

Code: Select all

int main(int argc, int *argc[])    /*the more common of the two...or*/
int main(int argc, int **argc)     /*the one I prefer*/


From what I understand, the second one is less common, but is it really frowned upon or is it just a personal preference? I also prefer pointer notation over array notation...are these bad habits that I need to break ASAP?

In plain C, I prefer the second one as well. AFAIK the entire array notation in C is essentially redundant, and in my experience, ditching the notion of a high-level array in favour of "a contiguous block of memory whose size is some natural-number multiple of the size of any of its elements" only leads to a better understanding of what's going on beneath the hood anyway.

It's a bit different in C++, because it has a high-level container model in addition to the basic C arrays; this makes me prefer the array notation for conformity's sake. I don't really use plain arrays in C++ that often, though; I prefer the std::array wrapper for arrays whose size is known at compile-time, and container classes for arrays which can change in size during execution. The only real use for undecorated C-style arrays is arrays whose size only becomes known at run-time, but doesn't change afterwards -- and frankly, I personally haven't encountered that situation very often.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Mon Jul 14, 2014 8:11 am UTC

I honestly don't see why it would matter. The statements are equivalent. Although, I'm not fool enough to believe there aren't people with very strong opinions as to why *[] is vastly superior to **, or vice versa.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Mon Jul 14, 2014 9:01 am UTC

phlip wrote:

Code: Select all

ON ERROR GOTO ErrHandler

Yeah...
But I do want a stack trace.

Fancy wrote:I'm really fighting with myself over which notation to use in the following situation. Anyone have input on it? I personally prefer the second, less-common form.

Code: Select all

int main(int argc, int *argc[])    /*the more common of the two...or*/
int main(int argc, int **argc)     /*the one I prefer*/


From what I understand, the second one is less common, but is it really frowned upon or is it just a personal preference? I also prefer pointer notation over array notation...are these bad habits that I need to break ASAP?

I'd say I have a weak preference for the first - saying what you mean (pointer to array), rather than what it is (pointer to pointer) - but the second is perhaps nicer aesthetically.
On the other hand, when you're thinking about pointers all the time, having the notation all in one place might be a good thing.
Image

speising
Posts: 2353
Joined: Mon Sep 03, 2012 4:54 pm UTC
Location: wien

Re: Coding: Fleeting Thoughts

Postby speising » Mon Jul 14, 2014 9:08 am UTC

first, it is usual to call the int argc, but the other argv.
anyway, if you are later dereferencing it with [], i think it makes sense to declare it with [], too.

Ubik
Posts: 1016
Joined: Thu Oct 18, 2007 3:43 pm UTC

Re: Coding: Fleeting Thoughts

Postby Ubik » Mon Jul 14, 2014 9:22 am UTC

The argv is usually something-char-something too.

Fancy
Posts: 57
Joined: Sun Jul 13, 2014 7:23 pm UTC

Re: Coding: Fleeting Thoughts

Postby Fancy » Mon Jul 14, 2014 1:38 pm UTC

...A continuation of my last fleeting thought.

The two argc was an accident, sorry for any confusion. I prefer it for the aesthetics, ut many people mention that it is harder for beginners to understand...I seem to be doing just fine though.

speising wrote:first, it is usual to call the int argc, but the other argv.
anyway, if you are later dereferencing it with [], i think it makes sense to declare it with [], too.


I actually don't dereference them with array notation either. I use pointers and whatnot like so.

Code: Select all

arr[6];
*(arr + 6);

Again, just preference. And because my terminal font can't render the square brackets correctly. They look all long and skinny.
With many little strokes a large tree is felled.
-Japanese Proverb

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Mon Jul 14, 2014 2:24 pm UTC

[] is for indexing, pointer arithmetic for iterators.

While they are equivalent on pointers, I'd learn to use them distinctly. Especially if you want to learn C++, where they can differ significantly (in a way that lines up with their idiomatic use in C)
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Mon Jul 14, 2014 2:38 pm UTC

speising wrote:first, it is usual to call the int argc, but the other argv.
anyway, if you are later dereferencing it with [], i think it makes sense to declare it with [], too.
Except you usually (or at least I usually, anyway) access the first coordinate with [] too, but C doesn't let you declare both coordinates with [][].

I am pretty indifferent. I tend to use char**, but that's more because I'm lazy and it's easier to type. :-)

I do pretty strongly think that *(x + y) notation instead of x[y] is rarely appropriate.

Fancy
Posts: 57
Joined: Sun Jul 13, 2014 7:23 pm UTC

Re: Coding: Fleeting Thoughts

Postby Fancy » Mon Jul 14, 2014 3:03 pm UTC

Yakk wrote:
EvanED wrote:


Meh. I assumed people would disagree, but at the moment I'm just casually writing my own code. If I was writing code for an open-source project or actually employed, I like ot think I would take the time to do something other people find reasonable.

How do they dffer in C++? I don't really plan on learning it at the moment, but curiosity drives me to ask.
With many little strokes a large tree is felled.
-Japanese Proverb

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Mon Jul 14, 2014 3:08 pm UTC

C++ has actual iterator and collection objects.
Iterators are manipulated through using pointer-arithmetic like operations, collections are accessed through [].
(C++ has operator overloading and STL classes typically overload operators to follow this pattern)
Image

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Mon Jul 14, 2014 5:53 pm UTC

Write code better than your project deserves, so you become ready for a better project. :)
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6579
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Mon Jul 14, 2014 6:29 pm UTC

grumble grumble c++ sucks grumble grumble no std::vector<std::string> argv grumble grumble
Summum ius, summa iniuria.

User avatar
Jplus
Posts: 1721
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: Netherlands

Re: Coding: Fleeting Thoughts

Postby Jplus » Mon Jul 14, 2014 6:33 pm UTC

"There are only two hard problems in computer science: cache coherence, naming things, and off-by-one errors." (Phil Karlton and Leon Bambrick)

coding and xkcd combined

(Julian/Julian's)

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6579
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Mon Jul 14, 2014 7:56 pm UTC

I'm pretty sure I can make a function that converts it in about 6 lines as well.
Summum ius, summa iniuria.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Mon Jul 14, 2014 8:51 pm UTC

6 lines? What are you doing with the other 5?

Code: Select all

int main( unsigned argc, char const*const* argv ) {
  std::vector<std::string> args{ argv, argv+argc };
  // done
}

Besides, std::initializer_list should be the main, not std::vector.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6579
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Mon Jul 14, 2014 10:47 pm UTC

I wasn't aware of that syntax, but two of those lines were function definition and return value. Is there a reason why that code doesn't overflow?
Summum ius, summa iniuria.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Mon Jul 14, 2014 10:55 pm UTC

Thesh wrote:I wasn't aware of that syntax, but two of those lines were function definition and return value. Is there a reason why that code doesn't overflow?

Why would it overflow?
std::vector has a range based constructor; it's just calling that.
Image

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6579
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Mon Jul 14, 2014 10:59 pm UTC

argv+argc is past the end of the array.

EDIT: nvm, didn't read all the documentation. I guess it's designed to work with end() which I despise, so I guess I despise that construct as well.
Summum ius, summa iniuria.

Fancy
Posts: 57
Joined: Sun Jul 13, 2014 7:23 pm UTC

Re: Coding: Fleeting Thoughts

Postby Fancy » Tue Jul 15, 2014 12:34 am UTC

Yakk wrote:Write code better than your project deserves, so you become ready for a better project. :)

You saying this makes me feel bad, but if I change now all of code will have to be changed for consistency.

A fleeting thought addendum
Trying to learn C is really frustrating me and making me feel like an absolute idiot, and I don't want to clog up these forums with my requests for help, but I have no where else to go...

I mean, I feel like an absolute imbecile for this. This is such basic stuff, and yet it doesn't work. The book teaches us with these nice, slow examples that make sense, and then BAM the end of chapter problems are virtually impossible.
With many little strokes a large tree is felled.
-Japanese Proverb

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Tue Jul 15, 2014 2:25 am UTC

@Thresh, while iterators may look evil, they end up producing really elegant code.

@Fancy Sure. But you are not supposed to be able to solve every end of chapter problem often, at least not easily.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Coding: Fleeting Thoughts

Postby ahammel » Tue Jul 15, 2014 2:27 am UTC

Fancy wrote:I mean, I feel like an absolute imbecile for this. This is such basic stuff, and yet it doesn't work.

I've felt like that ever since I learned to program :D
He/Him/His/Alex
God damn these electric sex pants!

Fancy
Posts: 57
Joined: Sun Jul 13, 2014 7:23 pm UTC

Re: Coding: Fleeting Thoughts

Postby Fancy » Tue Jul 15, 2014 2:31 am UTC

Yakk wrote:@Thresh, while iterators may look evil, they end up producing really elegant code.

@Fancy Sure. But you are not supposed to be able to solve every end of chapter problem often, at least not easily.

But some of them are just so easy even a 2 year old could do them, and I can't.

"Write a function that finds the first word in an input line, ingoring all preceding whitespace, and have it store it in an array."
What the hell is this?
With many little strokes a large tree is felled.
-Japanese Proverb

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6579
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Tue Jul 15, 2014 2:36 am UTC

Yakk wrote:@Thresh, while iterators may look evil, they end up producing really elegant code.

I realize the advantages, I hate the concept of returning an out of bounds, yet valid, pointer.

EDIT:

Tangentally related note, I've been thinking about sorting algorithms for linked lists, and I came up with one I find a little interesting:

Ingredients:
Doubly linked list to sort
Stack to store pointers to elements in linked list

1) Start with your comparison element c at index 0
2) Seek at elements > c until you find an element e that is less than your comparison element
3) add the pointer to the element n that comes before e to the stack, insert e before c. e becomes c, and the element after n becomes the next e
4) repeat steps 2 and 3 until you reach the end of the list
5) if c is the last element in the list, it is sorted, then you can return otherwise go to step 6
6) set c to the next element in the list (note that at this point, everything up to c is sorted)
7) pop the last element off the stack, and set e equal to the very next element
8) Go to step 2

Interesting things:
Worst case scenario is an already sorted list at O(n^2)
Best case scenario is a list in reverse order at O(n)
I believe average case is O(nlogn) although I haven't thought of how to figure that out, and I'm too lazy to test.

Not the best algorithm, but I thought it was funny that an already sorted list is the worst case, and a reverse order was the best case.
Summum ius, summa iniuria.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Tue Jul 15, 2014 9:31 am UTC

Thesh wrote:
Yakk wrote:@Thresh, while iterators may look evil, they end up producing really elegant code.

I realize the advantages, I hate the concept of returning an out of bounds, yet valid, pointer.

IIRC, a pointer past the end of an array must compare greater than any pointer in the array, so testing it arithmetically is valid.
Just don't dereference it - all hell can break loose then.

Fancy wrote:Trying to learn C is really frustrating me and making me feel like an absolute idiot, and I don't want to clog up these forums with my requests for help, but I have no where else to go...

C is probably a bad choice for a first language; yes it's a simple language, but there are so many caveats, pitfalls, and complications that it's really easy to just end up getting confused and frustrated without getting anything done.

Fancy wrote:"Write a function that finds the first word in an input line, ingoring all preceding whitespace, and have it store it in an array."
What the hell is this?

I can guarantee that if I tried to implement this in C, I'd fuck up in some way and get some mysterious error.
I can do it in Python trivially (although I had to look up how to read from stdin).

Edit:
Yeah, I corrupted something and my code printed some random ASCII character...
Image

User avatar
Diadem
Posts: 5654
Joined: Wed Jun 11, 2008 11:03 am UTC
Location: The Netherlands

Re: Coding: Fleeting Thoughts

Postby Diadem » Tue Jul 15, 2014 9:51 am UTC

One of the peculiarities of C++ is that Pi isn't defined anywhere in the standard library. So you have to do that yourself. You can do this once in some common header of course, but that would be way too easy. Much better to use a numeric literal for pi 20 different times (some in definitions for a pi-constant, some directly in computations).

But wait, it gets much better. Some heroic previous developer apparently figured out that pi is equal to 4.0 * atan(1.0). This happy fact of course had to be shared with the world.

So pi is defined this way 71 different times. One particularly egregious file defines a local constant pi at the start of every single function in the class.

I'm in hell.
It's one of those irregular verbs, isn't it? I have an independent mind, you are an eccentric, he is round the twist
- Bernard Woolley in Yes, Prime Minister


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 3 guests