POV-Ray : Newsgroups : povray.off-topic : Teach yourself C++ in 21 days Server Time
26 Nov 2026 10:09:16 EST (-0500)
  Teach yourself C++ in 21 days (Message 119 to 168 of 168)  
<<< Previous 50 Messages Goto Initial 50 Messages
From: Darren New
Subject: Re: Days 5-
Date: 20 Apr 2012 23:49:18
Message: <4f922e3e@news.povray.org>
On 4/20/2012 1:38, Invisible wrote:
>>> In other words, yet again, "now you know how this works, you don't
>>> need to actually use it".
>>
>> Right. Except in very limited circumstances when you know how deeply
>> you'll recurse, because there's no guarantee it'll work and no way to
>> check.
>
> ...what?

You have no way of knowing how much stack space you have. Nobody writing 
reliable code wants to recurse for each level of a tree without knowing how 
deep the tree is.

>>> "Registers are a special area of memory built right into the CPU."
>>> Erm...
>>
>> What's questionable about that? Heck, on the Sigma 9, the registers 0
>> thru 15 were actually addressed as memory locations 0 thru 15, to the
>> point where you could store program code in the registers and branch to it.
>
> Nobody designs hardware like that any more. Haven't done for decades. :-P

So? They're still special areas of memory built into the CPU. Just because 
you can't address them using normal addressing modes any more doesn't mean 
they're not memory.

>>> "They take care of internal housekeeping."
>>> ...actually...
>>
>> Program Status Word.
>
> The /registers/ do not take care of anything. The /processor/ does.

Oh come on. :-)  The TLB registers take care of internal housekeeping 
certainly.  As do watchdog timer counters, interrupt mask levels, etc.

>>> So I'm guessing an architecture exists where the instruction pointer
>>> /isn't/ a single register then? :-P
>>
>> Yep. Anything with memory mapping hardware, segment registers, etc.
>
> None of which are relevant in the current day and age, unless you're writing
> an OS. Certainly this technicality has no place in an introductory
> programming text.

You asked. The IP address isn't a single register even on a 8086, and that 
isn't *that* long ago.

>>> Still, it does answer something I've always wondered about: What *is*
>>> the C calling convention?
>>
>> Undefined, generally speaking. Or rather, implementation-specific. And
>> depends on pragmas, sometimes.
>
> So you're telling me that the de facto calling convention that all software
> always uses is "undefined"?

Implementation-specific, yes.  How could you define it in a standard when 
you don't even know what architecture you're compiling for?

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Days 1-5
Date: 20 Apr 2012 23:52:16
Message: <4f922ef0$1@news.povray.org>
On 4/20/2012 0:51, Invisible wrote:
>>>> The integral part of the value is assigned to the int.
>>> So... it always rounds towards zero?
>>
>> As long as they're both positive.
>
> Does it round towards zero, or towards negative infinity?

I don't remember. I never use it under those circumstances, probably because 
it's implementation-defined.

> Oh good. The book /insists/ that left-to-right order is guaranteed.

There are a handful of operators for which that's true. The rest, not so much.

> A better way might be to think of true and false as 1 and 0. (Although of
> course C allows true to be /anything/ that isn't 0, not just 1.)

The real way to think of it is "BZ" and "BNZ" - branch on zero, and branch 
on not zero.  Of course, if you don't know common modern assembler, that 
might not be any easier to remember.

> I'm currently trying to work out how I can compile a program where module 1
> refers to module 2, but module 2 also refers to module 1. As far as I can
> figure out, this is impossible...

Neither can actually refer to the other, so you're good to go there. Just 
use the normal header file stuff.

Everything you refer to has to be compiled in the same compilation unit, so 
C and C++ really don't have any trouble with circular references. A benefit 
I never really realized before.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Days 1-5
Date: 20 Apr 2012 23:58:53
Message: <4f92307d$1@news.povray.org>
On 4/20/2012 5:18, Warp wrote:
> Darren New<dne### [at] sanrrcom>  wrote:
>> If you could #include<abc.o>  you'd get rid of all the silliness of
>> declaring inline functions multiple times, function prototypes, and all that
>> kind of BS.
>
>    So you would be simply changing the dependency to a .h file to dependency
> to a .o file. What would be the relevant difference?

You'd be getting rid of function prototypes, declaring inline functions 
multiple times, mismatched declarations between compilation units, 
compatible compiler flags between separately-compiled modules, and etc. That 
would be the relevant difference.

(Of course, if you *want* to have header files, you can still depend on the 
.o file instead of the .h file, and let people write the .c file even though 
you can still compile against the .h file.)

>    Also, I assume you understand that templated code cannot be precompiled
> into an object file? They need to be recompiled each time they are used...
> which is kind of the whole idea.

Of course. It's basically macro expansion. That's why I didn't say depending 
on a .h file would get rid of template functions.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Days 1-5
Date: 21 Apr 2012 00:00:45
Message: <4f9230ed$1@news.povray.org>
On 4/20/2012 0:20, Le_Forgeron wrote:
> Le 20/04/2012 03:56, Darren New a écrit :
>> On 4/19/2012 18:38, Alain wrote:
>>> Le 2012/04/17 09:40, Warp a écrit :
>>>
>>>>> is a perfectly valid statement in C++. On the other hand, it also
>>>>> means that
>>>>
>>>>> while (x[i] = y[i--]) ;
>>>>
>>>>> is perfectly valid. You sick, sick people.
>>>>
>>>> I think that's Undefined Behavior because the same variable is being

>>>> modified and referenced more than once in the same expression.
>>>>
>>>
>>> Nothing undefined here.
>>
>> Does it compare x[i] to y[i] or to y[i-1]?  Why do you answer that way
?
>>
> You missed the point: let's name k the initial value of i;

I don't think I missed the point. I just got the possible answers wrong. 
The 
*point* was that there *were* multiple possible answers. :-)

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Days 1-5
Date: 21 Apr 2012 00:01:54
Message: <4f923132$1@news.povray.org>
On 4/20/2012 0:55, Invisible wrote:
>>>>> while (x[i] = y[i--]) ;
>>>>
>>>>> is perfectly valid. You sick, sick people.
>>>>
>>>> I think that's Undefined Behavior because the same variable is being
>>>> modified and referenced more than once in the same expression.
>>>>
>>>
>>> Nothing undefined here.
>>
>> Does it compare x[i] to y[i] or to y[i-1]? Why do you answer that way?
>
> Last time I checked, the /comparison/ operator is ==.
>
> The = operator performs *assignment*. :-P

Yah yah. Still missing the point. It's still undefined, whether it's an 
assignment or a comparison.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 21 Apr 2012 00:02:43
Message: <4f923163$1@news.povray.org>
On 4/20/2012 0:57, Invisible wrote:
>>> When will we see the Haskell# language?
>>
>> I'm pretty sure the whole .NET bit is too OO to make that useful.There's
>> way too much stateful stuff (like I/O) that you'd want to use from .NET
>> to make it reasonable to have a purely function .net language.
>
> Haskell already supports a wide range of I/O operations. That's pretty
> stateful, and it's not a problem.
>
> Yeah, if you wanted to talk to the .NET libraries, it would all end up being
> monadic. (Even the .NET stuff that's actually pure - since it isn't /marked/
> as pure.) But it would still work fine.
>
> I think it's probably vacuous to try to estimate how "useful" it would be
> without actually trying it...

Well, they tried making STM work on .NET and gave up because of all the 
state, if you remember.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 21 Apr 2012 00:04:47
Message: <4f9231df$1@news.povray.org>
On 4/20/2012 10:02, Orchid Win7 v1 wrote:
> On 20/04/2012 02:41 AM, Darren New wrote:
>> Plus, the IDE for Smalltalk doesn't really deal too much with the fact
>> that it's OO. It didn't do any of the sorts of completion you're talking
>> about.
>
> Well, to be fair, since Smalltalk isn't statically typed, you'd be
> hard-pressed to figure out what messages are applicable to a given variable.
> ;-)

You'd be surprised. People write code that looks at javascript, for example, 
and comes up with something like 70% of the variables being statically typed 
in ways that it's even easy to tell.  Even when you *could* figure it out, 
indeed even when the variable had a value already, you didn't get the sorts 
of completion you're talking about.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 21 Apr 2012 00:05:47
Message: <4f92321b@news.povray.org>
On 4/20/2012 1:07, Invisible wrote:
>>> (And besides, any kind of detection of this cannot be 100% accurate,
>>> as the problem "will this line of code ever be reached?" is unsolvable
>>> in the general case.)
>>
>> But detecting type errors isn't 100% accurate either.
>>
>> int x = 1 ? 5 : "hello";
>>
>> That's not legal, but it's not a type violation either.
>
> The general problem of determining whether every possible code path is
> well-typed is undecidable. Type systems insert artificial restrictions to
> /make/ the problem decidable. Hence, there are expressions and statements
> which are well-typed, but do not type-check.

Which is the point I'm making. We put up with saying "that'll never be the 
wrong type, but it's still illegal", so the argument that "whether this code 
is reachable is unsolvable, so we shouldn't even try" is equally bogus.)

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Orchid Win7 v1
Subject: Re: Days 1-5
Date: 21 Apr 2012 14:15:20
Message: <4f92f938$1@news.povray.org>
>> Does it round towards zero, or towards negative infinity?
>
> I don't remember. I never use it under those circumstances, probably
> because it's implementation-defined.

No wonder so many programs don't compile if you (say) change from a 
32-bit OS to a 64-bit OS...

>> A better way might be to think of true and false as 1 and 0. (Although of
>> course C allows true to be /anything/ that isn't 0, not just 1.)
>
> The real way to think of it is "BZ" and "BNZ"

Sure, that's obviously how it's implemented (and why it works that way). 
Still doesn't help me remember which is which. ;-)


Post a reply to this message

From: Orchid Win7 v1
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 21 Apr 2012 14:18:50
Message: <4f92fa0a$1@news.povray.org>
>>> But detecting type errors isn't 100% accurate either.
>>>
>>> int x = 1 ? 5 : "hello";
>>>
>>> That's not legal, but it's not a type violation either.
>>
>> The general problem of determining whether every possible code path is
>> well-typed is undecidable. Type systems insert artificial restrictions to
>> /make/ the problem decidable. Hence, there are expressions and statements
>> which are well-typed, but do not type-check.
>
> Which is the point I'm making.

And I'm agreeing. ;-) [Although I'm not sure I got the technical terms 
right...]

> We put up with saying "that'll never be
> the wrong type, but it's still illegal", so the argument that "whether
> this code is reachable is unsolvable, so we shouldn't even try" is
> equally bogus.)

Well, to be fair, the code you worked is well-typed, but /very stupid/. 
The fact that it gets rejected is no big deal, really.

(OTOH, all the advocates of dynamically-typed languages seem to think 
that this is /the primary reason/ that statically-typed languages suck - 
because you /can't/ just do whatever the hell you want, no matter how 
incoherent.)


Post a reply to this message

From: Orchid Win7 v1
Subject: Re: Days 5-
Date: 21 Apr 2012 14:28:10
Message: <4f92fc3a@news.povray.org>
> You have no way of knowing how much stack space you have. Nobody writing
> reliable code wants to recurse for each level of a tree without knowing
> how deep the tree is.

Nobody writes recursive code? IN WHICH UNIVERSE??

I'm also loving the way you say "you don't know how big the stack is", 
and immediately follow that with "you should check how deep the tree 
is". But if you don't know how big the stack is, you STILL don't know if 
you can do it. :-P

Besides, it's not like there's an /alternative/ to recursion.

>> Nobody designs hardware like that any more. Haven't done for decades. :-P
>
> So? They're still special areas of memory built into the CPU. Just
> because you can't address them using normal addressing modes any more
> doesn't mean they're not memory.

Well, to be /technical/ about it, the entire concept of "memory" is a 
fiction. It would be more accurate to say that there is a large topology 
of transistors connected together - but that's not a very useful way to 
think about it.

>> So you're telling me that the de facto calling convention that all
>> software
>> always uses is "undefined"?
>
> Implementation-specific, yes. How could you define it in a standard when
> you don't even know what architecture you're compiling for?

Amazing. So the one calling convention that every piece of software 
supports isn't actually defined at all. That's impressive, right there.


Post a reply to this message

From: Orchid Win7 v1
Subject: Re: Days 1-5
Date: 21 Apr 2012 14:30:50
Message: <4f92fcda@news.povray.org>
> At least on machines designed to be programmed in assembler, one can
> generally put a useful and informative comment on pretty much every line.

I haven't yet seen an assembler where you /can't/ stick comments 
anywhere you want to. That /still/ doesn't mean I want the comments to 
out-number the actual code.

>> You'd expect part of the language's basic syntax to be, you know...
>> part of
>> the language's basic syntax. But it isn't. It's just a regular operator,
>> which means you can use it in places where you shouldn't be putting
>> random
>> commas, and that makes it do strange stuff. (And, being C, this isn't
>> checked in any way.)
>
> Why would you put randomg *anything* in? This isn't a sonnet. It's
> computer code. Why would you put random commas in any more than you put
> random quote marks in?

Ever heard of something called a "mistake"? Perhaps you don't make 
those, but I do sometimes. And it's worrying to know that if I do, the 
compiler isn't going to say "oh, you made a mistake", it's just going to 
generate code that does something bizarre.

> Plus, "void" is a relatively recent development.

This is The Real WTF.


Post a reply to this message

From: Darren New
Subject: Re: Days 1-5
Date: 22 Apr 2012 23:23:26
Message: <4f94cb2e$1@news.povray.org>
On 4/21/2012 11:30, Orchid Win7 v1 wrote:
>> At least on machines designed to be programmed in assembler, one can
>> generally put a useful and informative comment on pretty much every line.
>
> I haven't yet seen an assembler where you /can't/ stick comments anywhere
> you want to. That /still/ doesn't mean I want the comments to out-number the
> actual code.

I said "useful."

> Ever heard of something called a "mistake"? Perhaps you don't make those,
> but I do sometimes. And it's worrying to know that if I do, the compiler
> isn't going to say "oh, you made a mistake", it's just going to generate
> code that does something bizarre.

Sure. And if you randomly change * to / and + to -, you'll get similar 
errors. In practice, it's not a mistake people make.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Days 5-
Date: 22 Apr 2012 23:30:04
Message: <4f94ccbc$1@news.povray.org>
On 4/21/2012 11:28, Orchid Win7 v1 wrote:
>> You have no way of knowing how much stack space you have. Nobody writing
>> reliable code wants to recurse for each level of a tree without knowing
>> how deep the tree is.
>
> Nobody writes recursive code? IN WHICH UNIVERSE??

I have written very very little recursive code in my entire career. Of that, 
90% of my recursive code is of the form
   Try to X, 10 times.
   if X failed,
     Try to X one fewer times

Yes, my current project has a tree structure that's at most 3 levels deep, 
and parsing that into flat structures is recursive, once. Before that, it 
was iterative over a queue. (Actually, it might still be, I don't remember.)

> I'm also loving the way you say "you don't know how big the stack is", and
> immediately follow that with "you should check how deep the tree is". But if
> you don't know how big the stack is, you STILL don't know if you can do it. :-P

Well, I know the stack is deep enough to hold 3 levels of tree. The point is 
you can't take an *arbitrary* tree and parse it recursively.

> Besides, it's not like there's an /alternative/ to recursion.

Of course there is. I'm pretty sure every recursive algorithm can be made 
explicitly iterative. The advantage of doing so is that you can handle 
failures of running out of resources, before you ask.

>>> Nobody designs hardware like that any more. Haven't done for decades. :-P
>>
>> So? They're still special areas of memory built into the CPU. Just
>> because you can't address them using normal addressing modes any more
>> doesn't mean they're not memory.
>
> Well, to be /technical/ about it, the entire concept of "memory" is a
> fiction. It would be more accurate to say that there is a large topology of
> transistors connected together - but that's not a very useful way to think
> about it.

But in some cases, those transistors are wired together in a way that 
retains state arbitrarily long, which we call memory. ;-)

>>> So you're telling me that the de facto calling convention that all
>>> software
>>> always uses is "undefined"?
>>
>> Implementation-specific, yes. How could you define it in a standard when
>> you don't even know what architecture you're compiling for?
>
> Amazing. So the one calling convention that every piece of software supports
> isn't actually defined at all. That's impressive, right there.

Which calling convention do you think every piece of software supports? It's 
defined by the implementation. Have you tried invoking Java code from C? 
Have you tried invoking C# code from C++? Have you invoked C++ objects from 
Haskell?

http://www.scribd.com/doc/20689745/Calling-Conventions

Not sure if you're trying to be sarcastic, incredulous, or simply ignorant here.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Invisible
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 23 Apr 2012 03:58:16
Message: <4f950b98@news.povray.org>
>> I think it's probably vacuous to try to estimate how "useful" it would be
>> without actually trying it...
>
> Well, they tried making STM work on .NET and gave up because of all the
> state, if you remember.

They gave up because they tried to make all the existing state mutation 
stuff still work in the presence of transactions, which is /obviously/ 
impossible.


Post a reply to this message

From: Invisible
Subject: Re: Days 1-5
Date: 23 Apr 2012 04:08:51
Message: <4f950e13$1@news.povray.org>
>> Ever heard of something called a "mistake"? Perhaps you don't make those,
>> but I do sometimes. And it's worrying to know that if I do, the compiler
>> isn't going to say "oh, you made a mistake", it's just going to generate
>> code that does something bizarre.
>
> Sure. And if you randomly change * to / and + to -, you'll get similar
> errors. In practice, it's not a mistake people make.

If you're in the middle of writing an expression, and the phone rings or 
something, and then you got back and hit "compile", it says "hey dude, 
this * operator only has one argument. Shouldn't there be two?"

But, apparently, if you're half way through writing a function call and 
the same thing happens, the compiler doesn't say anything, because comma 
is just a valid operator that you can put anywhere you want...


Post a reply to this message

From: Invisible
Subject: Re: Days 5-
Date: 23 Apr 2012 04:31:34
Message: <4f951366$1@news.povray.org>
>> Nobody writes recursive code? IN WHICH UNIVERSE??
>
> I have written very very little recursive code in my entire career.

Damn... I'm trying to think of something you can code without actually 
using recursion. Hmm. Well, I guess there must be /something/...

>> Besides, it's not like there's an /alternative/ to recursion.
>
> Of course there is. I'm pretty sure every recursive algorithm can be
> made explicitly iterative. The advantage of doing so is that you can
> handle failures of running out of resources, before you ask.

So if you want to count how many nodes there are in a binary tree, how 
do you do that non-recursively?

>> Amazing. So the one calling convention that every piece of software
>> supports
>> isn't actually defined at all. That's impressive, right there.
>
> Which calling convention do you think every piece of software supports?

> Not sure if you're trying to be sarcastic, incredulous, or simply
> ignorant here.

If a programming language supports calling /any/ foreign language, that 
language will always be C. It will know about standard C types, it will 
usually know about C structs, and it will let you call arbitrary C 
functions.

And yet, the way that you call a C function is, apparently, undefined.

That's pretty bizarre.

It also makes me wonder how the heck it's possible to take object code 
from multiple C compilers and link it all together, if each of them is 
potentially using a completely different calling convention. It sounds 
like it shouldn't work.


Post a reply to this message

From: Francois Labreque
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 23 Apr 2012 08:28:14
Message: <4f954ade$1@news.povray.org>
Le 2012-04-20 10:47, Invisible a écrit :
>> Not to mention a lot cheaper than a dozen
>> occupational therapy sessions due to tendinitis or carpal tunnel
>> syndrome.
>
> Nobody gets tendinitis just from using a mouse.
>

I have two weeks off work, 10 physiotherapy sessions and a visit from an 
occupational therapist at home to redesign my work space that disagree 
with you.

When you need to use the mouse with your right hand, you need to lift 
your arm over the numeric keypad and off to the side to grab the mouse, 
then move the arm back to the keyboard so that your can continue typing. 
  In most cases, this means lifting your entire arm from the shoulder on 
down, whereas if you were using your mouse left-handed, you'd only need 
to move your wrist, with your elbow still resting on the chair's arm rest.

Repeated sporadic use of the mouse over the course of two long mights 
and days of work did cause me to have tendinitis bad enough that I had 
to be driven to the hospital since I could no longer lift my right arm 
at the shoulder, and it would have been too dangerous to try to drive in 
those conditions.

-- 
/*Francois Labreque*/#local a=x+y;#local b=x+a;#local c=a+b;#macro P(F//
/*    flabreque    */L)polygon{5,F,F+z,L+z,L,F pigment{rgb 9}}#end union
/*        @        */{P(0,a)P(a,b)P(b,c)P(2*a,2*b)P(2*b,b+c)P(b+c,<2,3>)
/*   gmail.com     */}camera{orthographic location<6,1.25,-6>look_at a }


Post a reply to this message

From: Invisible
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 23 Apr 2012 09:25:03
Message: <4f95582f$1@news.povray.org>
>> Nobody gets tendinitis just from using a mouse.
>
> I have two weeks off work, 10 physiotherapy sessions and a visit from an
> occupational therapist at home to redesign my work space that disagree
> with you.

OK. So maybe you had the desk at the wrong height or something? IDK. 
I've been using a mouse since I was 12, sometimes staying up to program 
until 2 in the morning, and it hasn't caused my any trouble.

FWIW, I also play keyboard, where you have to constantly support the 
entire weight of your arm all the time. And I played violin for years...

> When you need to use the mouse with your right hand, you need to lift
> your arm over the numeric keypad and off to the side to grab the mouse,
> then move the arm back to the keyboard so that your can continue typing.
> In most cases, this means lifting your entire arm from the shoulder on
> down, whereas if you were using your mouse left-handed, you'd only need
> to move your wrist, with your elbow still resting on the chair's arm rest.

I usually have an arm rest set up so I only have to lift my forearm, not 
my entire arm, but hey.

> Repeated sporadic use of the mouse over the course of two long mights
> and days of work did cause me to have tendinitis bad enough that I had
> to be driven to the hospital since I could no longer lift my right arm
> at the shoulder, and it would have been too dangerous to try to drive in
> those conditions.

Damn. And to think that I have to lift 14 stone of my dance partner...

That said, my shoulder *does* hurt now! >_<


Post a reply to this message

From: Francois Labreque
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 23 Apr 2012 19:47:47
Message: <4f95ea23$1@news.povray.org>
Le 2012-04-23 09:25, Invisible a écrit :
>>> Nobody gets tendinitis just from using a mouse.
>>
>> I have two weeks off work, 10 physiotherapy sessions and a visit from an
>> occupational therapist at home to redesign my work space that disagree
>> with you.
>
> OK. So maybe you had the desk at the wrong height or something? IDK.
> I've been using a mouse since I was 12, sometimes staying up to program
> until 2 in the morning, and it hasn't caused my any trouble.

It wasn't a problem for me either until I had to do it 40 hours straight...

>
> FWIW, I also play keyboard, where you have to constantly support the
> entire weight of your arm all the time. And I played violin for years...
>

That's probably it, your shoulder muscles are trained.

>> When you need to use the mouse with your right hand, you need to lift
>> your arm over the numeric keypad and off to the side to grab the mouse,
>> then move the arm back to the keyboard so that your can continue typing.
>> In most cases, this means lifting your entire arm from the shoulder on
>> down, whereas if you were using your mouse left-handed, you'd only need
>> to move your wrist, with your elbow still resting on the chair's arm
>> rest.
>
> I usually have an arm rest set up so I only have to lift my forearm, not
> my entire arm, but hey.
>
>> Repeated sporadic use of the mouse over the course of two long mights
>> and days of work did cause me to have tendinitis bad enough that I had
>> to be driven to the hospital since I could no longer lift my right arm
>> at the shoulder, and it would have been too dangerous to try to drive in
>> those conditions.
>
> Damn. And to think that I have to lift 14 stone of my dance partner...
>
> That said, my shoulder *does* hurt now! >_<

Not for 40 hrs straight...;)

-- 
/*Francois Labreque*/#local a=x+y;#local b=x+a;#local c=a+b;#macro P(F//
/*    flabreque    */L)polygon{5,F,F+z,L+z,L,F pigment{rgb 9}}#end union
/*        @        */{P(0,a)P(a,b)P(b,c)P(2*a,2*b)P(2*b,b+c)P(b+c,<2,3>)
/*   gmail.com     */}camera{orthographic location<6,1.25,-6>look_at a }


Post a reply to this message

From: Le Forgeron
Subject: Re: Days 5-
Date: 24 Apr 2012 03:07:43
Message: <4f96513f$1@news.povray.org>
Le 21/04/2012 05:43, Darren New a écrit :
> 
> I don't think mis-matched declarations were ever something that C
> worried about. Does C++ actually check that sort of thing now?

The mangling pattern/scheme of C++ for function's name uses a lot of the
signature: the namespace, the name itself and the description of the
arguments' types. A bit more than C with its double underscores.

As we are talking of template, I would think the code would be
duplicated anyway in the many files: templates are most probably inline
(if you use 1 of 13 templates, your code only get the one you used).

-- 
Software is like dirt - it costs time and money to change it and move it
around.

Just because you can't see it, it doesn't weigh anything,
and you can't drill a hole in it and stick a rivet into it doesn't mean
it's free.


Post a reply to this message

From: Invisible
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 24 Apr 2012 03:56:09
Message: <4f965c99$1@news.povray.org>
>> Damn. And to think that I have to lift 14 stone of my dance partner...
>>
>> That said, my shoulder *does* hurt now! >_<
>
> Not for 40 hrs straight...;)

Christ, 40 *seconds* straight is enough to wipe me out. o_O

I'm such a weed...


Post a reply to this message

From: Invisible
Subject: Re: Day 6
Date: 24 Apr 2012 04:11:57
Message: <4f96604d@news.povray.org>
On 20/04/2012 02:03 PM, Invisible wrote:
> On 20/04/2012 01:36 PM, Warp wrote:
>> Orchid Win7 v1<voi### [at] devnull> wrote:
>>> On the other hand, it appears to be aimed at people who already know the
>>> C++ language. That isn't really me, yet. I know some of the syntax, but
>>> certainly not all of it, or what all of it actually does.
>>
>> I think you'll learn on the fly (at least if you have the right
>> attitude).
>
> Given that I already some some clue about C++, that might actually work...

You know what? I'm just going to /buy/ the book. In the unlikely event 
that it actually helps me to get a better job, it will have easily paid 
for itself multiple times over.


Post a reply to this message

From: Darren New
Subject: Re: Days 1-5
Date: 25 Apr 2012 01:16:09
Message: <4f978899$1@news.povray.org>
On 4/23/2012 1:08, Invisible wrote:
> a valid operator that you can put anywhere you want...

It has to be between two other arguments, and you can't write a naked comma 
operator in the middle of a function's arguments, because commas separate 
function arguments. So you'd still get a compiler error.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Days 5-
Date: 25 Apr 2012 01:17:19
Message: <4f9788df@news.povray.org>
On 4/24/2012 0:07, Le_Forgeron wrote:
> The mangling pattern/scheme of C++ for function's name

Ah yes.  I had forgotten about that.

-
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Days 5-
Date: 25 Apr 2012 01:22:54
Message: <4f978a2e@news.povray.org>
On 4/23/2012 1:31, Invisible wrote:
> Damn... I'm trying to think of something you can code without actually using
> recursion. Hmm. Well, I guess there must be /something/...

Almost all business logic. I don't remember seeing any recursion in any 
operating system kernels I've read. I can't think of any recursive SQL code 
I've written at all.

> So if you want to count how many nodes there are in a binary tree, how do
> you do that non-recursively?

You use a queue. Each node you visit, you tack on to the end of the queue to 
be counted, and you go until the queue is empty.

Alternately, manually maintain the stack. Which is not "recursion" in the C 
sense, because you can actually tell without just blasting memory in unknown 
ways when you run out of room for the stack.

> If a programming language supports calling /any/ foreign language, that
> language will always be C. It will know about standard C types, it will
> usually know about C structs, and it will let you call arbitrary C functions.

OK. Yes, as long as you link to the proper C calling convention.

> And yet, the way that you call a C function is, apparently, undefined.

It's implementation-defined. You have to read the compiler manual (or source 
code) to know what the sequence is. And different functions in the same code 
can have different calling conventions.

Unless you have a CPU that actually enforces calling conventions.

> It also makes me wonder how the heck it's possible to take object code from
> multiple C compilers and link it all together, if each of them is
> potentially using a completely different calling convention. It sounds like
> it shouldn't work.

And indeed it doesn't. Try compiling one library with gcc and another with 
visual C and see if they link cleanly. Take a library off the mac and link 
it to a Windows-compiled main().

For that matter, try compiling one program for x86 and the other for x64.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 25 Apr 2012 01:23:47
Message: <4f978a63$1@news.povray.org>
On 4/23/2012 0:59, Invisible wrote:
>>> I think it's probably vacuous to try to estimate how "useful" it would be
>>> without actually trying it...
>>
>> Well, they tried making STM work on .NET and gave up because of all the
>> state, if you remember.
>
> They gave up because they tried to make all the existing state mutation
> stuff still work in the presence of transactions, which is /obviously/
> impossible.

That's my point.  How useful would it be if you couldn't actually use any of 
the other .NET libraries, including even I/O, reflection, etc.?

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Invisible
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 25 Apr 2012 04:12:35
Message: <4f97b1f3$1@news.povray.org>
>>> Well, they tried making STM work on .NET and gave up because of all the
>>> state, if you remember.
>>
>> They gave up because they tried to make all the existing state mutation
>> stuff still work in the presence of transactions, which is /obviously/
>> impossible.
>
> That's my point. How useful would it be if you couldn't actually use any
> of the other .NET libraries, including even I/O, reflection, etc.?

You do all of that stuff from /outside/ your transactions, that's all. 
Remember, transactions are only for thread communication. You start a 
transaction, fetch the next work item from the shared work queue, and 
the transaction. Then you process the work item, calling whatever 
libraries you need. Simples.


Post a reply to this message

From: Invisible
Subject: Re: Days 5-
Date: 25 Apr 2012 04:22:26
Message: <4f97b442$1@news.povray.org>
On 25/04/2012 06:22 AM, Darren New wrote:
> On 4/23/2012 1:31, Invisible wrote:
>> Damn... I'm trying to think of something you can code without actually
>> using recursion. Hmm. Well, I guess there must be /something/...
>
> Almost all business logic.

I suppose I should consider myself lucky that I'm never going to be 
writing anything like that.

> I don't remember seeing any recursion in any
> operating system kernels I've read.

Really? That's surprising. No recursive sorting algorithms for balancing 
the B*-trees that the directory nodes use, or for sorting the ready 
thread list by priority?

> I can't think of any recursive SQL code I've written at all.

SQL is a rather special-purpose language. I'm not sure it even 
/supports/ recursion...

>> So if you want to count how many nodes there are in a binary tree, how do
>> you do that non-recursively?
>
> You use a queue. Each node you visit, you tack on to the end of the
> queue to be counted, and you go until the queue is empty.

In other words, you manually implement the stack.

Tell me, in what way does this prevent you running out of stack?

>> And yet, the way that you call a C function is, apparently, undefined.
>
> It's implementation-defined. You have to read the compiler manual (or
> source code) to know what the sequence is. And different functions in
> the same code can have different calling conventions.
>
> Unless you have a CPU that actually enforces calling conventions.

So... how is it ever possible to statically link software?

>> It sounds like it shouldn't work.
>
> And indeed it doesn't. Try compiling one library with gcc and another
> with visual C and see if they link cleanly.

It's news to me that this /doesn't/ work.

I mean, if every compiler uses its own random calling convention, then 
how /the hell/ is it possible to write some C, link it against GMP, 
wxWidgets and the OS header files, and get a usable binary? You know, 
given that you have no idea which compiler these libraries are compiled 
with...

> Take a library off the mac and link it to a Windows-compiled main().

Yeah, well, one is going to be an ELF object, and the other will be a PE 
module. You won't even be able to find a linker program that understands 
both file formats. :-P That has nothing to do with whether the machine 
code within those files would work if you linked it together.

> For that matter, try compiling one program for x86 and the other for x64.

There's absolutely no reason to expect binaries for different 
architectures to work together.

I would, however, expect that on any given architecture, the C calling 
convention is always the same.


Post a reply to this message

From: Warp
Subject: Re: Day 6
Date: 25 Apr 2012 07:59:59
Message: <4f97e73f@news.povray.org>
Invisible <voi### [at] devnull> wrote:
> You know what? I'm just going to /buy/ the book.

  I'd recommend getting both of them. (Of course you could buy the
"Effective C++" first, and if you like it, buy "More Effective C++"
later.)

-- 
                                                          - Warp


Post a reply to this message

From: Francois Labreque
Subject: Re: Days 5-
Date: 25 Apr 2012 08:25:24
Message: <4f97ed34$1@news.povray.org>
Le 2012-04-25 04:22, Invisible a écrit :
> On 25/04/2012 06:22 AM, Darren New wrote:
>> On 4/23/2012 1:31, Invisible wrote:
>>> Damn... I'm trying to think of something you can code without actually
>>> using recursion. Hmm. Well, I guess there must be /something/...
>>
>> Almost all business logic.
>
> I suppose I should consider myself lucky that I'm never going to be
> writing anything like that.

Why not?  Didn't you rewrite the code to compile your danse tournament 
rankings?  I know you only did it for yourself, but that was business 
logic, even if you weren't using WebSphere, J2EE, Weblogic or some big 
platform like that.

>
>>> And yet, the way that you call a C function is, apparently, undefined.
>>
>> It's implementation-defined. You have to read the compiler manual (or
>> source code) to know what the sequence is. And different functions in
>> the same code can have different calling conventions.
>>
>> Unless you have a CPU that actually enforces calling conventions.
>
> So... how is it ever possible to statically link software?
>

You have to take extra steps to make sure it works.  For example, back 
in the days of Windows 3.1, you had to use the Pascal calling convention 
for your functions in order to make sure that they could interact with 
other modules.  (Maybe it's still that way, I haven't touched a C 
program in 15 years.)

-- 
/*Francois Labreque*/#local a=x+y;#local b=x+a;#local c=a+b;#macro P(F//
/*    flabreque    */L)polygon{5,F,F+z,L+z,L,F pigment{rgb 9}}#end union
/*        @        */{P(0,a)P(a,b)P(b,c)P(2*a,2*b)P(2*b,b+c)P(b+c,<2,3>)
/*   gmail.com     */}camera{orthographic location<6,1.25,-6>look_at a }


Post a reply to this message

From: Invisible
Subject: Re: Day 6
Date: 25 Apr 2012 09:08:24
Message: <4f97f748$1@news.povray.org>
On 25/04/2012 12:59 PM, Warp wrote:
> Invisible<voi### [at] devnull>  wrote:
>> You know what? I'm just going to /buy/ the book.
>
>    I'd recommend getting both of them. (Of course you could buy the
> "Effective C++" first, and if you like it, buy "More Effective C++"
> later.)

I think I can actually buy the pair for a lower price... (Amazon likes 
to do that.)

Gotta love how Amazon screwed me over, and I was all pissed about it, 
and now here I am giving them my money again.


Post a reply to this message

From: Invisible
Subject: Re: Days 5-
Date: 25 Apr 2012 09:12:30
Message: <4f97f83e$1@news.povray.org>
>>> Almost all business logic.
>>
>> I suppose I should consider myself lucky that I'm never going to be
>> writing anything like that.
>
> Why not? Didn't you rewrite the code to compile your danse tournament
> rankings?

I did not "rewrite" anything. I merely wrote a program that downloads 
some web pages and attempts to extract the raw data from them. And that 
is all.

(The organiser's website is obnoxiously difficult to navigate. 
Fortunately I was able to reverse-engineer how the URLs are generated...)

> I know you only did it for yourself, but that was business
> logic, even if you weren't using WebSphere, J2EE, Weblogic or some big
> platform like that.

OK.

>> So... how is it ever possible to statically link software?
>
> You have to take extra steps to make sure it works.

Really?

> For example, back in
> the days of Windows 3.1, you had to use the Pascal calling convention
> for your functions in order to make sure that they could interact with
> other modules. (Maybe it's still that way, I haven't touched a C program
> in 15 years.)

So what you're saying is "the C calling convention is undefined, but the 
OS calling convention is not"?


Post a reply to this message

From: Francois Labreque
Subject: Re: Days 5-
Date: 25 Apr 2012 10:25:33
Message: <4f98095d$1@news.povray.org>
Le 2012-04-25 09:12, Invisible a écrit :
>>> So... how is it ever possible to statically link software?
>>
>> You have to take extra steps to make sure it works.
>
> Really?
>

Yes.  For example: Miocrsoft dictating that all Windows applications and 
DLLs must use the Pascal calling convention.

(I know DLLs are not statically linked... but you get my drift.  If you 
want to use library XYZ, you need to use the same calling convention as 
library X uses.

>> For example, back in
>> the days of Windows 3.1, you had to use the Pascal calling convention
>> for your functions in order to make sure that they could interact with
>> other modules. (Maybe it's still that way, I haven't touched a C program
>> in 15 years.)
>
> So what you're saying is "the C calling convention is undefined, but the
> OS calling convention is not"?

No.  I'm saying - as Darren pointed out - that the C calling convention 
is not undefined, but implementation-defined.  There's a difference.

Division by zero = undefined.
Number of bits in an integer = implementation-defined.

-- 
/*Francois Labreque*/#local a=x+y;#local b=x+a;#local c=a+b;#macro P(F//
/*    flabreque    */L)polygon{5,F,F+z,L+z,L,F pigment{rgb 9}}#end union
/*        @        */{P(0,a)P(a,b)P(b,c)P(2*a,2*b)P(2*b,b+c)P(b+c,<2,3>)
/*   gmail.com     */}camera{orthographic location<6,1.25,-6>look_at a }


Post a reply to this message

From: Darren New
Subject: Re: Days 5-
Date: 25 Apr 2012 23:33:45
Message: <4f98c219$1@news.povray.org>
On 4/25/2012 1:22, Invisible wrote:
> Really? That's surprising. No recursive sorting algorithms for balancing the
> B*-trees that the directory nodes use, or for sorting the ready thread list
> by priority?

If you can limit the recursion a priori, then sure. If you know you'll only 
have at most 4 levels of tree, or only 128 entries in the list to sort, or 
something like that, recursion is fine. I wouldn't write production code to 
manipulate an arbitrary data structure with actual machine-stack-based 
recursion in C.

> SQL is a rather special-purpose language. I'm not sure it even /supports/
> recursion...

That's kind of my point.

> In other words, you manually implement the stack.

Yes.

> Tell me, in what way does this prevent you running out of stack?

It doesn't. It just keeps you from running out of stack without knowing it.

If your language runtime already supplies that service (e.g., C# throwing an 
exception when it runs out of stack or something) then recursive algorithms 
are fine.

>> Unless you have a CPU that actually enforces calling conventions.
> So... how is it ever possible to statically link software?

You appear to be having a hard time distinguishing "it's 
implemention-defined and not specified in the standard' from "we don't know 
what it is, ever."

> I mean, if every compiler uses its own random calling convention,

It doesn't.

> then how
> /the hell/ is it possible to write some C, link it against GMP, wxWidgets
> and the OS header files, and get a usable binary? You know, given that you
> have no idea which compiler these libraries are compiled with...

Because sometimes the OS defines the calling convention to be used.

> I would, however, expect that on any given architecture, the C calling
> convention is always the same.

In spite of the page I pointed you to showing all the different calling 
conventions used by the x86 line, right?

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 25 Apr 2012 23:36:36
Message: <4f98c2c4$1@news.povray.org>
On 4/25/2012 1:12, Invisible wrote:
> You do all of that stuff from /outside/ your transactions, that's all.

Except that .NET is about components, so that doesn't work out too well.

And if you're talking about putting Haskell on .NET, then your entire 
program becomes one "transaction". (Note we've moved to talking about STM 
from talking about Haskell, which was not my intention. It was an analogy.)

> Remember, transactions are only for thread communication. You start a
> transaction, fetch the next work item from the shared work queue, and the
> transaction. Then you process the work item, calling whatever libraries you
> need. Simples.

And if the work item is in a class written that does I/O to obtain it, or to 
log a message, or etc etc etc?

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Invisible
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 26 Apr 2012 04:13:42
Message: <4f9903b6$1@news.povray.org>
On 26/04/2012 04:36 AM, Darren New wrote:
> On 4/25/2012 1:12, Invisible wrote:
>> You do all of that stuff from /outside/ your transactions, that's all.
>
> Except that .NET is about components, so that doesn't work out too well.
>
> And if you're talking about putting Haskell on .NET, then your entire
> program becomes one "transaction".

How so?

> (Note we've moved to talking about
> STM from talking about Haskell, which was not my intention. It was an
> analogy.)

OK. And I was just saying that Haskell /already/ lets you use libraries 
written in C, which aren't functional at all. I don't see why using the 
.NET libraries would be any harder. [Assuming you solve the problem of 
how to make your program run on the CLR in the first place, obviously.]

>> Remember, transactions are only for thread communication. You start a
>> transaction, fetch the next work item from the shared work queue, and the
>> transaction. Then you process the work item, calling whatever
>> libraries you need.
>
> And if the work item is in a class written that does I/O to obtain it,
> or to log a message, or etc etc etc?

I am really bad at typing, aren't I? :-S

What I /meant/ to write was that you start a transaction, fetch the next 
work item, and then end the transaction. Once the transaction is over, 
you can do as much I/O as you like.

The problem (I assume) that you're talking about is that all the 
existing .NET stuff is structured under the assumption that you can do 
I/O whenever you feel like it. I can see a few ways to approach that. 
(Perhaps the simplest possibility being "only Haskell is allows to use 
STM". :-P )


Post a reply to this message

From: Warp
Subject: Re: Days 5-
Date: 26 Apr 2012 08:09:56
Message: <4f993b14@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> If you can limit the recursion a priori, then sure. If you know you'll only 
> have at most 4 levels of tree, or only 128 entries in the list to sort, or 
> something like that, recursion is fine. I wouldn't write production code to 
> manipulate an arbitrary data structure with actual machine-stack-based 
> recursion in C.

  Very usually the recursion depth of a typical recursive algorithm is
O(log n). This means that the computer wouldn't be able to hold as much
data as to make you run out of stack space when running the recursive
algorithm on it. (For example, if the recursion depth is 50, that means
that there's about 10^15 elements of data. Even if each element took just
one single byte, that would be like 1024 terabytes of RAM.)

-- 
                                                          - Warp


Post a reply to this message

From: Darren New
Subject: Re: Days 5-
Date: 27 Apr 2012 20:38:17
Message: <4f9b3bf9$1@news.povray.org>
On 4/26/2012 5:09, Warp wrote:
>    Very usually the recursion depth of a typical recursive algorithm is
> O(log n). This means that the computer wouldn't be able to hold as much
> data as to make you run out of stack space when running the recursive
> algorithm on it.

Assuming that you're not writing a library that might invoke you 40 levels down.

That said, I've found I rarely need it, and that the undefined behavior 
isn't worth the risks. YMMV. If you can handle the program crashing when you 
give it too much data in a way that generates bogus results, then sure, feel 
free. :-)  (I'm not being sarcastic - there are lots of programs like that.)

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 27 Apr 2012 20:40:58
Message: <4f9b3c9a@news.povray.org>
On 4/26/2012 1:13, Invisible wrote:
> OK. And I was just saying that Haskell /already/ lets you use libraries
> written in C, which aren't functional at all.

And can the C call back into the Haskell? And if so, are all the Haskell 
invariants and such maintained? And can you do that without telling the 
caller whether they're calling C or compiled Haskell?

> What I /meant/ to write was that you start a transaction, fetch the next
> work item, and then end the transaction. Once the transaction is over, you
> can do as much I/O as you like.

Right. But if "fetch the transaction" means "obtain it from the server over 
there using TCP/IP", then you're kind of screwed, aren't you?

Heck, even a regular expression match isn't functional in .NET.

> The problem (I assume) that you're talking about is that all the existing
> .NET stuff is structured under the assumption that you can do I/O whenever
> you feel like it. I can see a few ways to approach that. (Perhaps the
> simplest possibility being "only Haskell is allows to use STM". :-P )

And that's the kind of incompatibility I'm saying makes .NET much less useful.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Warp
Subject: Re: Days 5-
Date: 28 Apr 2012 04:33:05
Message: <4f9bab41@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> That said, I've found I rarely need it

  It's not usual to need it, but sometimes it can be quite useful.
Almost anything involving things like permutations and combinations
are significantly easier to express recursively than iteratively.

> If you can handle the program crashing when you 
> give it too much data in a way that generates bogus results, then sure, feel 
> free. :-)

  As I said, if the recursion depth is O(log n), then you *can't* give it
so much data as for the stack space to run out. It's physically impossible.

  If your recursion level is O(n), then it sounds a lot like an iterative
algorithm that has been expressed recursively for no good reason. (Of
course exceptions probably exist, but are rare.)

-- 
                                                          - Warp


Post a reply to this message

From: Orchid Win7 v1
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 28 Apr 2012 05:56:16
Message: <4f9bbec0$1@news.povray.org>
>> OK. And I was just saying that Haskell /already/ lets you use libraries
>> written in C, which aren't functional at all.
>
> And can the C call back into the Haskell?

Yes. I demonstrated using the C sort() function to sort Haskell data, 
remember?

> And if so, are all the Haskell invariants and such maintained?

You have to tell the compiler whether or not you consider the C function 
to be "pure" or not. Obviously, you can lie. Don't do that.

> And can you do that without telling the
> caller whether they're calling C or compiled Haskell?

Does sort() know what it's calling?

>> What I /meant/ to write was that you start a transaction, fetch the next
>> work item, and then end the transaction. Once the transaction is over,
>> you can do as much I/O as you like.
>
> Right. But if "fetch the transaction" means "obtain it from the server
> over there using TCP/IP", then you're kind of screwed, aren't you?

Yeah. STM only works for stuff local to one machine.

Or rather, the implementations I've seen only work local to one machine. 
It's quite plausible you could extend it so that the transactional data 
you're mutating might be remote - but them it would be the STM engine 
sending network traffic, not you.

> Heck, even a regular expression match isn't functional in .NET.

Probably. In fact, I doubt much of the .NET libraries are. So you would 
probably end up using existing Haskell libraries for anything except 
actual I/O - the thing that .NET is good at.

>> The problem (I assume) that you're talking about is that all the existing
>> .NET stuff is structured under the assumption that you can do I/O
>> whenever
>> you feel like it. I can see a few ways to approach that. (Perhaps the
>> simplest possibility being "only Haskell is allows to use STM". :-P )
>
> And that's the kind of incompatibility I'm saying makes .NET much less
> useful.

Certainly it makes it less useful, yes. Whether it makes it "not worth 
it at all" is more open to debate.


Post a reply to this message

From: Darren New
Subject: Re: Days 5-
Date: 28 Apr 2012 12:39:29
Message: <4f9c1d41$1@news.povray.org>
On 4/28/2012 1:33, Warp wrote:
> Darren New<dne### [at] sanrrcom>  wrote:
>> That said, I've found I rarely need it
>
>    It's not usual to need it, but sometimes it can be quite useful.
> Almost anything involving things like permutations and combinations
> are significantly easier to express recursively than iteratively.

Fair enough. That said, you can usually tell by looking at the input 
structure how deeply you'll likely need to recurse for something like that.

>> If you can handle the program crashing when you
>> give it too much data in a way that generates bogus results, then sure, feel
>> free. :-)
>
>    As I said, if the recursion depth is O(log n), then you *can't* give it
> so much data as for the stack space to run out. It's physically impossible.

Oh? How deep is your stack? Are you sure your on-the-heap data structure 
hasn't used up all your potential stack space?

The point is not that if the algorithm is all you're doing, you won't run 
out of stack space. The point is that you don't know how much stack depth 
you have, what's on the stack above you, or how big your data structure is, 
even assuming you're recursing due to a data structure.

Or how much stack space the thing you're calling during the recursion takes, 
if your recursion is part of a more generic data structure. If you say 
"process each node of the DOM with this lambda", you don't know what that 
lambda is going to do.

Why does C++ limit the depth of template instantiation required to 17 
levels, or whatever it is? Clearly, it's possible to run out of stack doing 
recursion.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 28 Apr 2012 12:43:47
Message: <4f9c1e43$1@news.povray.org>
On 4/28/2012 2:56, Orchid Win7 v1 wrote:
> You have to tell the compiler whether or not you consider the C function to
> be "pure" or not. Obviously, you can lie. Don't do that.

Fair enough.

>> And can you do that without telling the
>> caller whether they're calling C or compiled Haskell?
>
> Does sort() know what it's calling?

I don't know. That's why I'm asking. :-)

>> Heck, even a regular expression match isn't functional in .NET.
>
> Probably. In fact, I doubt much of the .NET libraries are. So you would
> probably end up using existing Haskell libraries for anything except actual
> I/O - the thing that .NET is good at.

I think .NET is good at more than just I/O. :-) Actually, I don't think .NET 
is any better at I/O that anything else on Windows is.

>> And that's the kind of incompatibility I'm saying makes .NET much less
>> useful.
>
> Certainly it makes it less useful, yes. Whether it makes it "not worth it at
> all" is more open to debate.

It breaks a fundamental tenet of .NET, which is that it doesn't matter what 
language the caller is written in vs the callee. MS saying that "yes, this 
.NET library works, but only if you call it from Haskell and not C# or VB or 
F#" would not fly well.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Warp
Subject: Re: Days 5-
Date: 28 Apr 2012 12:52:23
Message: <4f9c2047@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> >    As I said, if the recursion depth is O(log n), then you *can't* give it
> > so much data as for the stack space to run out. It's physically impossible.

> Oh? How deep is your stack? Are you sure your on-the-heap data structure 
> hasn't used up all your potential stack space?

  As I said, if your recursion depth is O(log n), then you would need a
ridiculous amount of data in order to run out of stack space even with
a very stack-hungry recursive function. (For example, if your recursion
level were 50, then the input data, even if it took just 1 byte per element,
would require something like 1024 terabytes of RAM. How likely are you going
to run out of stack space with that few recursion levels? You could easily
have that many function calls on the stack even without recursion.)

  It's highly unusual to require enormous amounts of stack on one single
function call, especially if you are implementing a recursive algorithm.
If each function call takes exponentially more stack space than there's
input, you are doing something wrong. (And even if you did, your algorithm
would be quite slow, as each function call would be operating on a rather
large amount of local data.)

> Why does C++ limit the depth of template instantiation required to 17 
> levels, or whatever it is?

  Never heard of such a limit.

-- 
                                                          - Warp


Post a reply to this message

From: Darren New
Subject: Re: Days 5-
Date: 28 Apr 2012 12:57:43
Message: <4f9c2187$1@news.povray.org>
On 4/28/2012 9:52, Warp wrote:
> level were 50,

I understand your argument. I'm unconvinced that you're (a) not already 40 
levels of stack deep when you get invoked, and (b) know what your stack 
recursion depth can be.

Maybe I'm just used to working on machines with actual limited address space 
and RAM. 50 levels of recursion sounds like a lot of stack space used, to me.

 >   It's highly unusual to require enormous amounts of stack on one single
function call,

I would think that depends on the program. If you're making an image of your 
input data for each level, you're screwed, which is why people tend not to 
do that sort of thing. If (maybe) you're parsing a programming language, I 
can see each level having a fairly large amount of data associated with it.

> would require something like 1024 terabytes of RAM. How likely are you going
> to run out of stack space with that few recursion levels? You could easily
> have that many function calls on the stack even without recursion.)

That's my point! :-)

>> Why does C++ limit the depth of template instantiation required to 17
>> levels, or whatever it is?
>
>    Never heard of such a limit.

IIRC, template function nesting is only required to be supported to some 
realtively small depth.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Warp
Subject: Re: Days 5-
Date: 28 Apr 2012 13:14:11
Message: <4f9c2563@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> On 4/28/2012 9:52, Warp wrote:
> > level were 50,

> I understand your argument. I'm unconvinced that you're (a) not already 40 
> levels of stack deep when you get invoked, and (b) know what your stack 
> recursion depth can be.

  My point is that you are not going to get even close to 50. Perhaps
something like 20.

  If your stack can't hold hundreds of recursive function calls, then
you should upgrade your computer to the new millenium.

> Maybe I'm just used to working on machines with actual limited address space 
> and RAM. 50 levels of recursion sounds like a lot of stack space used, to me.

  What? Even if each function call took like a kilobyte of space (which is
quite a lot for one single function call), it would still be just 50 kB.
I think stack sizes are counted in megabytes in modern systems.

>  >   It's highly unusual to require enormous amounts of stack on one single
> function call,

> I would think that depends on the program. If you're making an image of your 
> input data for each level, you're

doing it wrong. (If for nothing else, then because it increases the
computational complexity of your algorithm by a factor of n, which is quite
a lot. Eg. a fast O(n log n) algorithm becomes a crawling O(n^2 log n).
Not to talk about if the original algorithm was eg. O(n^2) to begin with...)

> >> Why does C++ limit the depth of template instantiation required to 17
> >> levels, or whatever it is?
> >
> >    Never heard of such a limit.

> IIRC, template function nesting is only required to be supported to some 
> realtively small depth.

  I suppose the standard probably as a minimum recommended amount (like
it has for many other things, like the length of variable names). However,
if you surpass that limit your program won't even compile, so it's not
a question of running out of memory when running the program. (And most
C++ compilers have an option to increase the space dedicated to type
names.)

  Consider that some projects use template metaprogramming quite
extensively, and the internal type names that result from it can be
quite large (we are talking about thousands and thousands of characters).
Most C++ programs don't use type names that long.

-- 
                                                          - Warp


Post a reply to this message

From: Darren New
Subject: Re: Days 5-
Date: 28 Apr 2012 13:38:55
Message: <4f9c2b2f$1@news.povray.org>
On 4/28/2012 10:14, Warp wrote:
>    If your stack can't hold hundreds of recursive function calls, then
> you should upgrade your computer to the new millenium.

Well, that's what I said. If I have a machine with enough power to support 
that sort of thing, I'm probably not going to be using C. :-)

PS: Pro-tip. I work for google. Don't try to spider the web recursively. ;-) 
As the machines get bigger, so do the problems people throw at them.

But you have a database with a B-Tree index? Sure, chances are you're not 
going to blow the stack walking down that tree.

I'm not saying recursion isn't useful. I'm saying that one must keep in mind 
the possible depth of recursion, because C doesn't tell you when you overrun 
the stack. You just get the same random errors you get when you run off the 
end of an array, except you haven't actually violated the spec, as far as I 
know.

>> Maybe I'm just used to working on machines with actual limited address space
>> and RAM. 50 levels of recursion sounds like a lot of stack space used, to me.
>
>    What? Even if each function call took like a kilobyte of space (which is
> quite a lot for one single function call), it would still be just 50 kB.
> I think stack sizes are counted in megabytes in modern systems.

Depends on the system. Credit card terminal? No. Last card terminal I worked 
on had 14K of space free for code and data and stack. :-)

In any case, would you call malloc() inside each level of recursion as you 
go without checking whether malloc() returned NULL? I wouldn't think so. So 
if malloc() can fail and you want to check, why not recursion? Why not just 
use the returned value from malloc() and let it crash out when you try to 
write to offset 0?

> doing it wrong.

Yep. As I said, that's why people don't do it that way.

Note, however, that we're also comparing to things like Haskell, where the 
"naive recursive algorithm" *is* the iterative algorithm.

>    I suppose the standard probably as a minimum recommended amount (like
> it has for many other things, like the length of variable names). However,
> if you surpass that limit your program won't even compile, so it's not
> a question of running out of memory when running the program. (And most
> C++ compilers have an option to increase the space dedicated to type
> names.)

Yep. All to get around problems with naive recursive algorithms.

In any case, that's the sort of thing I'm talking about. If you add a level 
of template indirection and your compiler crashes, that's one thing. If you 
add another web page to the list of web sites you're selling ads on and your 
revenue stream collapses, that's another thing.

Hope that you don't wind up adding another level to your templates and your 
compiler finishes but generates the incorrect code.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Invisible
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 30 Apr 2012 05:03:13
Message: <4f9e5551$1@news.povray.org>
>>> Heck, even a regular expression match isn't functional in .NET.
>>
>> Probably. In fact, I doubt much of the .NET libraries are. So you would
>> probably end up using existing Haskell libraries for anything except
>> actual I/O - the thing that .NET is good at.
>
> I think .NET is good at more than just I/O. :-) Actually, I don't think
> .NET is any better at I/O that anything else on Windows is.

Well, I haven't ever used .NET, so I couldn't say.

>>> And that's the kind of incompatibility I'm saying makes .NET much less
>>> useful.
>>
>> Certainly it makes it less useful, yes. Whether it makes it "not worth
>> it at
>> all" is more open to debate.
>
> It breaks a fundamental tenet of .NET, which is that it doesn't matter
> what language the caller is written in vs the callee. MS saying that
> "yes, this .NET library works, but only if you call it from Haskell and
> not C# or VB or F#" would not fly well.

Well, another possibility would be "you can use this library, but it's 
up to you to not do any I/O within transactions. If you do, anything 
could happen, and it will be Your Fault."


Post a reply to this message

From: Invisible
Subject: Frege
Date: 9 May 2012 06:33:20
Message: <4faa47f0$1@news.povray.org>
>> When will we see the Haskell# language?
>
> I'm pretty sure the whole .NET bit is too OO to make that useful.There's
> way too much stateful stuff (like I/O) that you'd want to use from .NET
> to make it reasonable to have a purely function .net language.

I've been thinking for years that it would be cool to write a Haskell to 
Java compiler.

Yesterday night, I discovered that somebody has actually done this.

Specifically, there is a compiler which translates a language called 
"Frege" into Java. Frege is basically the same as Haskell, with a few 
tiny syntax changes. The compiler takes your Frege source code and turns 
it into Java source code, which the standard Java compiler then compiles 
as normal.

At the moment, it's all quite experimental. There's basically one person 
maintaining it, and it's still brand new. Documentation is nearly 
non-existent. The compiler is fairly slow, and error reporting leaves a 
lot to be desired. But it /works/.

I wrote 2KB of Frege code. The Frege compiler translated this into 47KB 
of Java code. The Java compiler then translated this into 12 class files 
totalling 30KB. The compilation process took just under 6 seconds.

Of course, the program I wrote is only a simple CLI thing for test 
purposes. The interesting question is "how easily can I use the features 
of Java?"

It looks like it only takes 1 line of code to turn an existing Java 
class into a valid Frege data type. (A data type which Frege then knows 
nothing about.) It takes a further 1 line of code to turn any Java 
method into a valid Frege function. I haven't actually attempted to use 
this yet, but there's some example code showing the creation of a Swing 
GUI from Frege. The example is only 50 lines long.

Clearly I'm going to have to play with this for much, much longer before 
I can say how truly /useful/ it is. It's pretty damned exciting though! :-D


Post a reply to this message

<<< Previous 50 Messages Goto Initial 50 Messages

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.