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. The Lounge
  3. Javascript: formatting

Javascript: formatting

Scheduled Pinned Locked Moved The Lounge
javascriptcomquestion
15 Posts 10 Posters 0 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 Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    JsLint (http://www.jslint.com/[^]) includes "Strict whitespace" in its recommended options. How many of you use JsLint, and how many of you follow that formatting guideline? I like to write code as function() { } JsLint wants me to write it as: function() { } What do you do?

    C K S S R 8 Replies Last reply
    0
    • L Lost User

      JsLint (http://www.jslint.com/[^]) includes "Strict whitespace" in its recommended options. How many of you use JsLint, and how many of you follow that formatting guideline? I like to write code as function() { } JsLint wants me to write it as: function() { } What do you do?

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      Thomas George wrote:

      What do you do?

      i do what i do to all pedants: i point at laugh

      image processing toolkits | batch image processing

      L 1 Reply Last reply
      0
      • C Chris Losinger

        Thomas George wrote:

        What do you do?

        i do what i do to all pedants: i point at laugh

        image processing toolkits | batch image processing

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I was wondering why they include such strict formatting in "recommended" options. I use JsLint mainly to find out using undeclared variables (can be typo) and using global variables where a local is better etc.

        1 Reply Last reply
        0
        • L Lost User

          JsLint (http://www.jslint.com/[^]) includes "Strict whitespace" in its recommended options. How many of you use JsLint, and how many of you follow that formatting guideline? I like to write code as function() { } JsLint wants me to write it as: function() { } What do you do?

          K Offline
          K Offline
          keyboard warrior
          wrote on last edited by
          #4

          Thomas George wrote:

          What do you do?

          copy & paste ;P

          ----------------------------------------------------------- Completion Deadline: two days before the day after tomorrow

          L 1 Reply Last reply
          0
          • K keyboard warrior

            Thomas George wrote:

            What do you do?

            copy & paste ;P

            ----------------------------------------------------------- Completion Deadline: two days before the day after tomorrow

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            way to go. :)

            1 Reply Last reply
            0
            • L Lost User

              JsLint (http://www.jslint.com/[^]) includes "Strict whitespace" in its recommended options. How many of you use JsLint, and how many of you follow that formatting guideline? I like to write code as function() { } JsLint wants me to write it as: function() { } What do you do?

              S Offline
              S Offline
              StevenWalsh
              wrote on last edited by
              #6

              Thomas George wrote:

              function() { }

              As i've grown as a coder, i've started adapting this style. I find it makes code just look more professional... i don't know.

              L J 2 Replies Last reply
              0
              • S StevenWalsh

                Thomas George wrote:

                function() { }

                As i've grown as a coder, i've started adapting this style. I find it makes code just look more professional... i don't know.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Visually, I find it easier to match braces with function() { } That is what I found wierd. JsLint put in formatting in its recommended options. Formatting being a personal preference or institutional preference.

                1 Reply Last reply
                0
                • L Lost User

                  JsLint (http://www.jslint.com/[^]) includes "Strict whitespace" in its recommended options. How many of you use JsLint, and how many of you follow that formatting guideline? I like to write code as function() { } JsLint wants me to write it as: function() { } What do you do?

                  S Offline
                  S Offline
                  Shog9 0
                  wrote on last edited by
                  #8

                  function() { ... }

                  ;P But yeah, i stay away from K&R-style braces. I'm sure they were a great way to save paper back in the day, but now i'd rather see my braces line up.

                  Citizen 20.1.01

                  'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'

                  1 Reply Last reply
                  0
                  • L Lost User

                    JsLint (http://www.jslint.com/[^]) includes "Strict whitespace" in its recommended options. How many of you use JsLint, and how many of you follow that formatting guideline? I like to write code as function() { } JsLint wants me to write it as: function() { } What do you do?

                    R Offline
                    R Offline
                    RichardGrimmer
                    wrote on last edited by
                    #9

                    JSLint scared the bejeezus out of me at first look - my code was apparently riddled with problems, but on closer inspection, most of the stuff can be turned off (though I can see why they recommend most of the rules...) :) The documentation page explains why it dislikes some things - mostly because of potential tpyos as far as I can tell (like banning ++ since it can easilly by typed as + +)

                    C# has already designed away most of the tedium of C++.

                    L 1 Reply Last reply
                    0
                    • R RichardGrimmer

                      JSLint scared the bejeezus out of me at first look - my code was apparently riddled with problems, but on closer inspection, most of the stuff can be turned off (though I can see why they recommend most of the rules...) :) The documentation page explains why it dislikes some things - mostly because of potential tpyos as far as I can tell (like banning ++ since it can easilly by typed as + +)

                      C# has already designed away most of the tedium of C++.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      RichardGrimmer wrote:

                      JSLint scared the bejeezus out of me at first look

                      It told me that after 35% of my .js file, it found 150 errors without the formatting turned on. I was writing javascript after a long time, and did many things wrong. Still, it ran well. :omg: There were so many semicolons missing, typos in variable names, declaring local variables as globals. JsLint showed me how much of a mess I had written. Now, I have no errors at all excluding formatting. I can't look at the KR style braces, though. :)

                      1 Reply Last reply
                      0
                      • S StevenWalsh

                        Thomas George wrote:

                        function() { }

                        As i've grown as a coder, i've started adapting this style. I find it makes code just look more professional... i don't know.

                        J Offline
                        J Offline
                        Johnny
                        wrote on last edited by
                        #11

                        StevenWalsh wrote:

                        As i've grown as a coder, i've started adapting this style. I find it makes code just look more professional... i don't know.

                        I've found it makes code look more messy! Must be a tomato/potato kind of thing.

                        1 Reply Last reply
                        0
                        • L Lost User

                          JsLint (http://www.jslint.com/[^]) includes "Strict whitespace" in its recommended options. How many of you use JsLint, and how many of you follow that formatting guideline? I like to write code as function() { } JsLint wants me to write it as: function() { } What do you do?

                          L Offline
                          L Offline
                          lbothell
                          wrote on last edited by
                          #12

                          I'm fairly new to Javascript, but I also like to compact things a bit so that I don't get lost in pages and pages, so I kind of prefer the function() { } way of doing things, particularly for nested brackets. But only so long as it remains easy to find/correct/read. :cool:

                          _________________________________________________ Have a great day!!! -- L.J.

                          L 1 Reply Last reply
                          0
                          • L lbothell

                            I'm fairly new to Javascript, but I also like to compact things a bit so that I don't get lost in pages and pages, so I kind of prefer the function() { } way of doing things, particularly for nested brackets. But only so long as it remains easy to find/correct/read. :cool:

                            _________________________________________________ Have a great day!!! -- L.J.

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #13

                            I find myself doing if (condition) { statement 1; statement 2; } else { statement3; statement 4; } as long as it remains within reasonable width. I write small functions too in a single line. function() { } But for longer functions, I prefer the function { } than function { } I find it much easier to line up braces.

                            1 Reply Last reply
                            0
                            • L Lost User

                              JsLint (http://www.jslint.com/[^]) includes "Strict whitespace" in its recommended options. How many of you use JsLint, and how many of you follow that formatting guideline? I like to write code as function() { } JsLint wants me to write it as: function() { } What do you do?

                              E Offline
                              E Offline
                              Ed Poore
                              wrote on last edited by
                              #14

                              For JavaScript I tend to follow the majority of the code and do

                              function() {
                              }

                              but for all other languages such as C# and C I do

                              function()
                              {
                              }

                              I don't prefer either but for C# I hate to see code other than the way I write it, for JavaScript I prefer the K&R style.  Perhaps I'm slightly swayed by the fact that in JS it's slightly more compact thus less overhead to transfer (stupid but I always have that thought in the back of my head).

                              1 Reply Last reply
                              0
                              • L Lost User

                                JsLint (http://www.jslint.com/[^]) includes "Strict whitespace" in its recommended options. How many of you use JsLint, and how many of you follow that formatting guideline? I like to write code as function() { } JsLint wants me to write it as: function() { } What do you do?

                                M Offline
                                M Offline
                                Michael Dunn
                                wrote on last edited by
                                #15

                                Putting the start-of-block { anywhere but on a line by itself is Pure Evil(tm). If the { is mixed in with another line, it becomes insanely hard to find the start of a block just by scanning.

                                --Mike-- Visual C++ MVP :cool: LINKS~! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ "That's what's great about doing user interface work. No matter what you do, people will say that what you did was idiotic." -- Raymond Chen

                                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