- Code: Select all
<?php
// this is fugly. :)
class Foo {
public static function useUglyCode() {
$email = <<<EMAIL
Dear Mr. Mister,
...
...
EMAIL;
}
}
The question here is what is the most common use case?
Like others mentioned you often paste multiline strings into your code. I use them a lot for SQL and emails templates and here's what looks good to me. This is without keeping any parsing challenges in mind.
- Code: Select all
class Foo
def main
email = """
Dear Lovely String,
How are y...
Here's a new paragraph with an indent :)
"""
# here's how nice you can write SQL so you don't have to use an unnecessary ORM :)
# SQL is powerful, use it or lose it LOL
sql = """
SELECT a.foo, b.bar
FROM alpha a
LEFT JOIN beta b ON a.id = b.alpha_id
WHERE a.cost > 20
ORDER BY a.pro DESC
"""
print email, sql
Given this, additional processing, like hopscc suggested, is also needed. Not sure if I like the +| syntax but then again we all got used to string formats in C# and Java right?
@hopscc is that JSON string from the JSON parser? LOL. That's actually a good use case.