+8

Long strings auto wrap (no lines, strings)

-2724 13 years ago 0
Say you have this code in Python (but the exemple works in other languages):

class Doh(object):
    def foo():
        if bar:
            try:
                stuff()
            except CrazyError:
                log("Oh my God we are all going to die. Don't panic. I said don't panic! You are panicking ! Ok we're all dead, and it's because of you. Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh")



Now, you want to make you code fit into the 79 char limit:

class Doh(object):
    def foo():
        if bar:
            try:
                stuff()
            except CrazyError:
                log("""Oh my God we are all going to die. Don't panic.
                        I said don't panic! You are panicking !
                        Ok we're all dead, and it's because of you.
                        Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh""")


Wait, but now you got your log entries spreading on 4 lines in your log file and you can't parse it anymore.
So you are back to the old concatenation:

class Doh(object):
    def foo():
        if bar:
            try:
                stuff()
            except CrazyError:
                log("Oh my God we are all going to die. Don't panic."\
                      "I said don't panic! You are panicking !"\
                      "Ok we're all dead, and it's because of you."\
                       Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh")


Woops, now you don't have white spaces at 4 places in your string.class Doh(object):
    def foo():
        if bar:
            try:
                stuff()
            except CrazyError:
                log("Oh my God we are all going to die. Don't panic. "\
                      "I said don't panic! You are panicking ! "\
                      "Ok we're all dead, and it's because of you. "\
                       Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh ")


Well, my boss doesn't like the message, he wants it that way:


class Doh(object):
    def foo():
        if bar:
            try:
                stuff()
            except CrazyError:
                log("We are going to die. Don't panic. "\
                      "I said don't panic! You are panicking ! I know you do! I can see it!"\
                      "Ok we're all dead. "\
                       Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh ")


Ok, now this is ugly, but I'm too lazy to make it pretty again. I would have to redo everything.

I don't know about you, but I do this VERY often.

I would be very nice to just be able to select a string and ask the computer to wrap it for you. Or wrap it again to avoid update this by hand.

I know, this is not easy to do this every language got it's own way plus you need to take care of a lot checks prior to making the wrap
but I'm pretty sure everybody feels the pain for doing this f***ing strings.

 Posts: 7Joined: Mon May 09, 2011 8:08 pm