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 (Darkly)
  • No Skin
Collapse

Chebucto Regional Softball Club

  1. Home
  2. Uncategorized
  3. How do I teach myself to care more about writing efficient code?
A forum for discussing and organizing recreational softball and baseball games and leagues in the greater Halifax area.

How do I teach myself to care more about writing efficient code?

Scheduled Pinned Locked Moved Uncategorized
11 Posts 6 Posters 1 Views
  • 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.
  • myrmepropagandistF myrmepropagandist

    How do I teach myself to care more about writing efficient code? Coming from math I am happy if it simply always works and if you can read it and know why. But I would like to set a better example for my students. Unlike the math profs who taught me.

    Dead simple but more theoretical things like search optimization might be a place to start?

    mccM This user is from outside of this forum
    mccM This user is from outside of this forum
    mcc
    wrote last edited by
    #2

    @futurebird Hm.

    Dead serious suggestion from someone with experience:

    Don't think about efficiency as an end in itself. Think about efficiency *as it relates to a specific application*. *Why* do you want efficiency? Do you want better time efficiency? Better memory-space efficiency? Better *responsiveness* (which is very different from time effiiciency)? Do you have realtime constraints (a third layer, past responsiveness?)

    The *reason* you want efficiency changes *how* you seek efficiency.

    ? 1 Reply Last reply
    0
    • myrmepropagandistF myrmepropagandist

      How do I teach myself to care more about writing efficient code? Coming from math I am happy if it simply always works and if you can read it and know why. But I would like to set a better example for my students. Unlike the math profs who taught me.

      Dead simple but more theoretical things like search optimization might be a place to start?

      ? Offline
      ? Offline
      Guest
      wrote last edited by
      #3

      @futurebird I'm not sure how to change yourself, but I find writing efficient code absolutely joyful - in many cases, it's like simplifying a mathematical proof to a more clear and elegant formation. There are other parts of writing efficient code that _don't_ have that same "I'm making it better and simpler" aspect, but perhaps the spot where they overlap will be one where you can find joy in it?

      One of the starting points of writing efficient code is finding a good match between the data and problem you're solving and the data structures you're using to manipulate it. The right match can often be really elegant - again, in the way mathematicians use the term elegant, as well as performant. Like "I could solve this problem with a binary tree, or I just happened to notice I could use a hash table instead and make it faster", or whatnot.

      Do you have some examples of code areas / applications where you wish you could care more about it? Happy to dive in.

      (This is kind of my thing professionally, so, um, feel free to also say 'ok that's enough'. 😃 )

      myrmepropagandistF 1 Reply Last reply
      0
      • mccM mcc

        @futurebird Hm.

        Dead serious suggestion from someone with experience:

        Don't think about efficiency as an end in itself. Think about efficiency *as it relates to a specific application*. *Why* do you want efficiency? Do you want better time efficiency? Better memory-space efficiency? Better *responsiveness* (which is very different from time effiiciency)? Do you have realtime constraints (a third layer, past responsiveness?)

        The *reason* you want efficiency changes *how* you seek efficiency.

        ? Offline
        ? Offline
        Guest
        wrote last edited by
        #4

        @mcc @futurebird this is a fantastic bit of advice, and I want to add an additional flavor of efficiency: Efficiency of code readability.

        Sometimes you don't need the performance of a tightly coded loop, your memory usage is fine, and it runs fast enough, but you *do* want to be able to understand the code in a month when you come back after forgetting all of it

        1 Reply Last reply
        0
        • myrmepropagandistF myrmepropagandist

          How do I teach myself to care more about writing efficient code? Coming from math I am happy if it simply always works and if you can read it and know why. But I would like to set a better example for my students. Unlike the math profs who taught me.

          Dead simple but more theoretical things like search optimization might be a place to start?

          Bjørnar (he/him)B This user is from outside of this forum
          Bjørnar (he/him)B This user is from outside of this forum
          Bjørnar (he/him)
          wrote last edited by
          #5

          @futurebird There are many math problems that take a long time to compute with inefficient code, but can be solved really, really fast with a better solution. Matt Parker frequently writes inexpert Python code for a math problem he's interested in and sometimes some of his viewers are interested enough to write alternate and faster solutions
          https://youtu.be/c33AZBnRHks?si=-ae9e1qSUG7fyw8z

          myrmepropagandistF 1 Reply Last reply
          0
          • Bjørnar (he/him)B Bjørnar (he/him)

            @futurebird There are many math problems that take a long time to compute with inefficient code, but can be solved really, really fast with a better solution. Matt Parker frequently writes inexpert Python code for a math problem he's interested in and sometimes some of his viewers are interested enough to write alternate and faster solutions
            https://youtu.be/c33AZBnRHks?si=-ae9e1qSUG7fyw8z

            myrmepropagandistF This user is from outside of this forum
            myrmepropagandistF This user is from outside of this forum
            myrmepropagandist
            wrote last edited by
            #6

            @btuftin

            Oh god. I would totally run code for a month if I knew it'd do what I want. This is just the tendency I'm talking about.

            1 Reply Last reply
            0
            • myrmepropagandistF myrmepropagandist shared this topic
            • ? Guest

              @futurebird I'm not sure how to change yourself, but I find writing efficient code absolutely joyful - in many cases, it's like simplifying a mathematical proof to a more clear and elegant formation. There are other parts of writing efficient code that _don't_ have that same "I'm making it better and simpler" aspect, but perhaps the spot where they overlap will be one where you can find joy in it?

              One of the starting points of writing efficient code is finding a good match between the data and problem you're solving and the data structures you're using to manipulate it. The right match can often be really elegant - again, in the way mathematicians use the term elegant, as well as performant. Like "I could solve this problem with a binary tree, or I just happened to notice I could use a hash table instead and make it faster", or whatnot.

              Do you have some examples of code areas / applications where you wish you could care more about it? Happy to dive in.

              (This is kind of my thing professionally, so, um, feel free to also say 'ok that's enough'. 😃 )

              myrmepropagandistF This user is from outside of this forum
              myrmepropagandistF This user is from outside of this forum
              myrmepropagandist
              wrote last edited by
              #7

              @dave_andersen

              It's dead simple things like finding 5 letter words that meet all of the conditions thrown up by wordle results.

              I like this problem for my students, but it shouldn't take 10 seconds to do that. Even with a list of tens of thousands of words and a few dozen conditions.

              And I ... know what some of the problems are: it's more intuitive to make a list of invalid words then remove them from the valid ones.

              And I should use "continue" more ...

              1 Reply Last reply
              0
              • myrmepropagandistF myrmepropagandist

                How do I teach myself to care more about writing efficient code? Coming from math I am happy if it simply always works and if you can read it and know why. But I would like to set a better example for my students. Unlike the math profs who taught me.

                Dead simple but more theoretical things like search optimization might be a place to start?

                CaliC This user is from outside of this forum
                CaliC This user is from outside of this forum
                Cali
                wrote last edited by
                #8

                @futurebird From what I’ve seen, the general guidelines are to focus on clarity/readability. Everything else will become clear when it is needed. As a student knowing how to write code that I can actually understand in six months to a year after writing it seems a more useful skill.

                myrmepropagandistF 3 Replies Last reply
                0
                • CaliC Cali

                  @futurebird From what I’ve seen, the general guidelines are to focus on clarity/readability. Everything else will become clear when it is needed. As a student knowing how to write code that I can actually understand in six months to a year after writing it seems a more useful skill.

                  myrmepropagandistF This user is from outside of this forum
                  myrmepropagandistF This user is from outside of this forum
                  myrmepropagandist
                  wrote last edited by
                  #9

                  @cali

                  Well I do teach them that. They know I don't take assignments without readme.txt in the folder.

                  What the heck is this?
                  Why would I run it?
                  How do I use it?

                  Explain.

                  1 Reply Last reply
                  0
                  • CaliC Cali

                    @futurebird From what I’ve seen, the general guidelines are to focus on clarity/readability. Everything else will become clear when it is needed. As a student knowing how to write code that I can actually understand in six months to a year after writing it seems a more useful skill.

                    myrmepropagandistF This user is from outside of this forum
                    myrmepropagandistF This user is from outside of this forum
                    myrmepropagandist
                    wrote last edited by
                    #10

                    @cali

                    And to be clear, I teach *beginner* programmers and I don't really want them focused on efficiency. I just feel bad that I don't know as much about it mostly due to never needing to and being lazy.

                    So. Time to learn.

                    1 Reply Last reply
                    0
                    • CaliC Cali

                      @futurebird From what I’ve seen, the general guidelines are to focus on clarity/readability. Everything else will become clear when it is needed. As a student knowing how to write code that I can actually understand in six months to a year after writing it seems a more useful skill.

                      myrmepropagandistF This user is from outside of this forum
                      myrmepropagandistF This user is from outside of this forum
                      myrmepropagandist
                      wrote last edited by
                      #11

                      @cali

                      Also a lot of the lessons I've developed are designed around getting the computer to do something the way that a person would to help them understand algorithms from math.

                      For example factoring quadratics. If you know it factors you can just use the formula. Done.

                      But, we write a program that generates the steps of the "AC Method" because it's just such a good way to learn about lists, and functions.

                      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.
                      Powered by NodeBB Contributors
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups