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. Programming in Javascript creates bad habits

Programming in Javascript creates bad habits

Scheduled Pinned Locked Moved The Lounge
javascriptcsharppythonhtmlcom
16 Posts 9 Posters 27 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 Lost User

    var spinny = new function(){ var self=this; this.ID = "spinny"; this.show = function(){ $("#"+ self.ID).jqxLoader('open'); } } spinny.show(); spinny.ID="otherspinny"; spinny.show(); Is that better? :)

    T Offline
    T Offline
    TheGreatAndPowerfulOz
    wrote on last edited by
    #5

    :thumbsup: :laugh:

    #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

    1 Reply Last reply
    0
    • M Marc Clifton

      I find myself doing things I would never do in C# code. The two most common things are: 1) copy and paste code from one HTML page to another Why? Because making something reusable requires: a. create a separate js file b. put the functions in there c. add a </code> line to suck it in d. remember that I have these common functions in this other file when writing other pages OK, I suppose that's sort of the same steps in a real programming language, it just seems harder when working on a website. 2) everything tends to be inline code. I like to practice writing human readable and short methods when I code in C#. Conversely, when I code in Javascript, I'll do something like this (a somewhat trivial example, granted, but it makes the point): <code>$('#spinny').jqxLoader('open');</code> This is completely non-reusable and un-maintainable. Imagine hundreds of pages that all have spinny's for when the page does some sort of AJAX callback, and maybe you want to change something about the spinny behavior. So this: <pre>function showSpinny() { $('#spinny').jqxLoader('open'); }</pre> while seemingly stupid, becomes a re-usable and maintainable piece of code. I wonder what it is about Javascript that promotes these (I only cite two examples) practices? Is it just me? I don't think so, I see other developers writing the same cruft. Albeit, they're also Python developers, and I see the same cruft in their Python code. Marc <div class="signature"><a href="http://www.syncfusion.com/resources/techportal/ebooks/imperative">Imperative to Functional Programming Succinctly</a> <a href="http://www.higherorderprogramming.com/developers-1-1-1/">Contributors Wanted for Higher Order Programming Project!</a> <i>Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you.</i> - DangerBunny</div></x-turndown>

      C Offline
      C Offline
      Camilo Reyes
      wrote on last edited by
      #6
      1. Decouple vanilla JavaScript from DOM JavaScript 2) Write unit tests 3) Repeat :cool:
      M 1 Reply Last reply
      0
      • M Marc Clifton

        I find myself doing things I would never do in C# code. The two most common things are: 1) copy and paste code from one HTML page to another Why? Because making something reusable requires: a. create a separate js file b. put the functions in there c. add a </code> line to suck it in d. remember that I have these common functions in this other file when writing other pages OK, I suppose that's sort of the same steps in a real programming language, it just seems harder when working on a website. 2) everything tends to be inline code. I like to practice writing human readable and short methods when I code in C#. Conversely, when I code in Javascript, I'll do something like this (a somewhat trivial example, granted, but it makes the point): <code>$('#spinny').jqxLoader('open');</code> This is completely non-reusable and un-maintainable. Imagine hundreds of pages that all have spinny's for when the page does some sort of AJAX callback, and maybe you want to change something about the spinny behavior. So this: <pre>function showSpinny() { $('#spinny').jqxLoader('open'); }</pre> while seemingly stupid, becomes a re-usable and maintainable piece of code. I wonder what it is about Javascript that promotes these (I only cite two examples) practices? Is it just me? I don't think so, I see other developers writing the same cruft. Albeit, they're also Python developers, and I see the same cruft in their Python code. Marc <div class="signature"><a href="http://www.syncfusion.com/resources/techportal/ebooks/imperative">Imperative to Functional Programming Succinctly</a> <a href="http://www.higherorderprogramming.com/developers-1-1-1/">Contributors Wanted for Higher Order Programming Project!</a> <i>Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you.</i> - DangerBunny</div></x-turndown>

        Sander RosselS Offline
        Sander RosselS Offline
        Sander Rossel
        wrote on last edited by
        #7

        Because it's JavaScript, where this is never that, your string is actually a boolean, and array plus object is certainly not a number :D

        Read my (free) ebook Object-Oriented Programming in C# Succinctly. Visit my blog at Sander's bits - Writing the code you need. Or read my articles here on CodeProject.

        Simplicity is prerequisite for reliability. — Edsger W. Dijkstra

        Regards, Sander

        1 Reply Last reply
        0
        • M Marc Clifton

          I find myself doing things I would never do in C# code. The two most common things are: 1) copy and paste code from one HTML page to another Why? Because making something reusable requires: a. create a separate js file b. put the functions in there c. add a </code> line to suck it in d. remember that I have these common functions in this other file when writing other pages OK, I suppose that's sort of the same steps in a real programming language, it just seems harder when working on a website. 2) everything tends to be inline code. I like to practice writing human readable and short methods when I code in C#. Conversely, when I code in Javascript, I'll do something like this (a somewhat trivial example, granted, but it makes the point): <code>$('#spinny').jqxLoader('open');</code> This is completely non-reusable and un-maintainable. Imagine hundreds of pages that all have spinny's for when the page does some sort of AJAX callback, and maybe you want to change something about the spinny behavior. So this: <pre>function showSpinny() { $('#spinny').jqxLoader('open'); }</pre> while seemingly stupid, becomes a re-usable and maintainable piece of code. I wonder what it is about Javascript that promotes these (I only cite two examples) practices? Is it just me? I don't think so, I see other developers writing the same cruft. Albeit, they're also Python developers, and I see the same cruft in their Python code. Marc <div class="signature"><a href="http://www.syncfusion.com/resources/techportal/ebooks/imperative">Imperative to Functional Programming Succinctly</a> <a href="http://www.higherorderprogramming.com/developers-1-1-1/">Contributors Wanted for Higher Order Programming Project!</a> <i>Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you.</i> - DangerBunny</div></x-turndown>

          J Offline
          J Offline
          Jeremy Falcon
          wrote on last edited by
          #8

          JavaScript, like any other language, is what you make of it. There's nothing saying you can't do what you just did in your own programs to abstract logic. It's perfectly valid. Cheer up bro, you're not shaking hands with the devil until you start using Ruby. :) Anyway, where I see that JavaScript has failed miserably is allowing for things like modular development, but it was a language for the web and thus never to be compiled into a single executable. And web requests are expensive, so having 1000 modules to load an app / webpage was never feasible since it would be asking a web server for 1001 requests per page. But times have changed, especially with Node. There's nothing saying you can't write a well-written app in it, with all your bells and whistsles. The only difference being, you have to get things running manually, there is no JS bells and whistles preprocessor / add-on out of the box type thing. Maybe TypeScript in VS, but most things you have to just know about it to implement it.

          Jeremy Falcon

          1 Reply Last reply
          0
          • C Camilo Reyes
            1. Decouple vanilla JavaScript from DOM JavaScript 2) Write unit tests 3) Repeat :cool:
            M Offline
            M Offline
            Marc Clifton
            wrote on last edited by
            #9

            Camilo Reyes wrote:

            Decouple vanilla JavaScript from DOM JavaScript

            I can't even think of how to do that without classes, events, data binding, etc. anymore. I guess that's why there's all those frameworks like Backbone, none of which I've ever experienced a "wow, this is a great solution." Seems like they're all band-aids sitting on top of a bad language. Marc

            Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project! Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

            C 1 Reply Last reply
            0
            • M Marc Clifton

              Afzaal Ahmad Zeeshan wrote:

              Using JavaScript for any of my production application

              So what do you use for client-side web development? I still have to get into typescript, but it just seems like another layer of what can go wrong, and I like to recognize the code as mine when I'm debugging. Marc

              Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project! Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

              A Offline
              A Offline
              Afzaal Ahmad Zeeshan
              wrote on last edited by
              #10

              Quote:

              So what do you use for client-side web development?

              I don't do web anymore. However, I do have a home server built up for family purposes and entertainment; where I keep the few of the services that my family needs, such as image sharing, music streaming etc — I will not trust Facebook, Twitter and even Google+ with images of my family and what we are cooking for dinner. The web application has its 85%+ part built up as a Web API instead of plain HTML web app. And the clients are Android devices, a Windows Phone, a bunch of Desktop applications. They save me from having to use JavaScript. ;-)

              The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

              1 Reply Last reply
              0
              • M Marc Clifton

                I find myself doing things I would never do in C# code. The two most common things are: 1) copy and paste code from one HTML page to another Why? Because making something reusable requires: a. create a separate js file b. put the functions in there c. add a </code> line to suck it in d. remember that I have these common functions in this other file when writing other pages OK, I suppose that's sort of the same steps in a real programming language, it just seems harder when working on a website. 2) everything tends to be inline code. I like to practice writing human readable and short methods when I code in C#. Conversely, when I code in Javascript, I'll do something like this (a somewhat trivial example, granted, but it makes the point): <code>$('#spinny').jqxLoader('open');</code> This is completely non-reusable and un-maintainable. Imagine hundreds of pages that all have spinny's for when the page does some sort of AJAX callback, and maybe you want to change something about the spinny behavior. So this: <pre>function showSpinny() { $('#spinny').jqxLoader('open'); }</pre> while seemingly stupid, becomes a re-usable and maintainable piece of code. I wonder what it is about Javascript that promotes these (I only cite two examples) practices? Is it just me? I don't think so, I see other developers writing the same cruft. Albeit, they're also Python developers, and I see the same cruft in their Python code. Marc <div class="signature"><a href="http://www.syncfusion.com/resources/techportal/ebooks/imperative">Imperative to Functional Programming Succinctly</a> <a href="http://www.higherorderprogramming.com/developers-1-1-1/">Contributors Wanted for Higher Order Programming Project!</a> <i>Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you.</i> - DangerBunny</div></x-turndown>

                M Offline
                M Offline
                Mark_Wallace
                wrote on last edited by
                #11

                For me, it's a "fit for purpose" thing. I see js as being for "disposable" pages (which is what a fair proportion of the Interwebs comprise), and it's absolutely perfect for that, because all you need is either a quick "copy & paste and get the page up" solution, or a page template that already contains the required routines, so you don't even have to copy & paste anything. If you then want to set up a page that governs those pages, it's simple, quick, and up on the web before your second coffee. No coding standards, no databases, and no time at all "wasted" in getting the product (the content of the pages) to the customer (the web-surfer). A professional site for a business, however, needs content management, document management, library-based code injection, and at least one database -- it's no longer "pages"; it's now a program/application, which most certainly does need more than js can offer. However, even professional sites contain a lot of "pages", which don't need all the froufrou, so why waste twelve hours of a developer's time on what can be called "infrastructure work", when all he really needs to do is C & P & tweak a bit of js to get the content up on the site, where the customer can access it? Not everything needs to be wrapped in swaddling, carefully bandaged, then clad in perfectly-welded iron. Some things just need to be available to the customer.

                I wanna be a eunuchs developer! Pass me a bread knife!

                M 1 Reply Last reply
                0
                • M Mark_Wallace

                  For me, it's a "fit for purpose" thing. I see js as being for "disposable" pages (which is what a fair proportion of the Interwebs comprise), and it's absolutely perfect for that, because all you need is either a quick "copy & paste and get the page up" solution, or a page template that already contains the required routines, so you don't even have to copy & paste anything. If you then want to set up a page that governs those pages, it's simple, quick, and up on the web before your second coffee. No coding standards, no databases, and no time at all "wasted" in getting the product (the content of the pages) to the customer (the web-surfer). A professional site for a business, however, needs content management, document management, library-based code injection, and at least one database -- it's no longer "pages"; it's now a program/application, which most certainly does need more than js can offer. However, even professional sites contain a lot of "pages", which don't need all the froufrou, so why waste twelve hours of a developer's time on what can be called "infrastructure work", when all he really needs to do is C & P & tweak a bit of js to get the content up on the site, where the customer can access it? Not everything needs to be wrapped in swaddling, carefully bandaged, then clad in perfectly-welded iron. Some things just need to be available to the customer.

                  I wanna be a eunuchs developer! Pass me a bread knife!

                  M Offline
                  M Offline
                  Marc Clifton
                  wrote on last edited by
                  #12

                  Mark_Wallace wrote:

                  it's no longer "pages"; it's now a program/application, which most certainly does need more than js can offer.

                  Yup. :)

                  Mark_Wallace wrote:

                  However, even professional sites contain a lot of "pages", which don't need all the froufrou,

                  Quite true. Unfortunately, the web apps I've been developing are anything but froufrou, I can't think of a single page (except the About page) that doesn't have AJAX calls, event triggers, and data binding of some sort. Marc

                  Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project! Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

                  M 1 Reply Last reply
                  0
                  • M Marc Clifton

                    Mark_Wallace wrote:

                    it's no longer "pages"; it's now a program/application, which most certainly does need more than js can offer.

                    Yup. :)

                    Mark_Wallace wrote:

                    However, even professional sites contain a lot of "pages", which don't need all the froufrou,

                    Quite true. Unfortunately, the web apps I've been developing are anything but froufrou, I can't think of a single page (except the About page) that doesn't have AJAX calls, event triggers, and data binding of some sort. Marc

                    Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project! Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

                    M Offline
                    M Offline
                    Mark_Wallace
                    wrote on last edited by
                    #13

                    Then js shouldn't be used at all, because it's not fit-for-purpose for such things. Try to get this idea through to the people who make decisions about what to use. Put it in a way that makes it understandable -- e.g. tell them that they don't want their trousers made out of the same material as their shirts, even though they wear both.

                    I wanna be a eunuchs developer! Pass me a bread knife!

                    D 1 Reply Last reply
                    0
                    • M Mark_Wallace

                      Then js shouldn't be used at all, because it's not fit-for-purpose for such things. Try to get this idea through to the people who make decisions about what to use. Put it in a way that makes it understandable -- e.g. tell them that they don't want their trousers made out of the same material as their shirts, even though they wear both.

                      I wanna be a eunuchs developer! Pass me a bread knife!

                      D Offline
                      D Offline
                      Dan Neely
                      wrote on last edited by
                      #14

                      Mark_Wallace wrote:

                      Put it in a way that makes it understandable -- e.g. tell them that they don't want their trousers made out of the same material as their shirts, even though they wear both.

                      I'm not sure what you're getting on about; but I find cotton athletic shorts made from the same sort of fabric as the t-shirts I wear in my free time much more comfortable than the dressier pants I need to wear to work. :-\

                      Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                      M 1 Reply Last reply
                      0
                      • D Dan Neely

                        Mark_Wallace wrote:

                        Put it in a way that makes it understandable -- e.g. tell them that they don't want their trousers made out of the same material as their shirts, even though they wear both.

                        I'm not sure what you're getting on about; but I find cotton athletic shorts made from the same sort of fabric as the t-shirts I wear in my free time much more comfortable than the dressier pants I need to wear to work. :-\

                        Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                        M Offline
                        M Offline
                        Mark_Wallace
                        wrote on last edited by
                        #15

                        Pic or... ... On second thought, kindly disregard this posting.

                        I wanna be a eunuchs developer! Pass me a bread knife!

                        1 Reply Last reply
                        0
                        • M Marc Clifton

                          Camilo Reyes wrote:

                          Decouple vanilla JavaScript from DOM JavaScript

                          I can't even think of how to do that without classes, events, data binding, etc. anymore. I guess that's why there's all those frameworks like Backbone, none of which I've ever experienced a "wow, this is a great solution." Seems like they're all band-aids sitting on top of a bad language. Marc

                          Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project! Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

                          C Offline
                          C Offline
                          Camilo Reyes
                          wrote on last edited by
                          #16

                          Of course! The mindset of the frameworks is: "JavaScript sucks! So MOAR JavaScript." Is this not ironic? Vanilla JS is a complete paradigm shift. When you write C#, would you write it like you write Python? A good craftsman never blames the tool.

                          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