Re: Declarations variables, Dim, some guidance please



"Neal Zimm" <nealzimm@xxxxxxxxx> wrote in message
news:AEBDB225-BCB4-4A42-90DF-EF3175949C17@xxxxxxxxxxxxxxxx
> In an application that I'm developing I have dim'd quite a few variables
in
> Declarations. I'll admit some of it is not wanting to take the time to put
> those vars that are used quite often in many macros within the sub
> SubName(var list) parenthesis.
>
> 1) What advice can you offer on the pro's and cons of this technique? All
of
> the application's code is in ONE module.

Personally, I try and keep this to a minimum, as it is always possible that
in a procedure the variable will have a residual value from a previous
procedure, preferring to use arguments. Yes, I know we should always
initialise, but it is too easy to be lazy and rely on the default initial
value.

The pros and the cons are the same things really, they keep the value across
procedures, they have (at least) module scope, and so on, it would depend
upon the application as to whether that is a pro or a con. What I am saying
I guess is that each variablke should be carefully considerred before either
placing in Declarations or a procedure.

> 2) I got 'bitten' when testing a macro where a var called Draw was dim'd
as
> integer in Declarations, had a good value > 0 in prior macros, but was 0
in
> the macro I was testing.
>
> Sure enough, I had dim'd it again, inadvertantly, also as Integer in
the
> macro being tested. Hence the 0 value, I guess. The QUESTION is, why did
I
> NOT get a duplicate Dim error?

Because it is not a duplicate. The first was a module scope variable, the
second was a procedure scope variable, it is quite legitimate to have both.
When you do, when in the procedure with the procedure scope variable will
be the one used, as you experienced.


.



Relevant Pages

  • Re: Declarations variables, Dim, some guidance please
    ... Back when I was starting with VBE it seemed that double declarations ... >> the macro I was testing. ... >> NOT get a duplicate Dim error? ... The first was a module scope variable, ...
    (microsoft.public.excel.programming)
  • Re: Different syntax for declarations.
    ... the docstring is placed after declarations. ... decl-defun would still end up as a macro having the signature ... in spite of the wrapping progn and declaim material. ...
    (comp.lang.lisp)
  • Re: Noob to C++, trying to get syntax, etc.
    ... Declarations and definitions aren't too much different from what they ... > WorldGreeter ... > The console stream object, cout, passes into greetby reference. ... Here's a macro, using some of those stream things: ...
    (comp.lang.cpp)
  • Re: Runtime macros
    ... as a macro rather than a function, and at runtime, the macro could examine ... declarations again (except for those cases where it wouldn't be possible ... ISTM, if there are cases where you as a programmer can know that the first type seen indicates it is always that type that that can only be an artifact of some implementation detail about your whole system, eg harware, or third party code etc. ... called, if this is the first time, check the types of its arguments, put the declarations into the body of its code, compile it and them setf the symbol-function so that next time it just proceeds. ...
    (comp.lang.lisp)
  • Re: GC in Jons raytracing benchmark
    ... Nearly any object created with defstruct or defclass has pointers. ... > I don't know about defclass, but defstruct is a macro that uses cons ... Try DISASSEMBLE in a Common Lisp with a native code compiler. ...
    (comp.lang.lisp)