Board index » delphi » Re: Another Castalia 5/Delphi 2007 preview video

Re: Another Castalia 5/Delphi 2007 preview video


2007-03-07 01:51:47 AM
delphi274
And then a whole load of other parallel ones that use 'r' to mean
'Result'
r0 expands to "result := 0;"
r1 expands to "result := 1;"
rn expands to "result := nil;"
rf expands to "result := False;"
rt expands to "result := True;"
To get a bit more ambitious, I also loved 'sw' abbreviating 'swap'. If
you type 'sw' on the end of a code line that looked like this
edStartValue.AsInteger := n.fStartValue;
then CodeRush inserts a new line with the reverse assignment
n.fStartValue := edStartValue.AsInteger;
You can highlight a whole block of assignments like that and, using a
command in the right click menu, have it do all the swaps in one hit.
This is *very* satisfactory ;-)
I have somewhere a pdf of useful CodeRush keystroke shortcuts and
macros. Perhaps you would like an e...?
Will Watts
 
 

Re: Another Castalia 5/Delphi 2007 preview video

Will --
All of what you've described can be done with the built-in live
Templates.
--
Nick Hodges
Delphi Product Manager - CodeGear
blogs.codegear.com/nickhodges
 

Re: Another Castalia 5/Delphi 2007 preview video

Quote
The key there is "usually", and "rarely checked". My philosophy when I
find a bug is to work out how I can stop that problem ever happening
again. FreeAndNil is one such mechanism. Yes, often the finally is at the
end of the routine, but there are also times when it isn't, or new code
gets added to the end.
Sorry, for local variables I cannot see the point. If I have code like this:
var
Work: TMyWork;
begin
Work := TMyWork.Create(wtToday);
try
Work.Process;
finally
Work.Free;
end;
end;
And I want to extend it to this:
var
Work: TMyWork;
begin
Work := TMyWork.Create(wtToday);
try
Work.Process;
finally
Work.Free;
end;
Work := TMyWork.Create(wtTomorrow);
try
Work.Process;
finally
Work.Free;
end;
end;
I still don't require to nil it (in fact Destroy instead of Free is
enough). If for some reason the second part requires a check, why don't
you set Work to nil at the very beginning? Why does the second part
require a nil while the first part does not? In fact I try not to reuse
such local variables, and refactor it and call two sub methods from this
one. Last not least FreeAndNil is only required for multithreading
(otherwise you can simply nil the variable after destroying it). Of
course you can always do more than you need, but theoretically following
has the least overhead:
Destroy for local variables
Free for fields created in a constructor
Free, than nil in case the field does not always live
FreeAndNil in case the field does not always live in a multithreading
environment
IMO FreeAndNil is only required rarely, but of course you are right,
doing too much does not harm, except for execution speed.
--
Jens Gruschel
www.pegtop.net
 

Re: Another Castalia 5/Delphi 2007 preview video

Quote
I still don't require to nil it
What you require and what is good practice are two different things. Yes,
sure, you can write this:
Quote
var
Work: TMyWork;
begin
Work := TMyWork.Create(wtToday);
try
Work.Process;
finally
Work.Free;
end;
end;
And that is just fine. But let's say, two years from now, you get some new
programmer on your team, and they do this:
var
Work: TMyWork;
begin
Work := TMyWork.Create(wtToday);
try
Work.Process;
finally
Work.Free;
end;
if assigned(Work) then
Work.DoOtherProcess;
end;
It's a rookie error, but it happens. Now, this might go unnoticed for a very
long time, especially if DoOtherProcess is a class method. Then, other
changes are made over time, and one day something changes that breaks this
code. it is going to take some time to track it down and figure out why this
isn't working, why did it used to work, blah, blah, blah. All of this could
be avoided if you simply change Work.Free to FreeAndNil(Work).
Yes, this is hypothetical, and yes, it is contrived, but errors like this
creep in all the time, and are exacerbated when it is not local, and it's
FWork instead of TWork. it is just a good habit to get into that saves you
programming effort down the line.
Then again, maybe you're perfect, and your co-workers are perfect, and you
don't need to worry about problems like this. I doubt it, though. :-)
--
Tim Sullivan
Unlimited Intelligence Limited
www.uil.net
 

Re: Another Castalia 5/Delphi 2007 preview video

The problem though is the XML to write them. At least, that is how it
appears. Is there a dialog that one can just edit them in?
/Matthew Jones/
 

Re: Another Castalia 5/Delphi 2007 preview video

That does indeed summarise the problem. More likely is the TStringList
use, where you process it, clear it, then get Strings.Count. That might
work a lot of the time, but it isn't valid.
It isn't a requirement to do this, but on the few occasions a mistake is
made, FreeAndNil *guarantees* you know about it immediately.
/Matthew Jones/
 

Re: Another Castalia 5/Delphi 2007 preview video

Matthew Jones writes:
Quote
The problem though is the XML to write them. At least, that is how it
appears. Is there a dialog that one can just edit them in?
You can edit them in the IDE. You can create new ones with the
Template Template.
I wrote an expert that makes it pretty easy to add a "quick and dirty",
simple replacement one from the IDE.
cc.codegear.com/Item/23912
I can also easily convert a comma delimited text file to a bunch of
template files. I think the above code will do that.
--
Nick Hodges
Delphi Product Manager - CodeGear
blogs.codegear.com/nickhodges
 

Re: Another Castalia 5/Delphi 2007 preview video

Nick Hodges (CodeGear) writes:
Quote
Matthew Jones writes:

>The problem though is the XML to write them. At least, that is how
>it appears. Is there a dialog that one can just edit them in?

You can edit them in the IDE. You can create new ones with the
Template Template.

I wrote an expert that makes it pretty easy to add a "quick and
dirty", simple replacement one from the IDE.

cc.codegear.com/Item/23912

I can also easily convert a comma delimited text file to a bunch of
template files. I think the above code will do that.
Gee I wish I had of known that before I created my own.
I compiled yours up and its safe to say they are pretty different.
I posted some screenshots of mine in the attachments group (Subject:
Live Template Creator).
--
TJSDialog - TaskDialog for other operating systems:
www.jed-software.com/jsd.htm
Visual Forms IDE Add In: www.jed-software.com/vf.htm
Blog: jedqc.blogspot.com
 

Re: Another Castalia 5/Delphi 2007 preview video

Matthew Jones writes:
Quote
The problem though is the XML to write them. At least, that is how it
appears. Is there a dialog that one can just edit them in?
If you'd like to try mine out shoot me an email.
I posted some screenshots of mine in the attachments group (Subject:
Live Template Creator).
--
TJSDialog - TaskDialog for other operating systems:
www.jed-software.com/jsd.htm
Visual Forms IDE Add In: www.jed-software.com/vf.htm
Blog: jedqc.blogspot.com
 

Re: Another Castalia 5/Delphi 2007 preview video

JED writes:
Quote
I posted some screenshots of mine in the attachments group (Subject:
Live Template Creator).
I have no doubt that yours is vastly superior. ;-)
--
Nick Hodges
Delphi Product Manager - CodeGear
blogs.codegear.com/nickhodges
 

Re: Another Castalia 5/Delphi 2007 preview video

JED writes:
Quote
I compiled yours up and its safe to say they are pretty different.
I should add that mine is designed to create a very simple one-for-one
replacement template.
--
Nick Hodges
Delphi Product Manager - CodeGear
blogs.codegear.com/nickhodges
 

Re: Another Castalia 5/Delphi 2007 preview video

Bruce McGee writes:
Quote
csn and csx expand to CodeSite EnterMethod and ExitMethod calls with
the name of the current method name already filled in.
I see from one of Jacob's video tutorials that Castalia templates let
you insert the current method name.
Cool.
--
Regards,
Bruce McGee
Glooscap Software
 

Re: Another Castalia 5/Delphi 2007 preview video

I may do, but I have to say the Castalia demos look like it will do pretty
much most of what I want.
/Matthew Jones/
 

Re: Another Castalia 5/Delphi 2007 preview video

Quote
I see from one of Jacob's video tutorials that Castalia templates let
you insert the current method name.
Indeed, though it doesn't include the class. I am intrigued as to whether I
care, since I often delete the class from the Codesite versions.
/Matthew Jones/
 

Re: Another Castalia 5/Delphi 2007 preview video

If you haven't already, take a look at Dean't QC report. I think it
would be very useful for cases where you have a lot of small but
related templates like these.
I know the current layout is made for maximum flexibility, but also
supporting the simpler format might make live templates a little more
approachable.
qc.codegear.com/wc/qcmain.aspx
--
Regards,
Bruce McGee
Glooscap Software
 

Re: Another Castalia 5/Delphi 2007 preview video

Quote
>I see from one of Jacob's video tutorials that Castalia templates let
>you insert the current method name.

Indeed, though it doesn't include the class. I am intrigued as to whether I
care, since I often delete the class from the Codesite versions.
There's a macro for the classname as well. If you want the classname, it's
easy to just have it insert <classname>.<methodname>.
--Jacob