Board index » delphi » OOP isn't so hard

OOP isn't so hard

Quote
"Alessandro Federici" <alef@[nospam]remobjects.com> wrote in message

news:3e6faefa$1@newsgroups.borland.com...

Quote
> "Adrian Gallero" <agall...@netscape.net> wrote in message
> news:3e6fab56$1@newsgroups.borland.com...

> >     for i := 1 to FJobList.Count-1 do
> > Not that many ifs, and 1 line less ;-)

> Brilliant in its simplicity.

And buggy as well on second thought.

    Result := TJob(FJobList[0]).GetJobName();
    for i := 1 to FJobList.Count-1 do
         Result := ', '+Result;

If the list has zero items this will just blow up.
You need an IF COunt>0 around all this so we're back at square one ;-)

 

Re:OOP isn't so hard


Quote
"richk" <richk@_nospam_alltel.net> wrote in message

news:3e6faf94@newsgroups.borland.com...

Quote
> Please report to the manager's office, ASAP.

Damn! I was about to ask for a raise! <G>

Re:OOP isn't so hard


Quote
"richk" <richk@_nospam_alltel.net> wrote in message

news:3e6fb030@newsgroups.borland.com...

Quote
> "Alessandro Federici" <alef@[nospam]remobjects.com> wrote in message
> news:3e6f9274$1@newsgroups.borland.com...
> > 4) How much time did you spend looking at the VCL code which uses code
> that
> > is virtually identical to what I used
> > in my sample?

> Well, now... I can say that Delphi is GREAT. But, I don't know if I would
> consider VCL code to be the STANDARD for all code to be judged by.

It's isn't for me either (from an indentation pov, in case you were thinking
of that) but
the VCL's use of properties is definitely something to learn from. Then yes,
many things could be improved
, but that's for everything.

Re:OOP isn't so hard


In borland.public.delphi.non-technical, richk <richk@_nospam_alltel.net>
wrote in message <3e6fb...@newsgroups.borland.com>...

Quote
>#p___ 45 + 98/10 &^&%$ = 15

Gazuntheit [sic]

--
Cheers,
David Clegg
dclegg_at_ebetonline_dot_com

{$IFDEF Alessandro}Italian{$ELSE}French{$ENDIF} is the language of love.
For everything else there's Delphi.

Re:OOP isn't so hard


In borland.public.delphi.non-technical, Alessandro Federici
Quote
<alef@[nospam]remobjects.com> wrote in message

<3e6fb76...@newsgroups.borland.com>...

Quote
>If the list has zero items this will just blow up.

It won't blow up, but the for loop won't have any iterations to process. As
long as we remember to initialize Result all should be well.

I bet that Piddy, in his attempt to 'educate' us all, didn't realise how
educated he would be in return <g>

--
Cheers,
David Clegg
dclegg_at_ebetonline_dot_com

{$IFDEF Alessandro}Italian{$ELSE}French{$ENDIF} is the language of love.
For everything else there's Delphi.

Re:OOP isn't so hard


Quote
On Thu, 13 Mar 2003 12:26:09 +1100,  wrote:
>>If the list has zero items this will just blow up.

> It won't blow up, but the for loop won't have any iterations to process. As
> long as we remember to initialize Result all should be well.

Actually, it will, because the first of the 3 lines was:

    Result := TJob(FJobList[0]).GetJobName();

johannes

Re:OOP isn't so hard


Quote
David Clegg wrote:
> In borland.public.delphi.non-technical, Alessandro Federici
> <alef@[nospam]remobjects.com> wrote in message
> <3e6fb76...@newsgroups.borland.com>...

>>If the list has zero items this will just blow up.

> It won't blow up, but the for loop won't have any iterations to process. As
> long as we remember to initialize Result all should be well.

> I bet that Piddy, in his attempt to 'educate' us all, didn't realise how
> educated he would be in return <g>

Oh Yea!!! Nobody caught a major error in my code: "Troll := False;"
Slipped it right past ya, didn't I?

Hope this helps!

piddy

Re:OOP isn't so hard


Quote
piddy wrote:

> Oh Yea!!! Nobody caught a major error in my code: "Troll := False;"
> Slipped it right past ya, didn't I?

That was a major error?  Are you implying that the correct code is
   Troll := true; ?

To be honest, the delete sub-thread was nice one.

Wien.

Re:OOP isn't so hard


Quote
Josh P. wrote:

> Thank you! Comparing booleans to constants bugs me. Where to stop?

> If ((X=False)=True)=False ...

That is ugly.  But the ugliness is not in the boolean, it is in the writing.

After using boolean comparison for a while, I like it better for example

   if not FileExists () then <-- Drives me crazy.

I like
   if (FileExist() = false) then <-- I like this better.

Wien.

Re:OOP isn't so hard


Quote
Alessandro Federici wrote:

> Works. I use it from time to time. It's a nanosecond faster <G>

Everything for just a nanosecond, isn't it?  :)  Like swapping two
integer values using three xor?

procedure Swap (var a, b : integer);
begin
   a := a xor b;
   b := a xor b;
   a := a xor b;
end;

This took one of my co-worker think for a while.....

Wien.

Re:OOP isn't so hard


In article <3E700CBE.2080...@nospam.codeline.dot.net>, Erwien Saputra
wrote:

Quote
> if not FileExists () then <-- Drives me crazy.

> I like
>    if (FileExist() = false) then <-- I like this better.

I much prefer the first.

Mike Orriss (TeamB and DevExpress)

Re:OOP isn't so hard


"Erwien Saputra" wrote

Quote

>    if not FileExists () then <-- Drives me crazy.
> I like
>    if (FileExist() = false) then <-- I like this better.

This is one case where I would at least nod understandingly at the
argument.
However as long as the boolean identifier is well-named (function or
variable) then it is blasphemous (in my religion) to write
"if FileExists()=True"

Perhaps the solution to your above dilemma ("if not FileExists" being
ugly language) would be to invent a new function called "doesn't" or
somesuch. <g> How about these?
-> if Doesnt(FileExists()) then // Doesnt() function
-> if IsFalse(FileExists()) then // IsFalse function, same as Doesnt
-> if FileAbsent() then   // not-FileExists function
etc.

Kristofer

Re:OOP isn't so hard


"Erwien Saputra" wrote

Quote

> Everything for just a nanosecond, isn't it?  :)  Like swapping two
> integer values using three xor?

> procedure Swap (var a, b : integer);
> begin
>    a := a xor b;
>    b := a xor b;
>    a := a xor b;
> end;

I profiled it using Zprof and found it, on the average, twice as slow (on
my P4/1700) as:

procedure Swap2(var a, b : integer);
var c:integer;
begin
   c := a;
   a := b;
   b := c;
end;

Hmmm. So that's a lot of binary mumbo jumbo *and* slower code... ??

Kristofer

Go to page: [1] [2] [3] [4] [5] [6] [7] [8]

Other Threads