Jump to content
Tommi Prami

With haters unite

Recommended Posts

I see issue 21814...I see no with. Both eyes open...Brain perhaps not at 100% though.

Share this post


Link to post

Did you mean https://quality.embarcadero.com/browse/RSP-18953 - Tommi?

 

21814 is the Windows 10 Ansi/UTF-8 QP - which, by the way, returns different values on my Windows 10 Enterprise 1809  10.0.17763.831, depending on which PowerShell version you use.

 

PowerShell 5.1
IsSingleByte      : True
BodyName          : iso-8859-1
EncodingName      : Western European (Windows)
HeaderName        : Windows-1252
WebName           : Windows-1252
WindowsCodePage   : 1252
IsBrowserDisplay  : True
IsBrowserSave     : True
IsMailNewsDisplay : True
IsMailNewsSave    : True
EncoderFallback   : System.Text.InternalEncoderBestFitFallback
DecoderFallback   : System.Text.InternalDecoderBestFitFallback
IsReadOnly        : True
CodePage          : 1252

PowerShell 6.2.4
Preamble          :
BodyName          : utf-8
EncodingName      : Unicode (UTF-8)
HeaderName        : utf-8
WebName           : utf-8
WindowsCodePage   : 1200
IsBrowserDisplay  : True
IsBrowserSave     : True
IsMailNewsDisplay : True
IsMailNewsSave    : True
IsSingleByte      : False
EncoderFallback   : System.Text.EncoderReplacementFallback
DecoderFallback   : System.Text.DecoderReplacementFallback
IsReadOnly        : True
CodePage          : 65001

 

Share this post


Link to post

I'd like this to be possible, and a compiler switch that bans the old with statements.

with var ref := Some.Array[Index1].Reference, var thing := Function(Index1).Thing
do begin
  if ref.Value <> thing.Value
  then begin
    ...
  end;
end;
// ref and thing are not present

 

  • Like 1

Share this post


Link to post
2 hours ago, Lars Fosdal said:

I'd like this to be possible, and a compiler switch that bans the old with statements.


with var ref := Some.Array[Index1].Reference, var thing := Function(Index1).Thing
do begin
  if ref.Value <> thing.Value
  then begin
    ...
  end;
end;
// ref and thing are not present

 

It is, it's called inline variables... 😉

 

Share this post


Link to post
16 minutes ago, Wagner Landgraf said:

It is, it's called inline variables... 😉

 

True, but the point is a more natural limit of variable scope.

var ref := Some.Array[Index1].Reference;
var thing := Function(Index1).Thing;
if ref.Value <> thing.Value
then begin
  ...
end;
// ref and thing ARE present here

I guess you could wrap it in another pair of begin/end - but that would look a bit strange, while the with signals clearly that these are local.

Share this post


Link to post
7 minutes ago, Lars Fosdal said:

I guess you could wrap it in another pair of begin/end - but that would look a bit strange, while the with signals clearly that these are local.

You already have a begin...end pair:

with whatever do
begin
end;

So why not just move the inline inside the begin...end and get rid of the with:

begin
  var thisorthat := whatever;
  ...
end;

I see no reason to change the language so we can keep using with. Just get rid of it and forget it ever existed.

  • Like 3
  • Thanks 1

Share this post


Link to post

Indeed! You would write it this way:

begin
  ...
  begin  // do something with ref and thing 
    var ref := Some.Array[Index1].Reference;
    var thing := Function(Index1).Thing
    if ref.Value <> thing.Value
    then begin
      ...
    end;
  end;
  // ref and thing are not present
  ...
end;

 

Edited by Uwe Raabe

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×