There are two reasons, the ability to include common code at source level,
rather than using functions, seems appealing.
1. Some common code is used only at the development time for debugging
purpose, and not included in the final version. For example,
----------------------------------------
def fn1(self, testname, params, parentParams, defaultParams):
if params.get('_debug')=='Yes' or parentParams.get('_debug')=='Yes':
pdb.set_trace()
if 'device' in params:
dev = defaultParams['Devices'][params['device']]
else:
dev = defaultParams['Devices'][parentParams['device']]
# dev is used in the function later
# Real code of the funciton fn1.
------------------------------------------
First two lines, pdb.set_trace will not be in the final version.
2. Sometimes, the common code sets a variable (e.g. dev in the example
above). So a macro like textual expansion works better at runtime.
Of course, in Python, I can use a signature changing decorator to solve the
problem (so that I do not have modify the actual function calls). But I have
to go and modify all the fn1, fn2 etc.and change their signature.
For the above reasons, I thought if I can use Leo's functionality to adapt
the code at the source level itself.
Thanks,
-- sudhir
On Thu, Feb 25, 2010 at 2:47 PM, zpcspm <[email protected]> wrote:
> On Feb 25, 9:41 pm, Sudhir Kumar <[email protected]> wrote:
> > I am working with something like the following:
> >
> > + common_code
> > + @thin file1
> > |
> > --- fn1
> > |
> > --- fn2
> > + @thin file2
> > |
> > --- fn3
> > |
> > --- fn4 etc.
> >
> > Is there a way to include the contents of common_code in fn1, fn2
> > etc.wherever needed?
> >
> > Thanks,
> > -- sudhir
>
> If fn1-fn4 and common_code contain code in a certain programming
> language, I would encourage you to make common_code a function and
> just call it in fnx. Clones are cool and very appealing, but I'd say
> their usage makes more sense in templates/markup languages.
>
> --
> You received this message because you are subscribed to the Google Groups
> "leo-editor" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<leo-editor%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/leo-editor?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/leo-editor?hl=en.