Skip to main content

What Do you Think? A Proposal to Java Language For String

3 replies [Last post]
mijzcx
Offline
Joined: 2004-09-11
Points: 0

Hello Java Community,

As a Java Developer, my concern to Java Language future is this.

I would like to ask your vote and opinion on this?

Target: java language.

Traditionally we wrote:

public static void main( String[] args )
{
String vstat1, vstat2;

vstat1 = "The quick brown " +
"Fox jumps over " +
"The lazy dog. ";

vstat2 = vstat1;

System.out.println( vstat1 + " " + vstat2);
} // main()

My Proposal:

public static void main( String[] args )
{
string
{
The quick brown
Fox jumps over
The lazy dog.
} vstat1, vstat2;

System.out.println( vstat1 + " " + vstat2 );

} // main()

Projected benefit:
1. Easy to cut and paste especially for sql statements
run-checks.
2. Easy to read.
3. Less typing, no quotes and plus sign.
4. Look! Is it it easy, what do you think?

Yes, i am aware of phython multiline string.
http://docs.python.org/tut/node5.html#SECTION005120000000000000000

As To My Proposal: (Fig1)

public static void main( String[] args )
{
string
{
The quick brown
Fox jumps over
The lazy dog.
} vstat1, vstat2;

System.out.println( vstat1 + " " + vstat2 );

} // main()

The "string" here in (Fig1) is a keyword. There shall be distinction between a
String class and a keyword "string" for multiline code presentation.
Inside the brackets is a "message" presented as wordwrap of a long line
message synonymous to message string we traditionally wrote in one line. Resulting to a
long one line output message. The vstat1, and vstat2 variables are String variables
that automatically gets the message assigned.

This I endorsed as a solution to our traditional way of string multiline
presentation - as we all know that it stinks specially on SQL construct
or to some of our embbedded scripting in respect.

Embedded Scripting is a delicate part in programming. One miss or error
in spelling is a big distraction. IDEs are neutral to this string
presentations. This are all treated as raw, same way may it be a script
language embbeded or just a mere "quick brown fox".
We are (The Java Community especially at the DAO side) all
aware that scripts should be tested first before we embbed.

Outside file resources only offer another clumsiness on scripting
side. On one side we would not allow somebody an end user to alter our scripting, a
good example is SQLs. The aim is this, scriptings should be
easy enough to copy and paste from java source to executable scratch pad of the
scripting language of choice. Like for example for MySQL, I need to run first my
console mysql> or any SQL Manager Application and copy paste it to my console
in order to get an assurance that my scripts would run smoothly.
Now in debugging I am already confident that it is not my scripts
who are making some nuisance.

Traditionally we wrote: (Fig2)

public static void main( String[] args )
{
String vstat1, vstat2;

vstat1 = "The quick brown " +
"Fox jumps over " +
"The lazy dog. ";

vstat2 = vstat1;

System.out.println( vstat1 + " " + vstat2);
} // main()

In Fig2 traditionally we wrote like that. In debugging DAO, I first run a notepad or something;
transfer the strings into it; cleanup the quotes and plus signs; then copy and paste it
to the console or sql manager apps; then modify if theres some wringkles; then from
the notepad copy paste again to my java code; then add again a "quotes and a plus sign"
or aStringBuilder.append("again"); aStringBuilder.append("and again and so on"); - just
to envision this good practice. What a worst isnt it?

For embedded xml, yeah you can define also with this kind of construct
(Fig3 below). But not XML embedded language as part of Java language in which
I don't agree, for it will only cause Language Pollution or Confusion. Now vxml1(Fig3 below)
you can now use it like any other strings. And finally (Java)
with its "string" as keyword, Java should be distinct from other language,
especially C# were string and String means the same thing. Isn't it?

(Fig3)

string {
<?xml version="1.0"?>

Some thing like that.

} vxml1;

Sqlj in Oracle and DB2 #sql keyword already has this kind of concept,
but only concentrate to sql construct. You pre-compile first to sqlj
compiler then to javac so to say. As to my concern, I have this strong vibe
that there have been impluse already from the Java Community on kind of
problem I address. As I base this on my experience in programming particularly
in embedding scripting languages; making us like chasing cats and dogs in
debugging stage. Me, particular to SQL Scripting in DAO part.

In My Humble Opinion,

-Melvin

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
aviadbd
Offline
Joined: 2004-07-04
Points: 0

I would also point to note the new formatting ability in Tiger. How would you handle that?

I don't agree with soupdragon about swallowing the text: The compiler will identify this as a non-closed bracket, at worst, and the IDE could alert about this way before at best.

That said, I agree that newlines will be confusing. While ususally you would do
"A B C " +
"D E F"

And expect it to be a string without a newline, now you would have to guess (or know for sure that it IS with a newline). For us who just want to separate our long strings, this offers no real solution.

soupdragon
Offline
Joined: 2006-01-07
Points: 0

> I don't agree with soupdragon about swallowing the
> text: The compiler will identify this as a non-closed
> bracket, at worst, and the IDE could alert about this
> way before at best.
>

Imagine, for example, you put two of these things, one after the other and accidentally put a right paren instead of a right brace on the end of the first one. (On some fonts it's very easy to not see this mistake).

Usually you get a syntax error, sooner or later, but (for example in Perl) it's often a long way from the actual typo, because it doesn't happen at least until something ressembling the closing sequence is encountered. Sometime not until considerably later.

soupdragon
Offline
Joined: 2006-01-07
Points: 0

Well, my first thought is to wonder how many existing programs use "string" as a variable or field name.

You don't always want to name a String constant. If you are going to define a new literal format, it would be better to keep it as syntactically equivalent to a string literal.

Incidentally, I'm assuming that the newlines in your string constant will be significant, so your examples wouldn't actually be equivalent.

In langauages that use multi-line string literals there's always a risk of an unterminated multi-line string swallowing whole swatches of code, perhaps without even generating an error message. Your syntax, if the } were ommited, could silently swallow any following syntacitcal object which happend to end with }.

I agree that the need to use the " + \n" format isn't ideal, but I fear the proposed cure is slightly worse than the disease.