)) ... then you only have to change it in one =place (in the function definition), instead of in all the places where =the function is called.Because [function] only outputs the code that is in between =[return]...[/return] you can do all your calculations inside the =[function...] but outside any [return]...[/return].. and then just =output the final results that you do want output.. by putting that final =result inside [return]...[/return][function name=3DfinalResult] [math]a=3D0[/math] this=20 is=20 to mimic a big super long block of code [text]finalResult=3D [math]a=3D[a]+1[/math] [/text] with tons of white space where we do lots of calculations [return][finalResult][/return][/function]--------- On other topics: ----------=20I use [grep] to remove white space in WCS (WebdnaCodeSparker), similar =to how Ken suggested.If you use WCS, you do not have to bother about white space, anywhere. =Just toggle it on or off, site-wide, as desired. (and specifically =introduce white space just at the specific places where you actually =want/need it.)I wish we have true objects and arrays in Webdna.. but .. meanwhile..I would not use [arrayset] & [arrayget]. My limited experimentation of =those tags, a few years ago, made me think they are buggy, not well =thought out, awkward to use, and not ready for prime-time.HTH-Govinda=--Apple-Mail-1--565420559Content-Transfer-Encoding: quoted-printableContent-Type: text/html;charset=us-asciiYay Lawrence! First person to brave posting a webdna =question on stackoverflow (SO)!
If we keep it up, we'll get =our own tag there!
Toby, =hope you don't mind I posted your example code in my reply to Lawrence =there ^^^.
I would have given you direct credit, but then it =might have been confusing to readers on SO.. that were were referencing =a conversation in another =thread.
I'm trying =to understand in which case I should use the [function] or =not.
Lawrence,
I= would say that Ken is right ... that if you do not know you want =something (like a [function]), then better to avoid adding complexity =just because you think you are supposed to do it with complexity). = That will just make life harder.
Growing coding =skills is organic.. they come naturally from just doing; no use forcing =the process.
There are several =reasons to use [function], .. at least these are some =reasons:
1). to make your code easier to =read
2). to make your code easier to =maintain
3). to remove unwanted =white space from your code
4.) to make =your code easier to write
(once you have done the extra =work to set up a bunch of functions to do various tasks, in a =complicated site, then writing new code to use those functions is much =faster/easier! You just call the =functions!)
You can think of =function like an [include].. it effectively lets you put a bunch =of code at one spot in your page.. with just one short line (the =function call).
I like to use functions like that... as an =include... where I often put the function definition even in =the same file (if that function's code is unique to just that page), =...but I put the function definition up at the top of the page, out of =the way, and NOT in the spot where the call to the function is, where it =would make my code harder to read.
It is also =good to use functions like Toby said, as a way to do the same thing over =and over again without writing the same code over and over. That =makes your code easier to maintain. If there is some =change required later (like the client now wants an ordered =list (<ol>) instead of an un-ordered list (<ul>)) ... then =you only have to change it in one place (in the function definition), =instead of in all the places where the function is =called.
Because [function] only outputs the =code that is in between [return]...[/return] you can do all your =calculations inside the [function...] but outside =any [return]...[/return].. and then just output the final results =that you do want output.. by putting that final result =inside [return]...[/return]
[function =name=3DfinalResult]
=[math]a=3D0[/math]
= this
is
= to
mimic
= a
big
= super
long
= block
of
= code
= [text]finalResult=3D
= [math]a=3D[a]+1[/math]
= [/text]
= with
tons
= of
white
= space
where
= we
do
= lots
of
= calculations
=[return][finalResult][/return]
[/function]
--------- On other topics: =----------
I use [grep] to remove white space =in WCS (WebdnaCodeSparker), similar to how Ken suggested.
If =you use WCS, you do not have to bother about white space, anywhere. = Just toggle it on or off, site-wide, as desired. (and =specifically introduce white space just at the specific places where you =actually want/need it.)
I wish we have true =objects and arrays in Webdna.. but .. meanwhile..
I =would not use [arrayset] & [arrayget]. My limited =experimentation of those tags, a few years ago, made me think they are =buggy, not well thought out, awkward to use, and not ready for =prime-time.
HTH
-Govinda
=html>=--Apple-Mail-1--565420559--
Associated Messages, from the most recent to the oldest:
--Apple-Mail-1--565420559Content-Transfer-Encoding: quoted-printableContent-Type: text/plain;charset=us-asciiYay Lawrence! First person to brave posting a webdna question on =stackoverflow (SO)!If we keep it up, we'll get our own tag there!=http://stackoverflow.com/questions/9398280/how-to-use-function-in-webdna/9=399046#9399046Toby, hope you don't mind I posted your example code in my reply to =Lawrence there ^^^.I would have given you direct credit, but then it might have been =confusing to readers on SO.. that were were referencing a conversation =in another thread.> I'm trying to understand in which case I should use the
[function] or =not.Lawrence,=20I would say that Ken is right ... that if you do not know you want =something (like a
[function]), then better to avoid adding complexity =just because you think you are supposed to do it with complexity). That =will just make life harder. =20Growing coding skills is organic.. they come naturally from just doing; =no use forcing the process.There are several reasons to use
[function], .. at least these are some =reasons:1). to make your code easier to read2). to make your code easier to maintain3). to remove unwanted white space from your code4.) to make your code easier to write=20(once you have done the extra work to set up a bunch of =functions to do various tasks, in a complicated site, then writing new =code to use those functions is much faster/easier! You just call the =functions!)You can think of function like an
[include].. it effectively lets you =put a bunch of code at one spot in your page.. with just one short line =(the function call).I like to use functions like that... as an include... where I often put =the function definition even in the same file (if that function's code =is unique to just that page), ...but I put the function definition up at =the top of the page, out of the way, and NOT in the spot where the call =to the function is, where it would make my code harder to read.It is also good to use functions like Toby said, as a way to do the same =thing over and over again without writing the same code over and over. =That makes your code easier to maintain. If there is some change =required later (like the client now wants an ordered list (
) instead =of an un-ordered list ()) ... then you only have to change it in one =place (in the function definition), instead of in all the places where =the function is called.Because [function] only outputs the code that is in between =[return]...[/return] you can do all your calculations inside the =[function...] but outside any [return]...[/return].. and then just =output the final results that you do want output.. by putting that final =result inside [return]...[/return][function name=3DfinalResult] [math]a=3D0[/math] this=20 is=20 to mimic a big super long block of code [text]finalResult=3D [math]a=3D[a]+1[/math] [/text] with tons of white space where we do lots of calculations [return][finalResult][/return][/function]--------- On other topics: ----------=20I use [grep] to remove white space in WCS (WebdnaCodeSparker), similar =to how Ken suggested.If you use WCS, you do not have to bother about white space, anywhere. =Just toggle it on or off, site-wide, as desired. (and specifically =introduce white space just at the specific places where you actually =want/need it.)I wish we have true objects and arrays in Webdna.. but .. meanwhile..I would not use [arrayset] & [arrayget]. My limited experimentation of =those tags, a few years ago, made me think they are buggy, not well =thought out, awkward to use, and not ready for prime-time.HTH-Govinda=--Apple-Mail-1--565420559Content-Transfer-Encoding: quoted-printableContent-Type: text/html;charset=us-asciiYay Lawrence! First person to brave posting a webdna =question on stackoverflow (SO)!
If we keep it up, we'll get =our own tag there!
Toby, =hope you don't mind I posted your example code in my reply to Lawrence =there ^^^.
I would have given you direct credit, but then it =might have been confusing to readers on SO.. that were were referencing =a conversation in another =thread.
I'm trying =to understand in which case I should use the [function] or =not.
Lawrence,
I= would say that Ken is right ... that if you do not know you want =something (like a
[function]), then better to avoid adding complexity =just because you think you are supposed to do it with complexity). = That will just make life harder.
Growing coding =skills is organic.. they come naturally from just doing; no use forcing =the process.
There are several =reasons to use
[function], .. at least these are some =reasons:
1). to make your code easier to =read
2). to make your code easier to =maintain
3). to remove unwanted =white space from your code
4.) to make =your code easier to write
(once you have done the extra =work to set up a bunch of functions to do various tasks, in a =complicated site, then writing new code to use those functions is much =faster/easier! You just call the =functions!)
You can think of =function like an
[include].. it effectively lets you put a bunch =of code at one spot in your page.. with just one short line (the =function call).
I like to use functions like that... as an =include... where I often put the function definition even in =the same file (if that function's code is unique to just that page), =...but I put the function definition up at the top of the page, out of =the way, and NOT in the spot where the call to the function is, where it =would make my code harder to read.
It is also =good to use functions like Toby said, as a way to do the same thing over =and over again without writing the same code over and over. That =makes your code easier to maintain. If there is some =change required later (like the client now wants an ordered =list (<ol>) instead of an un-ordered list (<ul>)) ... then =you only have to change it in one place (in the function definition), =instead of in all the places where the function is =called.
Because
[function] only outputs the =code that is in between
[return]...[/return] you can do all your =calculations inside the [function...] but outside =any
[return]...[/return].. and then just output the final results =that you do want output.. by putting that final result =inside
[return]...[/return]
[function =name=3DfinalResult]
=
[math]a=3D0[/math]
= this
is
= to
mimic
= a
big
= super
long
= block
of
= code
= with
tons
= of
white
= space
where
= we
do
= lots
of
= calculations
[/function]
--------- On other topics: =----------
I use
[grep] to remove white space =in WCS (WebdnaCodeSparker), similar to how Ken suggested.
If =you use WCS, you do not have to bother about white space, anywhere. = Just toggle it on or off, site-wide, as desired. (and =specifically introduce white space just at the specific places where you =actually want/need it.)
I wish we have true =objects and arrays in Webdna.. but .. meanwhile..
I =would not use [arrayset] & [arrayget]. My limited =experimentation of those tags, a few years ago, made me think they are =buggy, not well thought out, awkward to use, and not ready for =prime-time.
HTH
-Govinda
=html>=--Apple-Mail-1--565420559--
Govinda
DOWNLOAD WEBDNA NOW!
Top Articles:
Talk List
The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...
Related Readings:
tcpsend (2001)
Database (2000)
Sorting ip addresses (2002)
Secure server question (1997)
About Include (2001)
Nested tags count question (1997)
RE: [WebDNA] directory protection questions (2008)
Keep away (1997)
shoppingcart reload qty (1997)
Re:2nd WebCatalog2 Feature Request (1996)
'does not contain' operator needed ... (1997)
[shownext max=?] armed (1997)
Not reading code (1997)
shipping help (1998)
Cart Numbers (1997)
searching numbers (1998)
Sort Order on a page search (1997)
Warning Message? (2000)
PCS Frames (1997)
PCS Frames-Default page is solution! (1997)