Recent

Author Topic: Bounded With  (Read 10619 times)

jc99

  • Hero Member
  • *****
  • Posts: 544
    • My private Site
Re: Bounded With
« Reply #45 on: July 16, 2017, 09:22:13 pm »
Supporting Typecasts could be usefull:
Code: Pascal  [Select][+][-]
  1. with b := Sender as TButton do
  2.     b.Caption := 'Click';
  3.  
Silly example, but get my point   ;)
What strange people. Instead of pressing Ctrl + Shift + C (at b) after writing b : = Sender as TButton, they prefer to write with and require changing the pascal language for this. Of course it's easier to change the language :D .

You are right, for new code, but what do you do with the tons (gigabytes) of already existing code ? I thought it as an intermediate, to maybe get rid of with in the final coding step.
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

Thaddy

  • Hero Member
  • *****
  • Posts: 10488
Re: Bounded With
« Reply #46 on: July 16, 2017, 10:32:10 pm »
Supporting Typecasts could be usefull:
Code: Pascal  [Select][+][-]
  1. with b := Sender as TButton do
  2.     b.Caption := 'Click';
  3.  
Silly example, but get my point   ;)
What strange people. Instead of pressing Ctrl + Shift + C (at b) after writing b : = Sender as TButton, they prefer to write with and require changing the pascal language for this. Of course it's easier to change the language :D .

You are right, for new code, but what do you do with the tons (gigabytes) of already existing code ? I thought it as an intermediate, to maybe get rid of with in the final coding step.
Jc99 So you think it's a good idea to have an implicit copy? Hmm.. Think again... Hmmm..
When you ask a question that is actually answered in the documentation, you are either lazy or a moron.

jc99

  • Hero Member
  • *****
  • Posts: 544
    • My private Site
Re: Bounded With
« Reply #47 on: July 17, 2017, 12:11:01 am »
Jc99 So you think it's a good idea to have an implicit copy? Hmm.. Think again... Hmmm..
No! I think of it as named, dereferenced, scoped pointer ! Otherwise it won't work with records ! And please don't get personal, it's all about the topic !
BTW: Creating a variable with  Ctrl + Shift + C won't work with records too.

[Edit]
There is only one argument against the "NewWith-proposal" for me (but it's a very big one): It's not Delphi compatible !
« Last Edit: July 17, 2017, 12:32:04 am by jc99 »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

bylaardt

  • Sr. Member
  • ****
  • Posts: 308
Re: Bounded With
« Reply #48 on: July 17, 2017, 03:04:49 am »
@jc99

pros and cons!
You started with the cons and give us a nil list of pros.

Replacing "var"/"const" with "with"/"using" is really a good point to abandon this idea.

about scope problems, remember that pascal-derived languages have nested functions and IMO the compiler provide good optimizations.

Thaddy

  • Hero Member
  • *****
  • Posts: 10488
Re: Bounded With
« Reply #49 on: July 17, 2017, 08:47:05 am »
Consider this about with....
Code: Pascal  [Select][+][-]
  1. {$macro on}{$Define dwim:=with}
https://en.wikipedia.org/wiki/DWIM

 >:D :'(
[edit] or
Code: Pascal  [Select][+][-]
  1. uses
  2.   classes,sysutils, math;
  3.  
  4. type
  5.   ESomebodyUsedWithException = class(Exception);
  6.  
  7. function CheckScopeForWith(const value:TObject):Boolean;  
  8. begin
  9.   Result := RandomFrom<Boolean>(true); // needs trunk!
  10. end;
  11.  
  12. function &with(const value:TObject):Tobject;
  13. begin
  14.    Result := value;
  15.   if CheckScopeForWith(value) then
  16.     Raise ESomebodyUsedWithException.Create('Back to school, with statement may be ambiguous here...or not, dunno, raised it anyway...')
  17.  end;
   
« Last Edit: July 17, 2017, 10:51:30 am by Thaddy »
When you ask a question that is actually answered in the documentation, you are either lazy or a moron.

jc99

  • Hero Member
  • *****
  • Posts: 544
    • My private Site
Re: Bounded With
« Reply #50 on: July 17, 2017, 11:22:20 am »
@jc99

pros and cons!
You started with the cons and give us a nil list of pros.

Replacing "var"/"const" with "with"/"using" is really a good point to abandon this idea.

about scope problems, remember that pascal-derived languages have nested functions and IMO the compiler provide good optimizations.
The pro is that the programmer would have access to an already existing pointer (as written in the wiki) to avoid ambiguous behavior.
For me having information and less ambiguity is a very BIG pro (sorry for not stating this so explicit here in the first place, i thought anybody with more than hobby programming experience would instantly see that.)

@Thaddy DWIM leaves place for speculation, it's a more TCEWIW-approach.
nobody forces you to use with, so please vice versa don't force anybody else not to ...
« Last Edit: July 17, 2017, 11:38:16 am by jc99 »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

Thaddy

  • Hero Member
  • *****
  • Posts: 10488
Re: Bounded With
« Reply #51 on: July 17, 2017, 12:09:58 pm »
@Thaddy DWIM leaves place for speculation,

As long as there is a scoping issue, yes, that's the whole point. It is speculative.,.
Even in some suggestions here like:
with b := Sender as TWhatever do
    b.Caption := 'Click';
and TWhatever has a field named "b",.. is plain silly.

In general I see just suggestions that require *more* typing to circumvent *less* typing that "with" was introduced for.
As far as I am concerned that is bad language design. We have perfectly readable block-scoping already.
I am not against the use of "with" perse, I am against using it without thought. Usually programmers do not think...Only when the debugger (or a crash... more likely) forces them to do so..
And computer language design is simply based around that concept: programmers do not think, they try and see what happens...

That also means that language features that *require* thought by implication should be banned from a well designed language....

We are all a lot more stupid than we think... :o Otherwise, why would only programmers need a structured language? Now think about that: we are morons..
« Last Edit: July 17, 2017, 02:40:03 pm by Thaddy »
When you ask a question that is actually answered in the documentation, you are either lazy or a moron.

bylaardt

  • Sr. Member
  • ****
  • Posts: 308
Re: Bounded With
« Reply #52 on: July 17, 2017, 04:46:44 pm »
@Jc99
Pointer? then your "BIG" pro is a total mess because "var"/"const" can provide this with great otimizations on compiler.
Avoid use "with" while you haven't knowledge about of the real purpose.
Disambiguation is a good idea at the first hand, but "with" is not the best way to do it.

bytebites

  • Sr. Member
  • ****
  • Posts: 299
Re: Bounded With
« Reply #53 on: July 17, 2017, 06:18:59 pm »
Consider this about with....
Code: Pascal  [Select][+][-]
  1.  
  2. function CheckScopeForWith(const value:TObject):Boolean;  
  3. begin
  4.   Result := RandomFrom<Boolean>(true); // needs trunk!
  5. end;
  6.  
  7.  


Which trunk compiles that?
Quote from: compiler says
Error: Operator is not overloaded: "RandomFrom(const {Open} Array Of Double):Double;" < "Boolean"

Thaddy

  • Hero Member
  • *****
  • Posts: 10488
Re: Bounded With
« Reply #54 on: July 17, 2017, 06:20:35 pm »
Since last friday  :D I wrote it! It is in math.pas. Above syntax is of course also {$mode delphi} but it also works in {$mode objfpc} if you care to type "specialize" a lot....
Small example:
Code: Pascal  [Select][+][-]
  1. program testrandomfrom;
  2. {$mode delphi}
  3. uses math,sysutils;
  4. var
  5.   i:integer;
  6.   a:array[0..99] of string;
  7. begin
  8.   for i :=0 to 99 do
  9.     a[i] := IntToStr(i);
  10.   for i :=1 to 100 do
  11.   begin
  12.     write(RandomFrom<string>(a):4);
  13.     if i mod 10 = 0 then writeln;
  14.   end;
  15.   readln;
  16. end.
« Last Edit: July 17, 2017, 08:36:41 pm by Thaddy »
When you ask a question that is actually answered in the documentation, you are either lazy or a moron.

jc99

  • Hero Member
  • *****
  • Posts: 544
    • My private Site
Re: Bounded With
« Reply #55 on: July 17, 2017, 11:12:50 pm »
As long as there is a scoping issue, yes, that's the whole point. It is speculative.,.
Even in some suggestions here like:
with b := Sender as TWhatever do
    b.Caption := 'Click';
and TWhatever has a field named "b",.. is plain silly.
That's why my first proposal was the (<stack-number>) - Proposal to circumvent name-identifier ambiguity.
@Jc99
Pointer? then your "BIG" pro is a total mess because "var"/"const" can provide this with great otimizations on compiler.
Avoid use "with" while you haven't knowledge about of the real purpose.
Disambiguation is a good idea at the first hand, but "with" is not the best way to do it.
Have you read the WIKI ?
Have you actually tried that with a record ?

Code: Pascal  [Select][+][-]
  1. var lsr=TSomerecord;
  2.      
  3. begin
  4.    SomeStruct[5].Somerecord.Caption := '' // Initialization
  5.    // [...]
  6.    lsr := SomeStruct[5].Somerecord;
  7.    lsr.Caption := 'Hello Underworld !';
  8.    // [...]
  9.    writeln(SomeStruct[5].Somerecord.Caption);//Suprise
  10. end.
  11.  
vs.
Code: Pascal  [Select][+][-]
  1. begin
  2.    SomeStruct[5].Somerecord.Caption := '' // Initialization
  3.    // [...]
  4.    with {lsr :=} SomeStruct[5].Somerecord do
  5.       {lsr.} Caption := 'Hello World !';
  6.    // [...]
  7.    writeln(SomeStruct[5].Somerecord.Caption);//No Suprise
  8. end.
  9.  

[EDIT]
 To make it clear:
The big pro to me is that i can _T_ell the _C_ompiler _E_xactly _W_hat _I_ _Want
I always prefer that over _D_o _W_hat _I_ _M_ean, because as  I wrote earlier: that leaves room for speculation and can change over the years.

« Last Edit: July 17, 2017, 11:52:34 pm by jc99 »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

bylaardt

  • Sr. Member
  • ****
  • Posts: 308
Re: Bounded With
« Reply #56 on: July 18, 2017, 12:13:12 am »
Have you actually tried that with a record ?
Works fine when i use var and pointers properly
Code: Pascal  [Select][+][-]
  1. var
  2.   lsr: ^TSomerecord;  
  3. begin
  4.    SomeStruct[5].SomeRecord.Caption := ''; // Initialization
  5.    // [...]
  6.    lsr := @SomeStruct[5].Somerecord;
  7.    lsr^.Caption := 'Hello Underworld !';
  8.    // [...]
  9.    writeln(SomeStruct[5].Somerecord.Caption);// Are you surprised?
  10. end;
  11.  

jc99

  • Hero Member
  • *****
  • Posts: 544
    • My private Site
Re: Bounded With
« Reply #57 on: July 18, 2017, 12:54:22 am »
Have you actually tried that with a record ?
Works fine when i use var and pointers properly
Code: Pascal  [Select][+][-]
  1. var
  2.   lsr: ^TSomerecord;  
  3. begin
  4.    SomeStruct[5].SomeRecord.Caption := ''; // Initialization
  5.    // [...]
  6.    lsr := @SomeStruct[5].Somerecord;
  7.    lsr^.Caption := 'Hello Underworld !';
  8.    // [...]
  9.    writeln(SomeStruct[5].Somerecord.Caption);// Are you surprised?
  10. end;
  11.  
POINTERS, That's your big solution ? Are you sure ?
So when writing code you first have distinguish, is it a record or maybe a class, or an object or maybe an array or a generic or is it something else, and what code do I have to use for that specific construct ?
Don't you think that that's a little archaic, when with can provide such an elegant solution ? 

BTW I am not suprised, this looks like code I've written 25 years ago, and I had hoped those times where long gone ...
The topic is about the future of free pascal, but this comes from the "dark"-ages 
« Last Edit: July 18, 2017, 12:57:30 am by jc99 »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

bylaardt

  • Sr. Member
  • ****
  • Posts: 308
Re: Bounded With
« Reply #58 on: July 18, 2017, 04:44:17 am »
Okay. I understand it's not elegant enought for you because is old fashion.
{sarcasm=On}
Just like sex is dirty, obscene and come from a long, long ago tradition of reprodution. I Know! Sex is for "animals"! But in vitro fertilization is better, because you can choose eye color and discard all other embryos. New Fashion!
{sarcasm=Off}
You can do it, is not ambigous and you can be sure this is a pointer. This is the real proposal of strongly typed language.

I know I can't change your opinion and I'll still waiting for your last rejoinder to close this dialectic. I am happy to participate in this interchange of ideas. Thanks.

mse

  • Sr. Member
  • ****
  • Posts: 286
Re: Bounded With
« Reply #59 on: July 18, 2017, 07:44:51 am »
@jc99:
Give up, FPC never will have a safe "with" statement unless Delphi introduces it. It has been discussed so many times without result. There is even an ancient Pascal compiler which has a save with statement, but FPC - nope.
https://www.mail-archive.com/fpc-pascal%40lists.freepascal.org/msg37615.html

MSElang has it BTW. MSElang also has the unification of "records", "objects" and "classes" which has been requested in another thread.


 

TinyPortal © 2005-2018