Monday, April 27, 2020

JavaScript: Adding to arrays with "..."

In JavaScript, push method is used to add to an array. Let's say you have an existing array called out  = [{e1: 5}, {e2:10}] and want to add its elements to an array called arr. Results differ for arr.push(out) and arr.push(...out). When you use ellipsis (...), each element of out array will be added as a separate element to arr and arr.length will increase by 2 after push. Without ..., out will be added as a single element to arr, and arr.length will increase by 1 after push operation. Below is an example script:


Tuesday, April 14, 2020

Technical Team Leader

A software technical team leader's main responsibility is to make the team better, because that will result in highest efficiency due to each member becoming a better version of themselves. Examples of duties of a techlead:
  • Review/refactor design and documentation that the team produces. See Scrum sprints.
  • Review code, optimize/refactor for comprehensibility, speed, memory and safety. This will keep you up to date with the code.
    • Evaluate and select code analysis tools.
    • Evaluate tutorials and point team members to them.
    • Use stack instead of heap.
    • Solve difficult technical challenges that are beyond the capabilities of a team member.
  • Assist in solving difficult problems. Since you have been continuously reviewing design and code, you won't need extra acclimation time.
  • Review issue definitions and refactor for comprehensibility.
  • Review commits to repository (commits should be multiple times a day, not once a week)
  • Write simulators/emulators for external hardware and software components
  • Write initial versions of build scripts. Scripts will be maintained by juniors.
  • Write initial versions of setup scripts that makes setting a development environment as simple as a single mouse click.  Scripts will be maintained by juniors.
  • Find ways to decrease build times, create tutorials.
    • Disable antivirus
    • Use Linux instead of Windows.
    • Precompiled headers
  • Optimize IDE settings, create tutorials.
    • Shortcuts
    • Folder view
    • Output directory = bin
Notice that the list does not contain product work because fulfilling the above would take a lot of time. Product development consists mostly of repetitive/boring work that a junior can handle with guidance of a senior. By freeing the techlead from those chores and making him a team mentor and solver of only hard problems, you improve productivity of everyone.

Thursday, April 02, 2020

Writing my first C program in Linux

Recently I wrote my first C program in Ubuntu Linux for which I had a deadline. I was already familiar with C/C++ on Windows. It was quite a learning experience. My method was as follows:
  1. Search the internet for projects matching the problem definition. Result: There weren't any.
  2. Search examples/tutorials for terms in the problem definition like fork, poll.
  3. Write small demos. Modify and combine examples to solve the original problem. Result: Faced many difficulties during adaptation.
  4. Dive deeper and understand the details of concepts/terms that I am not well versed in, like pipes.
  5. Apply that deeper knowledge.
  6. Increase depth until the problem is solved in its entirety.
As you can see, I did not start by reading a lengthy Linux C fundamentals book. I focused on the problem at hand, tried shortcuts first and only spent more time on problematic points. I felt a lot of frustration while trying to hack my way out but I was determined enough to overcome constant failures. If you are working under time pressure, this is the fastest method of getting things done.

Notes:
  • To display processes starting with "node": ps -ef|grep node
  • To run as a background process, add & to the end.
  • Windows Subsystem for Linux, using Ubuntu with VS Code, tasks.json to build file (ctrl + shift+b)
  • pipes, socketpair, filedescriptor, dup2. 
  • Redirecting stdin
  • fork - exec
  • poll
  • Converting a string to a vector of strings, with space as delimiter
  • Difficulty of using strings. Writing and reading structures is much easier, to read a string after a write, you need to send EOF with close(fd), but then you have the problem of opening the filedescriptor again.
  • gcc, makefile, tar
  • Difficult to find bug in C: for (int i = 0; len; i++). Note that i< is missing.
  • When you print elements of a union structure, you will only get the last set element right.