some new features to delphi prisem

classic Classic list List threaded Threaded
29 messages Options
12
Reply | Threaded
Open this post in threaded view
|

some new features to delphi prisem

ik-6
Hello,

REM Objects released an interesting document regarding some changes (that looks so much like Ruby) to their Delphi Prisem.

For example assignment of a value regarding a condition:

x := if Something then 2;
y := case Other of
         bla : 'hello';
         foo : 'bye';
         baz : 'adius';
       end;

And more.
You can find more in http://blogs.remobjects.com/blogs/mh/2010/02/18/p1116

Ido
http://ik.homelinux.org/

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: some new features to delphi prisem

Jürgen Hestermann


> y := case Other of
>          bla : 'hello';
>          foo : 'bye';
>          baz : 'adius';
>        end;

What do you gain with this?
Doesn't look much different to

case Other of
   bla : y := 'hello';
   foo : y := 'bye';
   baz : y := 'adius';
   end;

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: some new features to delphi prisem

ik-6
On Sat, Feb 20, 2010 at 20:01, Jürgen Hestermann <[hidden email]> wrote:


y := case Other of
        bla : 'hello';
        foo : 'bye';
        baz : 'adius';
      end;

What do you gain with this?
Doesn't look much different to

case Other of
 bla : y := 'hello';
 foo : y := 'bye';
 baz : y := 'adius';
 end;

Shorter write imho.

 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: some new features to delphi prisem

Marco van de Voort
In our previous episode, ik said:
> >
>
> Shorter write imho.

Or something easily marketable to make people upgrade. Not a problem of FPC.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: some new features to delphi prisem

Jürgen Hestermann
In reply to this post by ik-6
>         y := case Other of
>                 bla : 'hello';
>                 foo : 'bye';
>                 baz : 'adius';
>               end;
>     What do you gain with this?
>     Doesn't look much different to
>     case Other of
>      bla : y := 'hello';
>      foo : y := 'bye';
>      baz : y := 'adius';
>      end;
> Shorter write imho.

Is that realy a reason for adding yet another extension to Pascal?
This is C thinking. I don't care about a word more or less to write
if only the *reading* of source code is easy (and the logic of the
language is clear). But each variant in writing makes it harder to
understand a source code (especially for newbies to whom the
learning curve gets steeper and steeper with each of such 'extensions').


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: some new features to delphi prisem

Michalis Kamburelis-3
In reply to this post by ik-6
ik wrote:

> On Sat, Feb 20, 2010 at 20:01, Jürgen Hestermann
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>
>
>         y := case Other of
>                 bla : 'hello';
>                 foo : 'bye';
>                 baz : 'adius';
>               end;
>
>
>     What do you gain with this?
>     Doesn't look much different to
>
>
>     case Other of
>      bla : y := 'hello';
>      foo : y := 'bye';
>      baz : y := 'adius';
>      end;
>
>
> Shorter write imho.
>

Which also means "less chance of mistake". For example, if you decide
later to change "y" to "y1", you only have to change the code in one
place, not three. Functional "case" and "if" are not only from Ruby,
also from all functional languages (sml, ocaml), also Python and even C
have functional "if".

I'm not saying that this is some revolutional or essential feature.
But just because "we can work without it" doesn't mean it's totally
useless :)

Michalis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: some new features to delphi prisem

dmitry boyarintsev
Does this innovation makes "case" a function?

procedure SomeProc(const v: string);

SomeProc (  case Other of
                        a: 'a';
                        b: 'b';
                   end; );

Imho, this reduces the code readability.

thanks,
dmitry
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: some new features to delphi prisem

Marco van de Voort
In our previous episode, dmitry boyarintsev said:
> Does this innovation makes "case" a function?

I'd rather say an expression.
 
> procedure SomeProc(const v: string);
>
> SomeProc (  case Other of
>                         a: 'a';
>                         b: 'b';
>                    end; );
>
> Imho, this reduces the code readability.

Even if you are a favorite of said functionality, it should not
be added adhoc, but integrated in the language definition. (but that
would mean it is no longer Pascal).

I don't see the use either. Moreover the benefit/cost (work) is way to high
IMHO
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: some new features to delphi prisem

Graeme Geldenhuys-2
In reply to this post by Michalis Kamburelis-3
On 21 February 2010 17:00, Michalis Kamburelis <[hidden email]> wrote:
>
> Which also means "less chance of mistake". For example, if you decide
> later to change "y" to "y1", you only have to change the code in one
> place, not three.


Unfortunately you are wrong Michalis. Ever heard of 'syncron-edit'?

  http://wiki.freepascal.org/New_IDE_features_since#Syncron-Edit

You only need to change one variable, and all other instances will
change to. And syncron-edit applies to any selection of text. So
already works in more cases.


I vote against adding this language feature. It's not pascal-like and
actually makes the code harder to read. It also only applies to simple
assignment. Case begin..end blocks can do much more than simple
oneliners.

--
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: some new features to delphi prisem

dmitry boyarintsev
On Sun, Feb 21, 2010 at 9:03 PM, Graeme Geldenhuys
<[hidden email]> wrote:
> I vote against adding this language feature. It's not pascal-like and
> actually makes the code harder to read. It also only applies to simple
> assignment. Case begin..end blocks can do much more than simple
> oneliners.

Maybe some-one would like to catch-up with Delphi/Prism?
Wouldn't be possible to start a Prism mode to support new Delphi
syntax features? (or modeswitch, just like objectivec)?

I don't volunteer :) I'm happy with the present FPC syntax.

thanks,
dmitry
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: some new features to delphi prisem

Marco van de Voort
In our previous episode, dmitry boyarintsev said:
> > assignment. Case begin..end blocks can do much more than simple
> > oneliners.
>
> Maybe some-one would like to catch-up with Delphi/Prism?
> Wouldn't be possible to start a Prism mode to support new Delphi
> syntax features? (or modeswitch, just like objectivec)?

IMHO Prism is not even Delphi. Just recycling of the brand.

I'd rather see the time spent on features that really matter (like generics,
SEH/COM support, unicode).

If a feature is not supported by delphi, the usage is usually very low
(since most people don't even know about it, and some are limited by
compatibility requirements), except in the rare cases that it is really used
a lot (like in the past the pointer overindexing and the exit() features.
But they are no longer extensions, since D2009 Delphi has them too)

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: some new features to delphi prisem

dmitry boyarintsev
On Sun, Feb 21, 2010 at 9:22 PM, Marco van de Voort <[hidden email]> wrote:
> I'd rather see the time spent on features that really matter (like generics,
> SEH/COM support, unicode).

+1
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: some new features to delphi prisem

Michalis Kamburelis-3
In reply to this post by Graeme Geldenhuys-2
Graeme Geldenhuys wrote:

> On 21 February 2010 17:00, Michalis Kamburelis <[hidden email]> wrote:
>> Which also means "less chance of mistake". For example, if you decide
>> later to change "y" to "y1", you only have to change the code in one
>> place, not three.
>
>
> Unfortunately you are wrong Michalis. Ever heard of 'syncron-edit'?
>
>   http://wiki.freepascal.org/New_IDE_features_since#Syncron-Edit
>
> You only need to change one variable, and all other instances will
> change to. And syncron-edit applies to any selection of text. So
> already works in more cases.
>

Which is cool, but only if you and all your contributors use Lazarus for
all your editing. The fact that Lazarus makes something easier should
not be a reason to reject the language feature.

>
> I vote against adding this language feature. It's not pascal-like and
> actually makes the code harder to read. It also only applies to simple
> assignment. Case begin..end blocks can do much more than simple
> oneliners.
>

This is a matter of taste, I can imagine uses when at least functional
"if" would make code *more* readable. Noone forces programmers to
convert all their case/if to functional versions if they look
unreadable. The functional variants are supposed to be used in
particular situations, when they make sense.

Mind you, I'm not saying I'm a fan or a big proponent of this feature.
I do not own Delphi since a long time, being happy with FPC, so I'm also
not interested in compatibility.

Mostly, I'm playing devil's advocate here :), and I didn't see yet
a good argument against this feature (and I see cases when it would be
useful). The fact that it makes some cases less readable doesn't count
here imho (because it's optional, and can make other code more readable).

Michalis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: some new features to delphi prisem

Marco van de Voort
In our previous episode, Michalis Kamburelis said:
> > You only need to change one variable, and all other instances will
> > change to. And syncron-edit applies to any selection of text. So
> > already works in more cases.
> >
>
> Which is cool, but only if you and all your contributors use Lazarus for
> all your editing.
> The fact that Lazarus makes something easier should
> not be a reason to reject the language feature.

It also proves that such solution external to the language is possible. That
weakens the case for a language feature
 
> This is a matter of taste, I can imagine uses when at least functional
> "if" would make code *more* readable. Noone forces programmers to
> convert all their case/if to functional versions if they look
> unreadable. The functional variants are supposed to be used in
> particular situations, when they make sense.

That is always the reason, but every feature must be implemented tested,
supported, and may clash with future extensions.

"it wouldn't hurt", and a bit of typing, and some fairly theoretic case
about readability are IMHO quite weak arguments.
 
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re[2]: some new features to delphi prisem

José Mejuto
In reply to this post by Michalis Kamburelis-3
Hello FPC-Pascal,

Sunday, February 21, 2010, 7:29:54 PM, you wrote:

MK> This is a matter of taste, I can imagine uses when at least functional
MK> "if" would make code *more* readable. Noone forces programmers to
MK> convert all their case/if to functional versions if they look
MK> unreadable. The functional variants are supposed to be used in
MK> particular situations, when they make sense.

For me the bigger problem is that both statements change its behavior
in function of its context.

if a=b then 1 else 2;

this is a pascal error, but

z := if a=b then 1 else 2;

Is it correct ? From my point of view is much more reasonable to use
something like:

z := iff(a=b,1,2);

But to me it looks awful and a bit of c-ism and really horrible code
could be written:

z: Boolean;
begin
z := iff(a=b,iif(b=2,a=b,b<>a),not(a=b));

--
Best regards,
 JoshyFun

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: some new features to delphi prisem

David W Noon
On Sun, 21 Feb 2010 20:37:12 +0100, JoshyFun wrote about Re[2]:
[fpc-pascal] some new features to delphi prisem:

> Sunday, February 21, 2010, 7:29:54 PM, you wrote:
>
> MK> This is a matter of taste, I can imagine uses when at least
> MK> functional "if" would make code *more* readable. Noone forces
> MK> programmers to convert all their case/if to functional versions
> MK> if they look unreadable. The functional variants are supposed to
> MK> be used in particular situations, when they make sense.
>
> For me the bigger problem is that both statements change its behavior
> in function of its context.
>
> if a=b then 1 else 2;

That is an attempt at a statement, but what is being offered in Prism
is an enhanced *expression* syntax.

> this is a pascal error, but
>
> z := if a=b then 1 else 2;

This is actually valid ALGOL 60 and/or ALGOL 68.  Conditional
expressions were available in both languages.  I think Niklaus Wirth
continued with this in ALGOL W, but dropped it from Pascal.

Note that the ALGOLs required the "else" clause, as does C today (see
below).

> Is it correct ? From my point of view is much more reasonable to use
> something like:
>
> z := iff(a=b,1,2);

This is over-punctuated Visual BASIC.  Yuck.

> But to me it looks awful and a bit of c-ism and really horrible code
> could be written:
>
> z: Boolean;
> begin
> z := iff(a=b,iif(b=2,a=b,b<>a),not(a=b));

Mega-yuck!!

I can only infer that you don't write C.  The C equivalent is:

   z = a == b ? 1 : 2;

It's terse, but one gets used to it.
--
Regards,

Dave  [RLU #314465]
=======================================================================
[hidden email] (David W Noon)
=======================================================================
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re[2]: some new features to delphi prisem

José Mejuto
Hello FPC-Pascal,

Sunday, February 21, 2010, 9:32:50 PM, you wrote:

DWN> This is actually valid ALGOL 60 and/or ALGOL 68.  Conditional
DWN> expressions were available in both languages.  I think Niklaus Wirth
DWN> continued with this in ALGOL W, but dropped it from Pascal.
DWN> Note that the ALGOLs required the "else" clause, as does C today (see
DWN> below).

I'm the opposite of an compilers expert, also never learned Algol,
modula, eiffel or non "main-stream" languages, except Forth. So I
known my opinion is not an expert opinion, just an opinion only.

After this preamble :) I must say that this is Pascal, not Algol ;)

>> Is it correct ? From my point of view is much more reasonable to use
>> something like:
>> z := iff(a=b,1,2);
DWN> This is over-punctuated Visual BASIC.  Yuck.

iff is valid in VB ? Just a coincidence, I was trying to note the
"if-function".

>> But to me it looks awful and a bit of c-ism and really horrible code
>> could be written:
>> z: Boolean;
>> begin
>> z := iff(a=b,iif(b=2,a=b,b<>a),not(a=b));
DWN> Mega-yuck!!

I even do not know the result :)

DWN> I can only infer that you don't write C.  The C equivalent is:

Oh yes, I write and wrote C/C++ that's the reason I hate such things,
like:

if (a=a++==a) {......}

It's a funny entertainment to try to know which exactly that condition
will execute.

DWN>    z = a == b ? 1 : 2;
DWN> It's terse, but one gets used to it.

In near 20 years I was unable to find the reason and need of such
constructions, even when my first computer only have 3 Kb for source
code.

--
Best regards,
 JoshyFun

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Re[2]: some new features to delphi prisem

Matt Emson-2
In reply to this post by José Mejuto


Sent from my iPhone

On 21 Feb 2010, at 19:37, JoshyFun <[hidden email]> wrote:
> z := iff(a=b,1,2);
>
> But to me it looks awful and a bit of c-ism

No, that is a VB-ism. A C-ism would be:

z = (a==b ? 1 : 2);

Which I fo tend to use myself in c# as it is a lot more convenient in  
some cases.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: some new features to delphi prisem

Graeme Geldenhuys-2
In reply to this post by Marco van de Voort
Marco van de Voort wrote:
>
> IMHO Prism is not even Delphi. Just recycling of the brand.

+1


> I'd rather see the time spent on features that really matter (like generics,
> SEH/COM support, unicode).

Definitely. I would like to add 'Interface Delegation' to that list. It's a
vital part of Interfaces that is not implemented in FPC yet.



Regards,
  - Graeme -

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: some new features to delphi prisem

Graeme Geldenhuys-2
In reply to this post by Marco van de Voort
Marco van de Voort wrote:
>
> It also proves that such solution external to the language is possible. That
> weakens the case for a language feature


My point exactly! The language doesn't need such a feature because your
editor of choice should be able to do that, and in Lazarus IDE that is the
case.


Regards,
  - Graeme -

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
12