Posts

Are You Solving the Right Problem? (i.e. the XY Problem)

Ever heard of the XY problem? No? Those of you in tech support may have seen it without knowing its name, but it actually happens quite often in programming and tech support.  Here is an example from xyproblem.info , albeit rewritten for JavaScript n00b> How do I get the last 3 letters of the filename?  feline> If it's in a variable, you can slice it like str.slice(-3) feline> Wait, why are you asking?  What do you really want?  feline>Do you want the extension (of a file)?  n00b> Uh, yes?  feline>There's no guarantee that every file name will have a three-letter extension, so blindly grabbing three characters does not solve the problem. With that said, here are three ways to get it , using regex, split, or slice+lastIndexOf  See the problem? noob asks for X (last 3 characters of string), but actually wanted to solve Y (get file extension). What if there was no extension? What if the extension is MORE THAN 3 letters?  S...

Basic Program Logic: Input / Process / Output, and basic Loops

Previously, we had talked about how some people cannot problem-solve . While others take to it like duck to water. They can't see the process of the programing, esp. when it comes to applying if branches or even loops. So let's discuss that a bit.  A very simple program takes some input, process the input, and generates an output.  Get input Process input Display output Simple, right?   Let's Write a Simple Input/Process/Output program Now let's write a very simple calculator in JavaScript. Enter two numbers (with prompt), display the output with an alert box. NOTE: You can do this with command-line arguments and spit the output to the console. Or even use a different language. The idea is the same.   var a = prompt("Enter a",0) // input var b = prompt ("Enter b",0) // input var x=parseInt(a)+parseInt(b) // process alert("Result is "+x) // output You may have noticed I used parseInt. That's because prompt returns a STRING. And when you ...

Has COVID-19 really distorted the workspace that "Entry-level" and "Junior" had lost all meaning?

Image
Sometimes, looking at LinkedIn job listing makes me despair for all the junior webdev and software engineers, when requirements start to resemble a tragi-comedy, rather than reality.  In the US... An entry-level position should require NO existing experience.  A junior position should require 0-3 years of experience.  A mid-level position should require 3-5 years of experience.  A senior-level position should require 5-7 years of experience.  Yet it is clear that this no longer applies... Or LinkedIn employers are putting out CRAZY expectations, redefining "entry-level" to be 5-years of experience.  Here is one example. I'm not naming the guilty party, but as you can see, they defined their "junior" position as "MINIMUM of 5 years' experience"  Screenshot of a job from LinkedIn, posted 9/15/2020, where it defines "Junior" as entry-level, yet requires MINIMUM of 5 years experience And this is not even the craziest. I have seen some "e...

Why Learn Data Structures and Algorithms at All?

One question often asked by programming noobs is "why do I have to learn data structures and algorithms? I already have a ton of better stuff in the language itself. Array can be used to implement any sort of DS. Sort() build into the language is better than any sort I can implement. So why do we need to learn those at all?"  If you are ONLY interested in doing web development forever, then no, you don't need data structure and algorithms. Webdev, however, is a bit of special case, as you are mainly assembling bits and pieces of other libraries and modules and such into a coherent whole, serve it up in HTML, and style it with CSS. Get some data from user, send it to server, get some data back, present it to the user. You rarely have to crunch large datasets by yourself as a webdev.  However, if you deal with more complex software engineering, then you need some fundamentals, such as data structures and algorithms, to understand and solve even MORE complex problems. It...

Difference between computer science and software engineering

NOTE: This blog post was inspired by this Reddit post In my experience, many people do not understand the difference between computer science and software engineering. They want a coding career, not understanding they want the latter, not the former.  Computer sciences usually defined as "the study of computers and computational systems". It is more about the theory and practice of computing, which involves testing and improving data structures and the algorithms to manipulate them to achieve some goal. It's not really programming per se, but meta-programming. But it's definitely about software and its efficiency, and possibly better ways of doing things, and the various trade-offs.  Knowing computer science is NOT the same as knowing DSA (data structures and algorithms). Though they are usually taught together as basics to be discussed, as big O and computational efficiency is a big part of computer science. But different students have very different goals for learni...

How to Solve a Problem 5: Horse-Racing Duals and HyperDuals

 Let us take a look at one of the competitors to HackerRank... CodeWars, and one of the puzzles on it. This one is called Horse-Racing Duals, and a harder version called HyperDuals. But one thing at a time.  You can access the problem here:  Link Read the problem very carefully. Noticed that it lists " external resources: Sorting, Lists "? Clearly, you will need to sort the solution.  I am going to do this in JavaScript, which is pretty universal.  First, they did NOT create any data structure(s) for you, so you have to create your own. I simply called mine horses . And I added a line in the readline loop to load the number into the array.  const   N  =  parseInt ( readline ()); var   horses = [] horses . length = N ; for  ( let   i  =  0 ;  i  <  N ;  i ++) {      const   pi  =  parseInt ( readline ());      horses [ i ]= pi } But...

Yet another take on recursion

Recursion is often one of the hardest things to "get" in programming, so when you have your "aha" moment, it's that much more amazing. Conceptually, it's not that hard to see, but how do you actually program one such?  First, realize that " recursion is a method of solving a problem where the solution depends on solutions to smaller instances of the same problem." Let us try something simple. Let's say... I want you to sum up the elements of an arbitrary array, let's call it arr. It can have any number of elements, and each element is an integer. For the purpose of this exercise, let's just say it's [1,2,3,4], but it can be any integer, and the array can be any valid size. And I want to you use recursion, not loop (no for or while or such statements).  Now, remember the definition: "solving a problem where the solution depends on the solutions to smaller instances of the same problem".  Let's call this function rsum (...