Improved line continuation

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Improved line continuation

Post by Mistrel »

Still very frustrated with this.

As I break lines to try and simplify things I keep running into strange logic when reading quickly such as "If Not Not" which makes no sense rather than "If Not Or Not" or "If Not And Not". This forces me to break context with whatever I was doing either in a WTF moment or from the pure necessity of scrolling. But then after I return to scrolling vertically I've lost all reference as there may be conflicting logic that I can't see from other lines.

Please, please, please provide a solution for this. PureBasic is the only language I use that I cannot keep at under 80 columns for clarity.

Thank you.

Linking here a similar request:

http://www.purebasic.fr/english/viewtop ... =3&t=66631
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: Improved line continuation

Post by BorisTheOld »

It seems to me that the only logical solution to this problem is to add the " _ " as a valid continuation character.

I've been using BASIC since it was invented in the 1960's, and the underscore char has been used for line continuation for as long as I can remember. Other characters like "+" and "," are not always available in the line of code in order to create suitable break points.

Rod
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
User avatar
skywalk
Addict
Addict
Posts: 3960
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Improved line continuation

Post by skywalk »

This topic never ends.
Why not force a line end character(;) like C, Pascal, and many others?
Then you get continuation for free. :wink:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: Improved line continuation

Post by BorisTheOld »

skywalk wrote:This topic never ends.
The reason is that, with nearly 1,000,000 lines of PowerBasic code to convert, it would be nice to have one less thing to worry about.

Code: Select all

Sub subDefineFile Alias "dvs6069DefineFile"   _
     ( ByRef bruHcb            As udtIsamHcb  _    ' 14869 : isam file handle control block
     , ByVal bvnFileNumber     As DWORD       _    ' 10526 : file number: 1 - 999
     , ByRef brsIsamFileName   As STRING      _    ' 15557 : isam file descriptive name
     , ByRef brsFilePath       As STRING      _    ' 15040 : generic file path
     , ByVal bviRecordLength   As LONG        _    ' 14691 : file record length
     , ByVal bvnFieldCount     As DWORD       _    ' 11241 : number of data fields
     , ByVal bviIndexCount     As LONG        _    ' 11240 : number of indexes
     ) Export
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
User avatar
skywalk
Addict
Addict
Posts: 3960
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Improved line continuation

Post by skywalk »

So the problem is trailing comma's instead of leading?

Code: Select all

Procedure x(a,    ; a something
            b,    ; b something
            c,    ; c something
            d,    ; d something
            e)    ; e something
  ProcedureReturn a
EndProcedure
Certainly, your parser/translator app can handle this? The current line continuation method was not available when I started using PB, so I appreciate it as is. I'm still waiting on block comments. :)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: Improved line continuation

Post by BorisTheOld »

skywalk wrote:Certainly, your parser/translator app can handle this?
Yes, but the code generators still have to be changed to handle PB's non-standard syntax. It would be nice if there were fewer differences. However, PB is a powerful product, so I don't mind the extra work.

We've now created almost 500 macros (and counting) in order to keep our code highly structured and easy to read. Here's what the above PowerBasic code looks like now:

Code: Select all

ExternalSubroutine(DefineFile) ( ByBlk(bruHcb,          udtIsamHcb),   ; 14869 : isam file handle control block
                                 ByVal(bvnFileNumber,   typDword),     ; 10526 : file number: 1 - 999
                                 ByRef(bvsIsamFileName, typString),    ; 15557 : isam file descriptive name
                                 ByRef(bvsFilePath,     typString),    ; 15040 : generic file path
                                 ByVal(bviRecordLength, typInt32),     ; 14691 : file record length
                                 ByVal(bvnFieldCount,   typDword),     ; 11241 : number of data fields
                                 ByVal(bviIndexCount,   typInt32) )    ; 11240 : number of indexes
Rod
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Improved line continuation

Post by Mistrel »

What if a space and a semi-colon followed by a newline to indicated a line continuation? This is both backwards compatible and is unlikely to cause issues with older code as there is little reason for anyone to actually do this in practice.

It should also be fairly clear for those already familiar with languages which require the use of a semi-colon to indicate the end of a line. IMO, it's an obvious winner.

Code: Select all

If Not CompareMemory() ;
  Or Not CompareMemory()
User avatar
skywalk
Addict
Addict
Posts: 3960
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Improved line continuation

Post by skywalk »

Sorry, but a trailing semicolon already indicates comments. This would create a parsing logic sinkhole.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Improved line continuation

Post by Shield »

It wouldn't work, because the compiler would have to treat anything after a semicolon (i.e. comment) as a continuation, so it would inevitably break all code.

Code: Select all

If a ;
    Debug a
EndIf
Would have to be treated as

Code: Select all

If a Debug a
EndIf
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Improved line continuation

Post by Mistrel »

I think you misunderstand. The semi-colon will remain the comment symbol but if it appears as the end of a line and immediately followed by a newline then it will instead be treated as a line continuation symbol.

THIS indicates line continuation because it is a semi-colon followed immediately by a newline:

Code: Select all

If a ;
    Debug a
EndIf
THIS is still a comment because the semi-colon does not appear at the end of the line:

Code: Select all

; This is a comment but below will be for line-continuation
If a ;
    Debug a
EndIf
This works because there should be very little use-case for a bare semi-colon comment. But if you want to be fancy, just add a space:

Code: Select all

; 
; This is still OK
; 
; Because there are spaces
; 
But even in events where spaces are not present, it will works if the following line is a comment:

Code: Select all

; This is also OK
;
; Because it's just continuing a comment
It really is an elegant, backwards-compatible solution that is also similar to other languages use of ';' to indicate the end of a line. I think it's perfect.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Improved line continuation

Post by #NULL »

it's the opposite of perfect. :P looks like an empty comment but isn't, and does the opposite as in other languages: split one command into multiple lines, instead of separating multiple commands from each other [on the same line].
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Improved line continuation

Post by Josh »

For some years now we have line-continuation with (+), (,), (|), And, Or, Xor. Whether this was the best decision or whether a simple underscore like used in VB6 would be better is a question. It was a decision with which I can actually live quite well.

In any case, each program can assume a certain minimum hardware configuration. When I look at this image, a screen where there are only 60 characters per line for code is not one of them.

I don't understand why an already exhausted thread based on insufficient hardware has to be kept alive with even more stupid suggestions like a semicolon as line-continuation.
sorry for my bad english
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Improved line continuation

Post by Dude »

Mistrel wrote:This looks like a good candidate for line splitting
On such a small screen size that you're using (60 chars per line), you have three additional options:

(1) A smaller font size.
(2) A font that is proportional instead of fixed-width.
(3) Auto-hiding of the procedure panel in the IDE Settings.

Using all 3 of these will greatly provide more visible characters per line for you.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Improved line continuation

Post by Shield »

Limiting lines to 80 characters (not 60) is actually really common and has little to do with screen size
but with readability. Reading code that has excessively long lines is a nightmare.

@Mistrel
Alright, I get now what you mean. It's still a terrible idea in my opinion.

@Josh
Yes, what we have now is better than nothing. However, breaking lines manually with either "_" or "\" would have been a far superior option.
Then again, I don't care much personally. I don't remember the last PB program I wrote that was longer than 100 lines. :lol:
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Improved line continuation

Post by Mistrel »

Josh wrote:I don't understand why an already exhausted thread based on insufficient hardware has to be kept alive with even more stupid suggestions like a semicolon as line-continuation.
It has nothing to do with hardware. The picture was an example.

Line continuation is a tool to for restructuring code to improve clarity. I want it because it will make my code easier to read for myself and allow me to lay it out in a clearer, more concise way, that will allow it to be more easily understood by others.

PureBasic is a very verbose language and would benefit tremendously for this feature.

On a side note, I do not care for the use of "_" as a line continuation character because at a glance it is difficult to differentiate from "-". I tried it in a few tests and my poor eyesight struggles with it.
Post Reply