Jump to content



Photo

SubFunctions


  • Please log in to reply
34 replies to this topic

#1 Idea

Idea

    Wayfarer

  • Active Members
  • Pip
  • 59 posts

Posted 08 September 2005 - 02:22 PM

I tried to make a sub function and apparently AutoIt has zero support for subfunctions...

Func a()

Func b()
EndFunc
EndFunc

I'd assume that would work but it doesn't. Please point out how to impliment subfunctions.







#2 GaryFrost

GaryFrost

    I don't need your attitude. I have one of my own

  • Developers
  • 7,854 posts

Posted 08 September 2005 - 02:25 PM

a() b() c() Func a() ; do some code here EndFunc Func b() ; do some other code here EndFunc Func c()   a()   b() EndFunc

Edited by gafrost, 08 September 2005 - 02:26 PM.

SciTE for AutoItDirections for Submitting Standard UDFs

Don't argue with an idiot; people watching may not be able to tell the difference.


#3 Idea

Idea

    Wayfarer

  • Active Members
  • Pip
  • 59 posts

Posted 08 September 2005 - 02:27 PM

a() b() c() Func a() ; do some code here EndFunc Func b() ; do some other code here EndFunc Func c()   a()   b() EndFunc

<{POST_SNAPBACK}>

Yes this is what I've been doing however a and b are NOT subfunctions, they are just other functions! See here: http://www.gentee.com/doc/syntax/subfunc.htm

How can I impliment a true subfuntion..?

#4 Valik

Valik

    Former developer.

  • Active Members
  • PipPipPipPipPipPip
  • 18,879 posts

Posted 08 September 2005 - 02:29 PM

You can't. It's not supported and probably won't be.

#5 Raindancer

Raindancer

    Polymath

  • Active Members
  • PipPipPipPip
  • 229 posts

Posted 08 September 2005 - 02:31 PM

Why would you need Subfunctions if you can have the same result with Functions as privided by gafrost?
Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer

#6 GaryFrost

GaryFrost

    I don't need your attitude. I have one of my own

  • Developers
  • 7,854 posts

Posted 08 September 2005 - 02:31 PM

far as I know not in this scripting language, however why don't you just use a conditional statement that's all that is showing you in that example

for example

a(0) b(1) Func a($i_var)   if $i_var then     return 1   endif   return 0 EndFunc Func b($i_var)   if $i_var then     c()   Endif EndFunc Func c()  ; do some code here EndFunc

SciTE for AutoItDirections for Submitting Standard UDFs

Don't argue with an idiot; people watching may not be able to tell the difference.


#7 Idea

Idea

    Wayfarer

  • Active Members
  • Pip
  • 59 posts

Posted 08 September 2005 - 02:36 PM

far as I know not in this scripting language


Okay well this is my idea, impliment real subfunctions.

Func a()
Func b()
EndFunc
EndFunc

Is way better than being forced into using:
Func a()
b()
EndFunc

Func b()
EndFunc

See the link in my second post for a detailed explination on subfunctions and why using a standard function just is not the same! I am baffeled as to why AutoIt does not have such a simple feature that is so important to a scripting language.

#8 Raindancer

Raindancer

    Polymath

  • Active Members
  • PipPipPipPip
  • 229 posts

Posted 08 September 2005 - 02:38 PM

In my eyes

Func a()
Func b()
EndFunc
EndFunc


Brings only confusion to the code. makes it hard to read...
Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer

#9 Idea

Idea

    Wayfarer

  • Active Members
  • Pip
  • 59 posts

Posted 08 September 2005 - 02:43 PM

In my eyes

Func a()
Func b()
EndFunc
EndFunc
Brings only confusion to the code. makes it hard to read...

<{POST_SNAPBACK}>

All major languages have this essential feature, read the link I posted for insight into why. I don't understand why AutoIt doesn't include it. I would assume the target audience is a bit too low to understand it. ;)

#10 Raindancer

Raindancer

    Polymath

  • Active Members
  • PipPipPipPip
  • 229 posts

Posted 08 September 2005 - 02:57 PM

All major languages have this essential feature, read the link I posted for insight into why. I don't understand why AutoIt doesn't include it. I would assume the target audience is a bit too low to understand it.  ;)

<{POST_SNAPBACK}>

Maybe... :P
Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer

#11 Valik

Valik

    Former developer.

  • Active Members
  • PipPipPipPipPipPip
  • 18,879 posts

Posted 08 September 2005 - 03:13 PM

All major languages have this essential feature, read the link I posted for insight into why. I don't understand why AutoIt doesn't include it. I would assume the target audience is a bit too low to understand it.  ;)

<{POST_SNAPBACK}>

All major languages you say? Hmm, off the top of my head, C, C++, C# don't and I don't think Java does either. Right now those are the primary development languages in the world and none of them do so please stop over-exaggerating the ubiquity of the feature.

I've also stated already that it probably won't be implemented. There is no overwhelming reason. Yes, in some cases it may make code more modular and easier to read since all related code is located under a common item. But there is no real great need for the feature. It doesn't offer tremendous benefits and just adds unnecessary complexity. A function is a function no matter what scope is at and so long as the function can be seen where it needs to be used (Not a problem in AutoIt) then it doesn't matter if that function is at the global scope or local scope. Since it's not possible to implement at the local scope, the global scope will have to serve you.

Also I will point out that the example you link to is horrid. If you want a mini-global scope to use like that, then use a global variable with a highly unique name. The usefulness of sub-functions doesn't stem from them having access to local variables but rather from having functions scoped to where they are used. People should never write code as shown in that example because it's just as bad as using global variables judiciously. It makes the code hard to read and hard to follow.

The ideal usage I've seen for sub-functions is similar to below:
func DoSomething(array theArray) {     sub-function UseElement(array_item theItem)     {         theItem += 250;         theItem &= 0xFFFF // Bitwise and         print(theItem)     }     for (i = 0; i < theArray.Size(); ++i)     {         UseElement(theArray[i])         theArray[i] += random(1000, 9999)         UseElement(theArray[i])     } }
Rather than having to write the function body for UseElement() twice and have to maintain it twice in the event of future modifications, localizing the code into a single sub-function helps ease maintenance. However, this can obviously be done using two global functions. Examples like you linked to should not be done (or can be done with global variables and global functions) and examples like I show can be done with global functions. So there's no great use for having sub-functions.

#12 Nutster

Nutster

    Developer at Large

  • Developers
  • 1,450 posts

Posted 08 September 2005 - 03:52 PM

All major languages have this essential feature, read the link I posted for insight into why. I don't understand why AutoIt doesn't include it. I would assume the target audience is a bit too low to understand it.  ;)

<{POST_SNAPBACK}>

Which major languages support this? Pascal is the only one I know of that does and that feature is not used that often. C, C++, Java, Visual Basic, Perl, AWK, javascript, vbscript, Fortran, Ada, Cobol, AutoIt, etc. do not support nesting function definitions (which is what this feature is usually called). In any language that supports user-defined functions and procedures, including AutoIt, any function can be called from within another function, even recursively (calling a function from within itself), but this is not the same as what you are asking for.

The only reason I can think of to use a feature like this is to hide a function from calls by outside functions. Most of these languages have features to promote that, although AutoIt does not. Any function can be called from any other place, without restriction.

I would hardly call this an essential feature. A confusing one, sure, but actually not that useful.
David NuttallNuttall Computer ConsultingAutoIt allows me to re-invent the wheel so much faster.An Aquarius born during the Age of AquariusI'm off to write a wizard, a wonderful wizard of odd...

#13 /dev/null

/dev/null

    Universalist

  • MVPs
  • 2,946 posts

Posted 08 September 2005 - 05:11 PM

Which major languages support this?  Pascal is the only one I know of that does and that feature is not used that often.  C, C++, Java, Visual Basic, Perl, AWK, javascript, vbscript, Fortran, Ada, Cobol, AutoIt, etc. do not support nesting function definitions (which is what this feature is usually called).  In any language that supports

actually PERL does support a similar feature. It's called private function and it is only available inside the scope where it was defined.

For the rest, I agree with you.

$retval = Calc(5,5); print("value = $retval\n"); sub Calc {     my ($first, $second) = @_;     my $square = sub {         return($_[0] ** 2);     };     return(&$square($first) + &$square($second)); };


PS: Don't be afraid of my post number (666) ;)

Cheers
Kurt

Edited by /dev/null, 08 September 2005 - 05:12 PM.

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

#14 Nutster

Nutster

    Developer at Large

  • Developers
  • 1,450 posts

Posted 08 September 2005 - 07:03 PM

actually PERL does support a similar feature. It's called private function and it is only available inside the scope where it was defined.

For the rest, I agree with you.

Cheers
Kurt

<{POST_SNAPBACK}>

I have taught myself Perl from example scripts and help files and have never used that feature. I still do not think I would use it that often.
David NuttallNuttall Computer ConsultingAutoIt allows me to re-invent the wheel so much faster.An Aquarius born during the Age of AquariusI'm off to write a wizard, a wonderful wizard of odd...

#15 /dev/null

/dev/null

    Universalist

  • MVPs
  • 2,946 posts

Posted 08 September 2005 - 07:26 PM

I have taught myself Perl from example scripts and help files and have never used that feature.  I still do not think I would use it that often.

<{POST_SNAPBACK}>

You're right, that feature ist rarely used and not well known either. But as you know, there are many ways to solve a problem in Perl.....

Cheers
Kurt
__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

#16 Idea

Idea

    Wayfarer

  • Active Members
  • Pip
  • 59 posts

Posted 09 September 2005 - 04:14 PM

All major languages you say?  Hmm, off the top of my head, C, C++, C# don't and I don't think Java does either.  Right now those are the primary development languages in the world and none of them do so please stop over-exaggerating the ubiquity of the feature.

.Net

The feature is a bit too complex for someone like you to understand well, judging by your post. The target audience can't figure out how to use a feature so lets not include it seems to be the mentality of AutoIt development. Anyway I'm moving back to a "real" language, thanks anyway! ;)

#17 Valik

Valik

    Former developer.

  • Active Members
  • PipPipPipPipPipPip
  • 18,879 posts

Posted 09 September 2005 - 05:36 PM

.Net

The feature is a bit too complex for someone like you to understand well, judging by your post. The target audience can't figure out how to use a feature so lets not include it seems to be the mentality of AutoIt development. Anyway I'm moving back to a "real" language, thanks anyway!  ;)

<{POST_SNAPBACK}>

First of all, you are an idiot.

Second, .NET is currently comprised of C++ .NET, C# and VB .NET off the top of my head. The last time I looked, none of those languages supported "sub-functions" so why you mention .NET is beyond me. I'm being generous here, too, and ignoring the fact that .NET is not a language itself but rather a framework.

Third, I fully understand sub-functions, probably better than you do. I've used them in other languages (Lua comes to mind where I use them extensively). So please don't assume that because you are a dumbass that I don't fully comprehend a feature.

Forth, you're an idiot. Wait, I covered that? Well, how about this then. See that little bit next to my name and Nutster's name? See how it says "Developers"? David (Nutster) and I both pretty much iterated the exact same thing in our posts. Quite obviously, we are two of several people who could make your feature happen but we both shot it down for the same reasons without any prior correspondence on the matter. In other words, we didn't mean to say the same thing, but we're both well aware enough of what you ask for to see the same problems in it. So I don't think insulting our intelligence and telling us how to do things is the best way to ever get anything done.

And last, I will show a rare emotion and admit that I feel sorry for whatever community that you find that coincides with your "real" language. You've obviously not got any substance to contribute and while I do relish in the fact that you will be departing so soon after arriving, I do lament in the pain you will inflict to others with your supreme idiocy.

And with that this post has gone full circle so I bid you adieu.

#18 tylo

tylo

    Universalist

  • Developers
  • 280 posts

Posted 09 September 2005 - 08:47 PM

Hehe, this time I actually agree with you Valik. To add something useful here, the language D supports subfunctions, but it's hardly a "major" language, although it is supposed to be the language to supersede C++ in the future. Anyways, the only sensible purpose of using subfunctions I have seen in D, is for doing optimizations a little more elegant, which is hardly an issue in AutoIt.

Edited by tylo, 09 September 2005 - 08:50 PM.

blub

#19 therks

therks

    Witty quote

  • Active Members
  • PipPipPipPipPipPip
  • 2,166 posts

Posted 09 September 2005 - 09:38 PM

PHP kind of supports them...
It allows you to create a function within a function, but the behaviour is weird.

This is right out of their documentation:
<?php function foo() {   function bar()   {     echo "I don't exist until foo() is called.\n";   } } /* We can't call bar() yet    since it doesn't exist. */ foo(); /* Now we can call bar(),    foo()'s processesing has    made it accessible. */ bar(); ?>


#20 /dev/null

/dev/null

    Universalist

  • MVPs
  • 2,946 posts

Posted 09 September 2005 - 10:51 PM

All major languages have this essential feature, read the link I posted for insight into why. I don't understand why AutoIt doesn't include it. I would assume the target audience is a bit too low to understand it.  ;)


Hey "buddy", we are still waiting for an explanation why sub functions are so essential! I really want to learn something. Please be my advisor!

Cheers
Kurt

Edited by /dev/null, 13 September 2005 - 12:06 AM.

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users