Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Don't tell me how to declare a string!

Don't tell me how to declare a string!

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasetutorial
25 Posts 14 Posters 41 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Luc Pattyn

    TClarke wrote:

    private static final String SQL = "" + " SELECT " + " nvl( vss.structure_address, " + " ifsapp.serial_structure_template_api.get_pos(top_part_no," etc...

    Without the "" on the first line, you couldn't start the second line with a + hence the indentation might be at risk, i.e. the third and following lines might not align with the second one; this may become very important when the code is worthwhile and is likely be published on one or more forums. BTW: the code itself is OK, the compiler does the concatenation for you.

    Luc Pattyn [Forum Guidelines] [My Articles]


    this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


    D Offline
    D Offline
    dojohansen
    wrote on last edited by
    #21

    Indentation-wise, I find that this works well: string query = "SELECT [foo], [bar] " + "FROM [f] " + "WHERE [id] = @id";

    L 1 Reply Last reply
    0
    • D dojohansen

      Indentation-wise, I find that this works well: string query = "SELECT [foo], [bar] " + "FROM [f] " + "WHERE [id] = @id";

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #22

      That's fine by me, the only risk is you might omit a space somewhere, which you would notice more easily if everything were on one line.

      Luc Pattyn [Forum Guidelines] [My Articles]


      this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


      1 Reply Last reply
      0
      • C Chris Losinger

        compilers don't have feelings. they cannot be horrified. ;)

        image processing toolkits | batch image processing | blogging

        L Offline
        L Offline
        LFirth
        wrote on last edited by
        #23

        I bet it was comments like this that led to SkyNet waging war on man....

        1 Reply Last reply
        0
        • L Luc Pattyn

          Compilers are smart enough to understand that the concatenation of two literals yields a bigger literal. They don't generate run-time code to get that done. Also -- not applicable in this case -- the CLR compilers are known to use a StringBuilder if your code is performing complex concatenation involving not just literals, even when the source does not call for a StringBuilder explicitly. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


          R Offline
          R Offline
          Ri Qen Sin
          wrote on last edited by
          #24

          Oh nice! I didn't know that… Now I can write sloppy string concatenation code without worrying about the performance penalty! ^_^ Does this feature count as encouraging bad coding practices?

          ROFLOLMFAO

          L 1 Reply Last reply
          0
          • R Ri Qen Sin

            Oh nice! I didn't know that… Now I can write sloppy string concatenation code without worrying about the performance penalty! ^_^ Does this feature count as encouraging bad coding practices?

            ROFLOLMFAO

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #25

            Ri Qen-Sin wrote:

            Does this feature count as encouraging bad coding practices?

            Most people dont need to be encouraged in the wrong direction. Compiler optimizations typically improve the simple cases, and seldom drastically improve the complex cases (where most could be gained!). So staying vigilent would pay off frequently. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups