• Activity
  • Votes
  • Comments
  • New
  • All activity
    1. Code Quality Tip: Wrapping external libraries.

      Preface Occasionally I feel the need to touch on the subject of code quality, particularly because of the importance of its impact on technical debt, especially as I continue to encounter the...

      Preface

      Occasionally I feel the need to touch on the subject of code quality, particularly because of the importance of its impact on technical debt, especially as I continue to encounter the effects of technical debt in my own work and do my best to manage it. It's a subject that is unfortunately not emphasized nearly enough in academia.


      Background

      As a refresher, technical debt is the long-term cost of the design decisions in your code. These costs can manifest in different ways, such as greater difficulty in understanding what your code is doing or making non-breaking changes to it. More generally, these costs manifest as additional time and resources being spent to make some kind of change.

      Sometimes these costs aren't things you think to consider. One such consideration is how difficult it might be to upgrade a specific technology in your stack. For example, what if you've built a back-end system that integrates with AWS and you suddenly need to upgrade your SDK? In a small project this might be easy, but what if you've built a system that you've been maintaining for years and it relies heavily on AWS integrations? If the method names, namespaces, argument orders, or anything else has changed between versions, then suddenly you'll need to update every single reference to an AWS-related tool in your code to reflect those changes. In larger software projects, this could be a daunting and incredibly expensive task, spanning potentially weeks or even months of work and testing.

      That is, unless you keep those references to a minimum.


      A Toy Example

      This is where "wrapping" your external libraries comes into play. The concept of "wrapping" basically means to create some other function or object that takes care of operating the functions or object methods that you really want to target. One example might look like this:

      <?php
      
      class ImportedClass {
          public function methodThatMightBecomeModified($arg1, $arg2) {
              // Do something.
          }
      }
      
      class ImportedClassWrapper {
          private $class_instance = null;
      
          private function getInstance() {
              if(is_null($this->class_instance)) {
                  $this->class_instance = new ImportedClass();
              }
      
              return $this->class_instance;
          }
      
          public function wrappedMethod($arg1, $arg2) {
              return $this->getInstance()->methodThatMightBecomeModified($arg1, $arg2);
          }
      }
      
      ?>
      

      Updating Tools Doesn't Have to Suck

      Imagine that our ImportedClass has some important new features that we need to make use of that are only available in the most recent version, and we're several versions behind. The problem, of course, is that there were a lot of changes that ended up being made between our current version and the new version. For example, ImportedClass is now called NewImportedClass. On top of that, methodThatMightBecomeModified is now called methodThatWasModified, and the argument order ended up getting switched around!

      Now imagine that we were directly calling new ImportedClass() in many different places in our code, as well as directly invoking methodThatMightBecomeModified:

      <?php
      
      $imported_class_instance = new ImportedClass();
      $imported_class_instance->methodThatMightBeModified($val1, $val2);
      
      ?>
      

      For every single instance in our code, we need to perform a replacement. There is a linear or--in terms of Big-O notation--a complexity of O(n) to make these replacements. If we assume that we only ever used this one method, and we used it 100 times, then there are 100 instances of new ImportClass() to update and another 100 instances of the method invocation, equaling 200 lines of code to change. Furthermore, we need to remember each of the replacements that need to be made and carefully avoid making any errors in the process. This is clearly non-ideal.

      Now imagine that we chose instead to use the wrapper object:

      <?php
      
      $imported_class_wrapper = new ImportedClassWrapper();
      $imported_class_wrapper->wrappedMethod($val1, $val2);
      
      ?>
      

      Our updates are now limited only to the wrapper class:

      <?php
      
      class ImportedClassWrapper {
          private $class_instance = null;
      
          private function getInstance() {
              if(is_null($this->class_instance)) {
                  $this->class_instance = new NewImportedClass();
              }
      
              return $this->class_instance;
          }
      
          public function wrappedMethod($arg1, $arg2) {
              return $this->getInstance()->methodThatWasModified($arg2, $arg1);
          }
      }
      
      ?>
      

      Rather than making changes to 200 lines of code, we've now made changes to only 2. What was once an O(n) complexity change has now turned into an O(1) complexity change to make this upgrade. Not bad for a few extra lines of code!


      A Practical Example

      Toy problems are all well and good, but how does this translate to reality?

      Well, I ran into such a problem myself once. Running MongoDB with PHP requires the use of an external driver, and this driver provides an object representing a MongoDB ObjectId. I needed to perform a migration from one hosting provider over to a new cloud hosting provider, with the application and database services, which were originally hosted on the same physical machine, hosted on separate servers. For security reasons, this required an upgrade to a newer version of MongoDB, which in turn required an upgrade to a newer version of the driver.

      This upgrade resulted in many of the calls to new MongoId() failing, because the old version of the driver would accept empty strings and other invalid ID strings and default to generating a new ObjectId, whereas the new version of the driver treated invalid ID strings as failing errors. And there were many, many cases where invalid strings were being passed into the constructor.

      Even after spending hours replacing the (literally) several dozen instances of the constructor calls, there were still some places in the code where invalid strings managed to get passed in. This made for a very costly upgrade.

      The bugs were easy to fix after the initial replacements, though. After wrapping new MongoId() inside of a wrapper function, a few additional conditional statements inside of the new function resolved the bugs without having to dig around the rest of the code base.


      Final Thoughts

      This is one of those lessons that you don't fully appreciate until you've experienced the technical debt of an unwrapped external library first-hand. Code quality is an active effort, but a worthwhile one. It requires you to be willing to throw away potentially hours or even days of work when you realize that something needs to change, because you're thinking about how to keep yourself from banging your head against a wall later down the line instead of thinking only about how to finish up your current task.

      "Work smarter, not harder" means putting in some hard work upfront to keep your technical debt under control.

      That's all for now, and remember: don't be fools, wrap your external tools.

      23 votes
    2. I would like to get into drones, any tips?

      I bought one of those cheap miniature drones that are flimsy but overall pretty fun to start with. Now, I have the bug to get something with a camera, more flight time, and can withstand the wind....

      I bought one of those cheap miniature drones that are flimsy but overall pretty fun to start with. Now, I have the bug to get something with a camera, more flight time, and can withstand the wind. Any suggestions on what I could get <$150 that would be a good investment.

      Any maintenance tips or flying in public tips?

      9 votes
    3. A layperson's introduction to Thermodynamics, part 2: Equilibrium, phase changes and steam engines

      Intro Hello everyone, Today we cover equilibriums and phase changes. Through that we will get a basic understanding of how things like pressure, temperature, density, volume, etc. are related. The...

      Intro

      Hello everyone,

      Today we cover equilibriums and phase changes. Through that we will get a basic understanding of how things like pressure, temperature, density, volume, etc. are related.

      The previous chapter can be found here: https://tildes.net/~science/8ao/. I highly recommend that you read it before continuing.

      A collection of all topics covered can be found here: https://tildes.net/~tildes/8al/.

      Subject

      Summarized

      "Equilibrium" is fancy word for "balance". A system is in equilibrium when it is in balance with the surrounding systems. Any system will naturally attempt to be in equilibrim, and will adapt its physical properties to do so.

      A phase change is the transition of matter from a state (solid, liquid, gas, or plasma) to a different state. This happens due to a change in internal energy, changing how a material is bonded.

      Now that we have it summarised, lets dig a bit deeper.

      Equilibrium

      A system always tries to be in balance with its surrounding systems. We maybe don't think about this a lot, but we are all very familiar with this principle since we observe it every day.

      If you have a cup of hot cocoa, it will cool down until it has reached ambient temperature. At this point, the cocoa is considered to be in "thermal equilibrium". If we fill a balloon with air, it will expand. It will do so until the air inside the balloon has the same pressure as the air outside the balloon. At this point, the balloon is considered to be in "barometric (pressure) equilibrium".

      Just like when we talk about energy, there is a relationship when we talk about equilibriums. We have something we call (you may remember this from basic chemistry) an "ideal gas". An ideal gas is a good way of looking at this principle. Since the temperature, volume and pressure have a direct relationship.

      Pressure-volume-temperature diagram for ideal gases.

      In the diagram above we can see that if we change one of the three variables, then one (or both) of the other two variables has to change too. For instance, if we heat some air in a canister, the air will try to expand. But being unable to change in volume, it will instead increase pressure. [1]

      Phase changes

      Any material has a set of phases. The ones we'll discuss are the solid, liquid and gaseous phases. Unless we control the material's environment very carefully, materials will always follow this order when energy is added. Solid becomes liquid, liquid becomes gas, and vice versa. For instance water; ice (solid) becomes water (liquid), water becomes steam (gas). So each of these transformations is a phase change.

      So when water is solid (ice), the molecules are in a grid. The molecules do not move around much, maybe a little bit where they stand. But they all still stand in a grid.

      When the water gets heated up, the molecules will start to move. Molecules have a natural attraction to each other due to subatomic forces like the van der Waals force. So the molecules will no longer stay in a grid, but they will still keep each other close due to this attraction. So a material that sticks together but freely moves around is called a liquid.

      Once the material overcomes this natural attraction, the molecules can go anywhere they want. And that's when we get a gas. Or steam, in the case of water. All of this applies even for materials we don't usually imagine would melt or evaporate, for instance steel.

      Here is a visual representation of the three states.

      Now comes the fun part. Ice is water that is at 0 degrees Celcius or below. Liquid water is water that is 0 degrees and above. But wait! Does that mean that water can be both solid and liquid at the same temperature? Yes, indeed. A material requires a certain amount of internal energy to become liquid. That is why internal energy and temperature is often used interchangeably, but is not exactly the same.

      The water molecules in ice will use the supplied energy to get excited and start moving around. This continues until the solid-liquid water reaches a point where all molecules move around. At that point it has completely become a liquid. While water is in solid-liquid state, the amount of internal energy dictates how much is liquid and how much is solid. The exact same thing happens with water at 100 degrees. It can be steam or liquid, but not fully either until it reaches a certain amount of internal energy.

      Here is a diagram of this process.

      Another fun tidbit that makes water special: Water has a lower density as a solid than it has as a liquid, when both are at 0 degrees Celcius. This means that per unit of volume ice weighs less than (liquid) water. Therefore ice floats on top of water. This is the only material that behaves in this way. And thats extremely important to our existince, since it helps regulate heat in the ocean.

      Steam engines (and implication)

      We have learned a few new things today. But there is one really important wrinkle to all of this. A system always will try to be in balance. And this we can exploit. Pressure is a type of "pushing". So thats a type of work! And an increase in thermal energy can lead to an increase in temperature. We remember that from the ideal gas. So if we cleverly organize our system, we can create work from heat! This is the basis behind most heat engines (simplified a ton). We supply thermal energy to some gas or fluid, and extract work from this gas or fluid.

      A classical example is the steam engine. We have water inside a closed system. When we heat up the water, it will turn into steam. And this steam will want to be much less dense than water. As a consequence, the pressure inside the water tank increases drastically. We release a small amount of this steam into a closed piston.

      Here is an animation of this in action.

      The piston suddenly gets a high pressure level. As we remember, it will want to be in equilibrium with its surroundings. Currently the pressure inside the piston is much higher than outside the piston. As we remember from the ideal gas law, a higher volume will mean a lower pressure. So the piston will be moved, as the steam expands to reach a pressure balance. The movement from the piston will drive something, like a wheel. The steam is removed from the expanded piston, and the piston will return to its closed position.[2] Then the process is repeated again and again, to have the piston continously move something.

      All that from a bit of water in a tank and some supplied heat.

      Whats next?

      Next time we will talk about another important property. Entropy! In the previous topic I had a lot of questions regarding the quality of energy types, and what specifies heat from work on an intrinsic level. Entropy is the big answer to this. From that we will also cover the heat death of the universe, which would be a good introduction to "a laypersons introduction to nihilism" if we have any philosophers here.

      Note

      [1] For solid and fluid materials (as well as non-ideal gassess) this becomes a lot more complicated. If we ever do a "layperson's intro to fluid mechanics" we will cover it then.
      [2] This described design is very inefficient and very simplified. Usually the piston is made so steam is supplied in turns supplied to either side of the piston. Then the work will both removed the steam that already performed work as well as move the piston. That way you can have continous movement in both directions.

      See for instance this image.

      17 votes
    4. This is the most beautiful song I've ever heard - and it's country

      okay okay what in the actual fuck so i'm a southern boy myself. ever since i was a little kid my mom tried so hard to make me into a little cowboy. i was bought cowboy boots, cowboy hats, and...

      okay

      okay

      what in the actual fuck

      so i'm a southern boy myself. ever since i was a little kid my mom tried so hard to make me into a little cowboy. i was bought cowboy boots, cowboy hats, and boot-cut blue jeans. even at my young toddler age, i detested all of it lmao.

      i was always a city boy.

      i loved the idea of big cities like new york, los angeles, chicago, etc. hell, i even fantasized about spending my days in dallas of all places when i was in school daydreaming.

      my music tastes trended as far alternative as my style in clothes and girls - in middle school i listened to everything from Shinedown to Disturbed to A Day to Remember to Dimmu Borgir (spooky!)

      when i was in higschool - everything from showtunes (Phantom of the Opera) to Eminem to more metal (We Butter The Bread With Butter) to indie rock (Mumford and Sons)

      but never in my life was country even a blip on my radar.

      sure there were one or two songs you pick up that you get to know like

      "Back When" x Tim McGraw

      "Pretty Good at Drinking Beer" x Billy Currington

      (my stepdad is a country musician. it's hard not to pick up something here and there.)


      but

      i just discovered a new genre of music (new to me).

      i just discovered a new sound.

      i just discovered my new favorite song.

      and it's country.

      Hank Williams III - "Ghost to a Ghost"

      like oh my God

      i just earlier this week discovered something called "Outlaw Country". i'd somehow managed to go my whole life without ever coming into contact with this.

      will you listen to this fucking song??

      it's the same classic country instruments that we've heard for decades.

      paired with dark, angsty, grungy, emo lyrics.

      with an incredibly metal breakdown serving as the chorus.

      with a terrifically orchestral and bluesy viola/violin backing the entire song.

      WHAT IN TARNATION!?

      why did no one ever tell me there was an entire subgenre of emo cowboys running around talking about sleeping on the blacktop, relationship struggles, and popping hella pills


      i now listen to country music and i'm never admitting it to my parents lmao.

      if you didn't catch the link earlier, this song is a fucking work of art and literally brought me from awe to tears to fuck yeah! all in the span of six minutes in public in this cafe.

      https://youtu.be/RoJwrSTIZM0

      i think i've looped it back 7-8 times in a row now.

      i'm floored.


      what did you lot think?

      do you listen to outlaw country?

      please pass on any recommendations you have

      8 votes
    5. On YouTube and EU Article 13

      If you've been following tech news somewhat recently, you've surely heard about Article 13- the one where the EU essentially requires all content hosts to have extremely strict copyright checking...

      If you've been following tech news somewhat recently, you've surely heard about Article 13- the one where the EU essentially requires all content hosts to have extremely strict copyright checking tools and have automated takedown of any potentially copyrighted works.

      That got put on the backburner for a little bit, but now it's back with a vote being held in early 2019.

      YouTube, being one of, if not the largest content hosts in the world, is greatly affected by this motion. In fact, they have a whole website designed to encourage their creators to talk about A13 in their videos. The page very subtly hints at massive service changes that will happen in the EU if this actually ends up passing.

      The CEO of YouTube, Susan Wojcicki, has also written an op-ed for Financial times (linked to official YT blog since it's free there) about the issues facing YT if A13 passes.

      I haven't heard anything from official sources, but I've heard on the rumor mill that YouTube will completely suspend creators in the EU, not allowing them to upload any content, and potentially even removing their existing content from YouTube.

      What if this passes? YouTube is one of the biggest sources of free knowledge and entertainment we have today, and it's become engrained into the internet as it is today.

      With all this, I simply ask, "what's next?"

      9 votes
    6. ~music Listening Club 21 - At Folsom Prison

      21 weeks and yet another classic record discussion: At Folsom Prison by Johnny Cash! At Folsom Prison is a live album and 27th overall album by Johnny Cash, released on Columbia Records in May...

      21 weeks and yet another classic record discussion: At Folsom Prison by Johnny Cash!

      At Folsom Prison is a live album and 27th overall album by Johnny Cash, released on Columbia Records in May 1968. After his 1955 song "Folsom Prison Blues", Cash had been interested in recording a performance at a prison. His idea was put on hold until 1967, when personnel changes at Columbia Records put Bob Johnston in charge of producing Cash's material. Cash had recently controlled his drug abuse problems, and was looking to turn his career around after several years of limited commercial success. Backed with June Carter, Carl Perkins and the Tennessee Three, Cash performed two shows at Folsom State Prison in California on January 13, 1968. The resulting album consisted of fifteen tracks from the first show and two tracks from the second.

      Despite little initial investment by Columbia, the album was a hit in the United States, reaching number one on the country charts and the top 15 of the national album chart. The lead single from the album, a live version of "Folsom Prison Blues", was a top 40 hit, Cash's first since 1964's "Understand Your Man". At Folsom Prison received positive reviews and revitalized Cash's career, becoming the first in a series of live albums recorded at prisons that includes "At San Quentin" (1969), "Pa Osteraker" (1973), and "A Concert Behind Prison Walls" (1976). The album was rereleased with additional tracks in 1999, a three-disc set in 2008, and a five LP box set with bonus rehearsals in 2018 for Record Store Day. It was certified three times Platinum on March 27, 2003 by the Recording Industry Association of America for US sales exceeding three million.

      Here's the place to discuss your thoughts on the record, your history with it or the artist, and basically talk about whatever you want to that goes along with At Folsom Prison! Remember that this is intended to be a slow moving thing, feel free to take your time and comment at any point in the week!

      If you'd like to stream or buy the album, it can be found on most platforms here.

      Don't forget to nominate and vote for next week's obscure record in response to this comment!

      8 votes
    7. Meta-post for the "a layperson's introduction to..." series

      What's this? This post contains all entries of the "a layperson's introduction to" series. I will keep this thread up to date and sorted. This means this post is an excellent opportunity to try...

      What's this?

      This post contains all entries of the "a layperson's introduction to" series. I will keep this thread up to date and sorted. This means this post is an excellent opportunity to try out the bookmarking feature!

      Physics

      Quantum Physics

      Basics of quantum physics

      Topic Date Subtopics Author
      Spin and quantisation part 1 01 Nov 2018 spin, quantisation @wanda-seldon
      Spin and quantisation part 2 03 Nov 2018 superposition, observing, collapse @wanda-seldon
      The nature of light and matter part 1 16 Nov 2018 light, matter, wave-particle duality, photoelectric effect, double-slit experiment @wanda-seldon

      Material Science

      Topic Date Subtopics Author
      Spintronics 18 Jul 2018 spintronics, electronics, transistors @wanda-seldon
      Quantum Oscillations 28 Oct 2018 quantum oscillations @wanda-seldon
      LEDs 10 Nov 2018 leds, electronics, diodes, semiconductors @wanda-seldon
      Spintronics Memory 22 Jun 2019 spintronics @wanda-seldon

      Classical physics

      Thermodynamics

      Topic Date Subtopics Author
      Thermodynamics part 1 07 Nov 2018 energy, work, heat, systems @ducks
      Thermodynamics part 2 13 Nov 2018 equilibrium, phase changes, ideal gas @ducks
      Thermodynamics part 3 24 Nov 2018 @ducks

      Computer Science

      Artificial Intelligence

      Topic Date Subtopics Author
      Genetic Algorithms 18 Jun 2019 algorithm, genetic algorithm Soptik
      41 votes
    8. Creative process discussion

      I'd love to hear about how you create your favorite works. Of anything. How did you write your best music? How did you create your favorite character in a story you wrote? Anything of the sort....

      I'd love to hear about how you create your favorite works. Of anything. How did you write your best music? How did you create your favorite character in a story you wrote? Anything of the sort.

      I'd love to hear all the different processes people have. It's really quite an interesting topic of discussion, for me.

      Personally, I grab a cup of coffee and listen to instrumental music (mostly avant-garde jazz [Coltrane, Washington, etc]) while creating the world of the story I'm writing. There's something very productive-feeling about being wired on caffeine while also having a constant noise in your ears. It's how I compose some of my better characters and settings.

      Due to my constant writer's block phenomenon, sometimes I'll smoke some pot to get past it. It's almost like phasing through a wall you can't jump over. There's something lifting about it.

      16 votes
    9. Had to say goodbye to a friend today and it stings so bad :(

      So I'm doing my GED at the moment and I'm in the same couple of classes this gal. It's only 3 months into the semester and we won't be in the same classes next semester anyway. Nevertheless,...

      So I'm doing my GED at the moment and I'm in the same couple of classes this gal. It's only 3 months into the semester and we won't be in the same classes next semester anyway. Nevertheless, despite it only being 3 months we quickly became acquainted and within the last month or so we've become friends. Last week however, her boyfriend broke up with her and today he kicked her out of his apartment - so she's homeless. And in order to not live on the damn street she's going back to Norway (she's only been here in Denmark for a bit over a year) to live with her family until she can find somewhere to live here - she still has another semester to go until she's done with school here, so it need only be temporary.

      She's leaving tonight and so I asked if she wanted to meet after school today. We did and talked for a couple of hours at a cafe - and it was pretty nice despite her situation being total shit. I'm a really empathetic person in general and I feel all sorts of compassion for her. Simultaneously, despite barely even knowing her (today was the first time we actually hung out, come to think of it), I am gonna miss her like crazy... This is mostly about her because of how much it sucks for her and how bad I feel for her, but I can't help but feel like shit too even though I barely even know her! I can't tell if I have a crush on her or if I just like her as a friend, but who cares anyways - she's gone now and I might not see her again...

      Just had to get this off my chest I guess. I just wish so bad that she didn't have to leave - that I could've gotten to know her more and spent more time with her.

      I'm also trying to follow some advice from a psychologist, because I have borderline personality disorder and basically it means I feel feelings a lot more intensely than the average person. I also haven't been a very social person historically speaking so I find it difficult to navigate relationships and situations like this. So the advice I'm trying to follow is particularly this bit: Instead of ‘I love you with the passion of a thousand fiery suns’ it might be nice to do a small gesture. But it's difficult to not write her on messenger and just say something like "I'm gonna miss you :(" - I know it's stupid to do that and she doesn't feel the same way I do because it's only been like 1 month of actual friendship, but it's genuinely how I feel.

      Wasn't sure if this belongs in ~life or here, so I figured I'd just go with this one. Just had to get this off my chest so that maybe I'll not be dumb and write her something that the overly attached girlfriend meme could have written. I used to be super clingy and it's driven people away in the past so yeah. Anyway, thanks for caring if you read this whole post :)

      22 votes