Functions vs If-Then-Else program flow

For the discussion of Perl, Python, Ruby, and PHP and other interpreted languages.

Re: Functions vs If-Then-Else program flow

Post by thedotmaster on Mon Sep 28, 2009 6:13 pm
([msg=30198]see Re: Functions vs If-Then-Else program flow[/msg])

r-ID wrote:The CPU is responsible for allocating memory (i.e. RAM). Since when?

If a variable isn't local, it's global. doh

You're joking, right? Of course it uses functions. A method is a function! TRUE,
It's a function that's attached to an class. (first time heard such sequence) class funtion is method (you know that), but speaking about class it is better to say method :P

I know any of that programming language better then you do :P


Since always.
Well you seemed to be suggesting there was some other thing in between.
It may be called something different, but it is still a function. It's just an OOP term.

Oh really now, good for you.
Image
User avatar
thedotmaster
Contributor
Contributor
 
Posts: 984
Joined: Sun May 04, 2008 4:39 pm
Location: North West UK
Blog: View Blog (1)


Re: Functions vs If-Then-Else program flow

Post by r-ID on Tue Sep 29, 2009 3:55 am
([msg=30213]see Re: Functions vs If-Then-Else program flow[/msg])

if the cpu is responsible for memory allocation then the mouse is responsible for printing.
learn asm, there is no such instruction as memory allocation.
r-ID
Poster
Poster
 
Posts: 172
Joined: Mon Dec 29, 2008 6:04 pm
Blog: View Blog (0)


Re: Functions vs If-Then-Else program flow

Post by tgoe on Tue Sep 29, 2009 5:37 am
([msg=30215]see Re: Functions vs If-Then-Else program flow[/msg])

Of course there is... MOV, STOS et al
but with asm you might have to write your own memory manager

Anyway, with global/local, there are gray areas:
Code: Select all
#!/usr/bin/env python

num = 10

class MyClass():
    def my_function(self):
        num = 5
   
        def my_tiny_function():
            print(num)
   
        my_tiny_function()


def my_function():
    print(num)

mc = MyClass()
mc.my_function()
my_function()


my_tiny_function() prints 5 even though it has no local variables of its own. It doesn't see the global num.

In C, the two my_function()s above would have to have different names. OOP puts into syntax what C programmers have done all along with prefixes: avoid name clashes.
User avatar
tgoe
Contributor
Contributor
 
Posts: 661
Joined: Sun Sep 28, 2008 2:33 pm
Location: q3dm7
Blog: View Blog (0)


Re: Functions vs If-Then-Else program flow

Post by r-ID on Tue Sep 29, 2009 5:53 am
([msg=30216]see Re: Functions vs If-Then-Else program flow[/msg])

"MOV, STOS et al" what is that? CPU is a stupid thing all it does is calculate, no more, it has few registers eax ebx, a register for pointers to the memory etc. thats all. There are instructions to load/store variables from/to the memory. But since when cpu is responsible for memory allocation?
r-ID
Poster
Poster
 
Posts: 172
Joined: Mon Dec 29, 2008 6:04 pm
Blog: View Blog (0)


Re: Functions vs If-Then-Else program flow

Post by tgoe on Tue Sep 29, 2009 9:12 am
([msg=30225]see Re: Functions vs If-Then-Else program flow[/msg])

Only in reply to there being no instruction for memory allocation... don't you just modify the memory pointer?
User avatar
tgoe
Contributor
Contributor
 
Posts: 661
Joined: Sun Sep 28, 2008 2:33 pm
Location: q3dm7
Blog: View Blog (0)


Re: Functions vs If-Then-Else program flow

Post by r-ID on Tue Sep 29, 2009 10:17 am
([msg=30228]see Re: Functions vs If-Then-Else program flow[/msg])

registers are the fastest variables in computer, its a simple variable, like int a; int b; just it is located in cpu. When you set a value like a = 10; (mov eax,10) it doesn't mean that you are allocating memory, you just change the value (same thing with address registers)

-- Tue Sep 29, 2009 10:25 am --

so doing math is faster when you use asm, because you don't need to read/write variables from/to the memory, you can operate with them quickly in cpu.
r-ID
Poster
Poster
 
Posts: 172
Joined: Mon Dec 29, 2008 6:04 pm
Blog: View Blog (0)


Re: Functions vs If-Then-Else program flow

Post by thedotmaster on Tue Sep 29, 2009 12:30 pm
([msg=30234]see Re: Functions vs If-Then-Else program flow[/msg])

Urm, so how do you suppose that data enters memory? Does it just magically appear there?
Math being faster when you use asm? Not really. Modern high-level language compilers produce asm that is pretty much perfect for basic things like that, asm only becomes far more effective with more complex code.
Registers aren't a variable, they're a storage location.

Come back when you've learnt about the fetch-execute cycle and computer internals, and perhaps you ought to learn Asm - or is it one of the 10 languages that you "know"?
Image
User avatar
thedotmaster
Contributor
Contributor
 
Posts: 984
Joined: Sun May 04, 2008 4:39 pm
Location: North West UK
Blog: View Blog (1)


Re: Functions vs If-Then-Else program flow

Post by r-ID on Tue Sep 29, 2009 1:07 pm
([msg=30238]see Re: Functions vs If-Then-Else program flow[/msg])

"Registers aren't a variable, they're a storage location." Terms... I used comparision with programming variables, ofcource it's not the same variable as you use when you code. doh. But as variable stores value, register stores value.

wow, you made some progress, i'm impressed, have you read a bit? Atleast you do not write crap anymore such as "The CPU is responsible for allocating memory (i.e. RAM)".

And look
"Modern high-level language compilers produce asm that is pretty much perfect for basic things like that, asm only becomes far more effective with more complex code."

This is almost true, almost.

Keep going.
r-ID
Poster
Poster
 
Posts: 172
Joined: Mon Dec 29, 2008 6:04 pm
Blog: View Blog (0)


Re: Functions vs If-Then-Else program flow

Post by thedotmaster on Tue Sep 29, 2009 3:11 pm
([msg=30242]see Re: Functions vs If-Then-Else program flow[/msg])

wow, you made some progress, i'm impressed, have you read a bit? Atleast you do not write crap anymore such as "The CPU is responsible for allocating memory (i.e. RAM)".

No, the CPU is responsible for allocating RAM.
Have you even thought about how data gets stored? As I said before, it doesn't just magically appear.
I suggest reading this: http://richardbowles.tripod.com/durham/ ... .htm#part2

This is almost true, almost.

Erm, no. It is true.

This thread has now been locked as hopefully you'll have seen how idiotic you are being. Perhaps you should read up on your facts next time.
Image
User avatar
thedotmaster
Contributor
Contributor
 
Posts: 984
Joined: Sun May 04, 2008 4:39 pm
Location: North West UK
Blog: View Blog (1)


Previous

Return to Interpreted Languages

Who is online

Users browsing this forum: No registered users and 0 guests