Recent

Author Topic: Idea of multi-line strings, mantis 35827  (Read 9939 times)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: Idea of multi-line strings, mantis 35827
« Reply #15 on: December 28, 2020, 01:22:07 am »
Lazarus editor also provides an easy way to paste multiline string -- right click in place where you want to insert it and chose "Multi paste" (not actually a self-explaining name for that option).

Further more, if you are entering a string and hit enter while still inside the string (no closing ' yet) then you can configure the editor ("tab and indent") to insert the closing ' and any text you want.
E.g.
Code: Pascal  [Select][+][-]
  1. ' + LineEnding +

If you also want to be able to join lines and do other edit ops, you can always write editor macros (using Pascal Script) to detect your personal line break style and act on it.
A macro can also change the Pascal strings into raw text.

The difference is, that you will see the LineEnding in the source. But that also means you will see what line-ending it actually is: hardcode #13 or #10 or #13#10 or target specific LineEnding.
And you can also choose which of those line-endings you want to use.

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Idea of multi-line strings, mantis 35827
« Reply #16 on: December 28, 2020, 01:34:36 am »
Lots of ways, for example:
  • use a resourcestring section, though that posses the same problem with multi-line strings as any other code;
  • go down to basics and write your strings in an rc script as a string table, reading them back with a TStringTableResource, which has the advantage than some (most?) resource compilers allow you to use C-like scapes in the rc script;
  • ... etc ...
Ok well I know those ways but they are not really making it simpler.

Lazarus editor also provides an easy way to paste multiline string -- right click in place where you want to insert it and chose "Multi paste" (not actually a self-explaining name for that option).
That's good to know. In a way that solves the question.
Conscience is the debugger of the mind

440bx

  • Hero Member
  • *****
  • Posts: 3921
Re: Idea of multi-line strings, mantis 35827
« Reply #17 on: December 28, 2020, 02:04:13 am »
That's good to know. In a way that solves the question.
A few things are worth noting...

Yes, the feature saves some typing and/or the multi-line steps but...

Comparing the example @Zoran posted (see previous page) which uses "+ LineEnding" with using the backtick (see https://forum.lazarus.freepascal.org/index.php/topic,46050.msg326901.html#msg326901), the result using the backtick method proposed by @Akira1364 is substantially cleaner and easier to read, specifically because there are no "+" and "LineEnding" poking the eye of the reader.  In addition to that, changing the text is much simpler because the programmer doesn't have to concern him/herself with possibly having to add or delete "+ LineEnding".

IOW, the savings in typing are a bonus, what's nice about the feature is how much cleaner the resulting code is.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Idea of multi-line strings, mantis 35827
« Reply #18 on: December 28, 2020, 02:47:19 am »
Comparing the example @Zoran posted (see previous page) which uses "+ LineEnding" with using the backtick (see https://forum.lazarus.freepascal.org/index.php/topic,46050.msg326901.html#msg326901), the result using the backtick method proposed by @Akira1364 is substantially cleaner and easier to read, specifically because there are no "+" and "LineEnding" poking the eye of the reader.  In addition to that, changing the text is much simpler because the programmer doesn't have to concern him/herself with possibly having to add or delete "+ LineEnding".

On the other hand, the "backtick" is a small glyph and somewhat difficult to see when you're eye-scanning the text and making modifications at three a.m. and you are looking through a mental fog and irritated, tear-strained eyes.
I'd vote for a more visually apealling symbol, like the double-quote ... just saying :-\
« Last Edit: December 28, 2020, 02:49:13 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

440bx

  • Hero Member
  • *****
  • Posts: 3921
Re: Idea of multi-line strings, mantis 35827
« Reply #19 on: December 28, 2020, 03:12:38 am »
On the other hand, the "backtick" is a small glyph and somewhat difficult to see when you're eye-scanning the text and making modifications at three a.m. and you are looking through a mental fog and irritated, tear-strained eyes.
That's true and, it is likely a significant reason why the code looks so clean.  Everything has its pros and cons, backtick included.  ;)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Warfley

  • Hero Member
  • *****
  • Posts: 1499
Re: Idea of multi-line strings, mantis 35827
« Reply #20 on: December 28, 2020, 04:07:35 am »
https://bugs.freepascal.org/view.php?id=35827
I only want to suggest a syntax for multi-line strings:

case1)

Code: Pascal  [Select][+][-]
  1. var s = 'begin'/
  2. 'mdl'/
  3. 'end.' ;

Here we use / which is not defined for strings.
One thing I just rembered, if runtime code is not a problem (which it is for like consts), the following works:
Code: Pascal  [Select][+][-]
  1. operator /(const lhs: String; const rhs: String): String;
  2. begin
  3.   Result := lhs + LineEnding + rhs;
  4. end;
  5.  
  6. var
  7.   s: String;
  8. begin
  9.   s := 'foo' /
  10.        'bar';
  11.   WriteLn(s);
  12. end;

But thats not a good solution. Also I think / is not the best symbol, rather _ or something completely different like a named operator.

A hint, if I may: better shut off macros or undefine "ln" when it's no longer needed; otherwise you might find all your WriteLn()'s converted to "Write+LineEnding()" ;D
This was more of an example, if one thinks this more through, probably ln is also not the best name (probably a lot of people including me use ln as name for temporary variables containing lines). Something that is highly unlikely to be used, maybe something starting or ending on underscore, something line "_ln" or "_endl" or so.
Then this does not need to be undeffed necessarily.

But yeah, macros can be very messy, it has a reason why, unlike to C or C++ in pascal they are deactivated by default. A real, language level solution would be great. But as long as we don't have it, I personally think this produces much cleaner code than "+ LineEnding", which makes the code really ugly
« Last Edit: December 28, 2020, 04:10:48 am by Warfley »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8744
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Idea of multi-line strings, mantis 35827
« Reply #21 on: December 28, 2020, 04:52:11 am »
But thats not a good solution.
Not a bad one either to me. At least it serves the purpose, other overloadable symbolic operators are only - and *, which is way worse than /, while the rest are identifier operators. Nah, I wouldn't define AND for it.

Awkward

  • Full Member
  • ***
  • Posts: 133
Re: Idea of multi-line strings, mantis 35827
« Reply #22 on: December 28, 2020, 06:50:13 am »
... or we can just use double-plus ++ ...

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Idea of multi-line strings, mantis 35827
« Reply #23 on: December 28, 2020, 07:24:34 am »
A good solution should also work for constants and ressource strings; an operator overload won't do that because it's not active at compile-time.

In fact, now I think about it, are you sure this works?:
Code: Pascal  [Select][+][-]
  1. var
  2.   s: String;
  3. { ...}
  4.   s := 'foo' /
  5.        'bar';
because I remember having tested (again) some time this year and operator overloads ("*" in my case) didn't work when dealing with constants, even if assigning them to a var (IIRC, which I might not; it was in spring or early summer).
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Zoran

  • Hero Member
  • *****
  • Posts: 1824
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Idea of multi-line strings, mantis 35827
« Reply #24 on: December 28, 2020, 10:04:01 am »
the backtick method proposed by @Akira1364 is substantially cleaner and easier to read,

On contrary, it introduces something very dirty to Pascal language -- significant whitespaces at the end of line.
Inside these multiline strings, it is not obvious where the line ends. It is a very dirty feature.

In a language which should have clean syntax, you should safely rely on that there cannot be significant whitespaces at the end of a line.

With multiline string, you don't see where a line actually ends. You have to check it, and in Lazarus editor, as it is now, even that checking is not so easy -- the caret can be put anywhere beyond the actual end of the line.
So, with multiline strings, Lazarus editor will need to remove this feature. And it is a very nice feature -- I wouldn't like the caret to go left-right when I am going up-down through code.

Another beautiful feature which the editor will have to remove is automatically removing spaces from line endings when saving the unit file.

The editor uses the fact that in Pascal, spaces at the end of the line are always insignificant.
And the programmer should always be able to safely rely on that.

Some other languages do not care that much about clean syntax. In Pascal, clean syntax has always been important.
So, please do not introduce significant whitespaces at line endings in Pascal.
« Last Edit: December 28, 2020, 10:10:37 am by Zoran »

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: Idea of multi-line strings, mantis 35827
« Reply #25 on: December 28, 2020, 10:13:09 am »
So, please do not introduce significant whitespaces at line endings in Pascal.
+1

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Idea of multi-line strings, mantis 35827
« Reply #26 on: December 28, 2020, 11:56:27 am »
Better load them from resources, easier to post compilation translate them
How would you do that actually?

I don't do much enduser ready stuff in Lazarus, mostly internal tooling. But in my companies main (Delphi) app, I edit everything with GORM (poedit equivalemet made in Delphi), and then embed the .po's into the binary.

But the internal PO's can be overriden by external POs.   I use this for all user visible strings.

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Idea of multi-line strings, mantis 35827
« Reply #27 on: December 28, 2020, 12:17:21 pm »
I don't do much enduser ready stuff in Lazarus, mostly internal tooling. But in my companies main (Delphi) app, I edit everything with GORM (poedit equivalemet made in Delphi), and then embed the .po's into the binary.
Ok. Interesting, though that doesn't make it easier to add multiline strings, does it? You still need to add them as string constant.

So, please do not introduce significant whitespaces at line endings in Pascal.
+1
I suppose we can say the lines are R-trimmed.
Conscience is the debugger of the mind

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: Idea of multi-line strings, mantis 35827
« Reply #28 on: December 28, 2020, 01:14:37 pm »
All this stuff was already discussed in the thread by Akira1364 about this functionality. There won't be any further changes in syntax, cause it's good enough as it is and the majority of the core devs agree with it.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Idea of multi-line strings, mantis 35827
« Reply #29 on: December 28, 2020, 01:30:11 pm »
I don't do much enduser ready stuff in Lazarus, mostly internal tooling. But in my companies main (Delphi) app, I edit everything with GORM (poedit equivalemet made in Delphi), and then embed the .po's into the binary.
Ok. Interesting, though that doesn't make it easier to add multiline strings, does it?

You edit them in a memo? How much easier can it get?

Quote
You still need to add them as string constant.

No you load them by constant name/key from the compiled .po (.mo).


 

TinyPortal © 2005-2018