From: William Bland
Subject: Newbie question on renaming
Date: 
Message-ID: <pan.2004.05.06.22.57.46.544730@abstractnonsense.com>
Hi all,
	When I want to rename a variable in a statically typed language like
Java, I'm pretty lazy about it:  I rename the variable where it's defined,
compile, and then change the name in all the places the compiler tells me
about.  I like knowing that, if it compiled, I found all the places that
needed changing.

Of course I do much prefer dynamic typing, except that now I can't see an
easy way to rename things (search-and-replace doesn't work because I reuse
names sometimes, and often names are substrings of each other).

I guess this is the kind of thing that "refactoring browsers" are meant to
do (guessing because I've never used one).  I wonder how hard it would be
to get Emacs to rename a variable, taking into account scope?

Since we have a built in "parser" in the form of READ one could, of
course, write a Lisp program that renames variables in other Lisp
programs... that's way above my newbie level of Lisp at the moment though.

Am I missing something simple?  How do other people do this kind of thing?

Cheers,
	Bill.
-- 
Dr. William Bland.
It would not be too unfair to any language to refer to Java as a
stripped down Lisp or Smalltalk with a C syntax.   (Ken Anderson).

From: Alan Shutko
Subject: Re: Newbie question on renaming
Date: 
Message-ID: <87y8o5p2ap.fsf@wesley.springies.com>
William Bland <····@abstractnonsense.com> writes:

> I guess this is the kind of thing that "refactoring browsers" are meant to
> do (guessing because I've never used one).  I wonder how hard it would be
> to get Emacs to rename a variable, taking into account scope?

I like it!  You should write it and incorporate it into SLIME!

But I don't frequently find it a problem.  Most of my variables exist
in a very limited scope, inside a function or in a let body.  If it
doesn't, it has a *nice-long-name* which is unique across files or
directories.  So, when changing most variables, I have to change it
across two or three place only.

What you could do, for cases that are more involved than it, are to
use Emacs' mark-defun (C-M-h) or mark-sexp (C-M-SPC) commands, narrow
to the region (C-x n n), then C-M-% to replace things.  You probably
don't reuse a variable for different things within the same scope, right?
I've used this to good effect in many languages.

-- 
Alan Shutko <···@acm.org> - I am the rocks.
I just need enough to tide me over until I need more.
From: ·········@random-state.net
Subject: Re: Newbie question on renaming
Date: 
Message-ID: <c7ejur$9jvdb$2@midnight.cs.hut.fi>
William Bland <····@abstractnonsense.com> wrote:

> Of course I do much prefer dynamic typing, except that now I can't see an
> easy way to rename things (search-and-replace doesn't work because I reuse
> names sometimes, and often names are substrings of each other).

What Alan Shutko said, plus:

CL-USER(1): (defun foo (bar) quux) ; oops, forgot to rename quux -> bar
; in: LAMBDA NIL
;     (SB-INT:NAMED-LAMBDA FOO (BAR) (BLOCK FOO QUUX))
; ==>
;   #'(SB-INT:NAMED-LAMBDA FOO (BAR) (BLOCK FOO QUUX))
; 
; caught STYLE-WARNING:
;   The variable BAR is defined but never used.
;     (BLOCK FOO QUUX)
; 
; caught WARNING:
;   undefined variable: QUUX

; 
; caught WARNING:
;   This variable is undefined:
;   QUUX
; 
; compilation unit finished
;   caught 2 WARNING conditions
;   caught 1 STYLE-WARNING condition

FOO

...as you see, given a nice lisp the compiler is positively noisy about
you forgetting such details. And given a nice development environment like
Slime this noise translates into clickable annotations in the buffer.

Cheers,

  -- Nikodemus
From: William Bland
Subject: Re: Newbie question on renaming
Date: 
Message-ID: <pan.2004.05.07.02.39.24.267088@abstractnonsense.com>
On Fri, 07 May 2004 00:06:51 +0000, nikodemus wrote:

> William Bland <····@abstractnonsense.com> wrote:
> 
>> Of course I do much prefer dynamic typing, except that now I can't see an
>> easy way to rename things (search-and-replace doesn't work because I reuse
>> names sometimes, and often names are substrings of each other).
> 
> What Alan Shutko said, plus:
...
> ...as you see, given a nice lisp the compiler is positively noisy about
> you forgetting such details. And given a nice development environment like
> Slime this noise translates into clickable annotations in the buffer.
> 
> Cheers,
> 
>   -- Nikodemus

Fantastic!  I have to admit (hangs head in shame) I hadn't actually tried
compiling code with misnamed variables - I just assumed that any bugs
wouldn't show up until the code was run.  I'm *very* impressed at this
and, as you point out, it's particularly nice in SLIME.

Thanks also to Alan - good advice and some nice Emacs commands I didn't
know about!

Cheers,
	Bill.
-- 
Dr. William Bland.
It would not be too unfair to any language to refer to Java as a
stripped down Lisp or Smalltalk with a C syntax.   (Ken Anderson).
From: Ivan Toshkov
Subject: Re: Newbie question on renaming
Date: 
Message-ID: <2g1bffF3aoe3U1@uni-berlin.de>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

William Bland wrote:

> Hi all,
> When I want to rename a variable in a statically typed language like
> Java, I'm pretty lazy about it:  I rename the variable where it's defined,
> compile, and then change the name in all the places the compiler tells me
> about.  I like knowing that, if it compiled, I found all the places that
> needed changing.

Not always.  Consider this:

class SomeClass {
  int i;

  int doSomething() {
    int i;
    ...
  }
}

That's why I build a habit of prefixing class fields with underscore.

> 
> Of course I do much prefer dynamic typing, except that now I can't see an
> easy way to rename things (search-and-replace doesn't work because I reuse
> names sometimes, and often names are substrings of each other).
> 
> I guess this is the kind of thing that "refactoring browsers" are meant to
> do (guessing because I've never used one). 

Yes, I use Eclipse and JBuilder, and find them very convenient.  They make
life a bit easier in the Java world.  I thought I'll miss them in Lisp, but
found out, that my style is very different.  I write shorter functions,
with less variables in Lisp, and techniques, similar to those described by
Alan and Nikodemus work pretty well.  Of course, I haven't yet written
anything big in Lisp, so my experience is a limited.

- -- 
(apply #'concatenate 'string (reverse '(".org" "kov" ·@tosh" "ivan")))
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAm3fvuUkHlsKSHdcRAmbjAJ0XRDLjHXo5Ccg4n1M2yxwqvWyA+ACeIpm8
sefSUYorphiV2r31iPKgygw=
=K5d1
-----END PGP SIGNATURE-----