Heredoc delimiters to make embedded strings easier to read

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

Heredoc delimiters to make embedded strings easier to read

Post by Mistrel »

Consider the following SQL statement as we have it now:

Code: Select all

Statement.s=""+
  "SELECT"+#CRLF$+
  "   id, position"+#CRLF$+
  "FROM"+#CRLF$+
  "   location l"+#CRLF$+
  "WHERE"+#CRLF$+
  "   l.id= "+#CRLF$
Compared to if we had heredoc delimiters (in this example '[[' and ']]'):

Code: Select all

Statement.s=[[
  SELECT
     id, position
  FROM
     location l
  WHERE
     l.id=
]]
Last edited by Mistrel on Sat Jul 14, 2018 5:04 am, edited 3 times in total.
Cyllceaux
Enthusiast
Enthusiast
Posts: 510
Joined: Mon Jun 23, 2014 1:18 pm

Re: Heredoc delimiters to make embedded strings easier to re

Post by Cyllceaux »

+1
User avatar
NicTheQuick
Addict
Addict
Posts: 1504
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Heredoc delimiters to make embedded strings easier to re

Post by NicTheQuick »

btw: You can also use escaped strings for more clarity:

Code: Select all

Statement.s = ~"SELECT\n" +
			  ~"   id, position\n" +
			  ~"FROM\n" +
			  ~"   location l\n" +
			  ~"WHERE\n" +
			  ~"   l.id = \n"
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Heredoc delimiters to make embedded strings easier to re

Post by Dude »

Users have been requesting block comments for 16 years (viewtopic.php?f=3&t=2384) and it hasn't happened, so I doubt heredoc delimiters will happen as they're essentially the same concept.

If it helps, you can do it by including text files as strings directly in your source (a "CatchString" for the file), but it means you can't see or edit that text file in your source.
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Heredoc delimiters to make embedded strings easier to re

Post by skywalk »

Block comments would help, but SQL is another language and I verify complex queries within SQLite browsers and my database.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply