Showing posts with label Essay. Show all posts
Showing posts with label Essay. Show all posts

Sunday, July 31, 2022

Essay 07 A 3G Computer Specification

Essay 07 A 3G Computer Specification

Minimum Specification Computer


It was sometime ago when Raspberry Pi Foundation came up with Raspberry Pi Zero. That's a bubble gum size computer, in comparison to mint tin sized computer. I think it's cute, and of course I bought one. The specification, however, falls short of my vision of an ideal computer.


Of course, it would be nice to have everything, but what I'm really aiming for is a cheap computer that does good enough computing. I still keep one to use as a daily driver when travelling. Raspberry Pi Zero is such a cute and handy computer!


Regarding the performance, it is somewhat lacking. It reminds me of the story of 3M computer specification. It tells a story about how Steve Jobs first heard the term.


 https://en.wikipedia.org/wiki/3M_computer  


which became the driving design of Next Computer: a megabyte of memory, a megapixel display, and a million instructions per second processing power. It is also commonly said that the price should be less than $10,000. 


When I define the specification of a simple yet usable computer, I came up with 3G specification: 1 GHz CPU, 1 GB RAM, and 1 Gb Bandwidth. The price should be less than $100. Raspberry Pi Zero didn't quite measure to it: 700 Mhz CPU, 512 kB RAM, and USB2 spec. So, I'd say about half my ideal specification, except the price, which was $10 with WiFi.


Raspberry Pi 4, which I bought as soon as I was able upon release, was in many ways exceeds the specification by about 4 times: 4 cores of 1 GHz CPU or faster, 4 GB RAM, and USB3 bandwidth. The price is $55, quite reasonable for the power and performance. So powerful, in fact, that the only applications that I can possibly max out of it would be 3D rendering and video editing. It mostly just sit idle doing nothing most of the time.


The Invisible Bandwidth


If you notice the difference of specification between the two, the original specification specified MIPS as an important factor. Steve Jobs puts in Display resolution as the important factor. I put Bandwidth as the important factor.


The reason why I don't really care about MIPS and Display is because I don't really use them. I mostly deal with integer calculation, and as far as display resolution is concerned, I'm still stuck with 800x600 resolution. In fact, I regularly set the font to large size, so that I don't have to squint at the display. Yes, I have a large HDMI monitor. No, I'm not a member of Tiny Font Society!


I set all my fonts and menu bar to large size, and I'm really dismayed that most program, including games and productivity tools, regularly set the font to extremely tiny size. Do you all have perfect vision or do you just not care? I think it's mostly the latter, but I really do hate tiny fonts.


As far as Bandwidth specification is concerned, I was clued in to the difference between Personal Computer (PC) and Mainframe Computer. I really like to deal with large amount of data, and the PC works well enough, but on the mainframe computer, I noticed that the processing went by at a much faster rate than the CPU would indicate. This piqued my interest. As I pore over the literature for the difference, I notice that the bandwidth is much larger on the mainframe. There is the answer!


Actually, that's not the whole story. There are several Bandwidth involved. The obvious one is the System Bus for data transfer between CPU and RAM. Then there's the bandwidth between computer and I/O devices. This is Serial, Parallel, or USB. Another set of bandwidth is the bandwidth between main CPU, math co-processor, and graphic co-processor. Nowadays, we have System on a Chip (SOC) architecture where everything is contained in one die. So, the most restrictive bandwidth is the I/O bandwidth, hence Gigabit bandwidth.


Or is it? Remember that I/O stands for Input/Output. Which external device has the slowest data rate? It's not the hard disk, or network, or keyboard. The slowest most restrictive bandwidth remains ignored because it's invisible. It seems like I'm the only one in the world who works on it.


The slowest bandwidth of the system is the bandwidth between keyboard and chair!


Sunday, July 24, 2022

Essay06 The Core of Computer Programming (part 2)

Essay06 The Core of Computer Programming (part 2)

The usage of IF-GOTO


In part one, I talk about the fundamental hardware necessary to enable IF-GOTO Conditional Branching. In part two, I will show the different way IF-GOTO can be used. Notwithstanding the exhortation "GOTO considered harmful!", let's see how Conditional Branching is to be used in a computer program.


Remember that computer program lies in Memory, and that is in reality just a sequence of numbers in sequential memory addresses. Computers don't really distinguish code and data, unless the hardware store each part separately. We're not concerned about that, though.


The simplest GOTO is Unconditional Branching. This is true if the Conditional evaluates a constant. In other words, either it is always True or always False. Or maybe, the Conditional isn't even checked. It has very limited usage, mainly to connect to a subroutine somewhere else. Reason maybe to simplify the main code, try to fit in the code more than what relative jump can cover, or provide hooks to be modified to point to updated code later. It can also be used to provide Infinite Loop. Lastly, it can also be abused to provide "Spaghetti Code" style of coding.


Therefore, Conditional Branching imply variables in the Conditional. This can be True or False, dependent on the variables. There's a whole section of Boolean algebra regarding this, but let's not go there for now. The main consideration here is that we can skip Forward, or Loop back.


Skipping Forward is usually used to provide interactive process. IF Something THEN Do This Else Do That. 


IF (TRUE) THEN DO THIS. 
IF (FALSE THEN DO THIS.
IF (TRUE) THEN DO THIS ELSE DO THAT

IF (TRUE) THEN DO THIS
ELSE IF (TRUE) THEN DO THIS
ELSE IF (TRUE) THEN DO THIS
ELSE DO THAT


The second example is called "IF-ELSE" ladder, and you can chain them for quite a long chain. There is something similar to this structure: ON...GOTO


ON (var) GOTO 1,2,3,...,N
ON (var) GOSUB 1,2,3,...,N


In C, we use switch() { case 1: ... default; } construct. The idea is that we execute different code depending on the value of variable, instead of TRUE/FALSE. Generally speaking, this is a concept of Multiplexer/Demultiplexer. 


Next, consider IF-GOTO to the preceeding address. This is called a LOOP. Easy way is Infinite LOOP.


LOOP start:
...
...
GOTO start:


You can use the loop to repeat N times:


REPEAT
...
...
UNTIL N=10


In C, we use do { } while () construct.


You can loop as long as a condition remains True


WHILE (cond)
...
...
WEND


In C, we use while () { } construct.


There is also FOR LOOP, but it's not interesting for the discussion. What is interesting are the keywords *break* and *continue*. CONTINUE is used to skip the rest of the loop and go to start immediately, while BREAK is used to BREAK out of the loop immediately. You can think of it as GOTO Start and GOTO End.


LOOP Start:
...
IF (cond) GOTO End: #break
...
IF (cond) GOTO Start #continue
...
GOTO Start
End:  #End of loop


And that should be it. There is also the Spaghetti Code style where you just go everywhere whenever you want. Such pattern are confusing and should be avoided whenever possible, but if you ever try to build a parser, maybe by using lex and yacc, then it can't be helped. State based or Functional coding is like that, too.


Saturday, July 16, 2022

Essay05 The Core of Computer Programming (part 1)

Essay05 The Core of Computer Programming (part 1)

A look at (simplified) computer system


The question is: What is essence of computer programming? What is the core of computer programming? What is it, that if you take away from the thing that is computer programming, will cause the thing to no longer be computer programming? My answer is: Conditional Branching (IF-GOTO).


This is a surprisingly deep issue. There are many considerations regarding this question. I had planned this to be just a single post, but having seen the whole, completed answer, I decided to split it into 2 parts. If you, like most people, think that the issue is a simple one, then I encourage you to stop at this point and work out your answer. Then continue reading, and compare our answers.


First, let me tell you what computer is not. There is an old joke that when a prospective buyer ask a salesman what the computer can do, the salesman answered that the computer can do half the things the customer can do. "Great! I'll take two!" Ha ha. Well, computers don't work like that. Computers can only do what you tell it to do, no more, no less. And whatever the computer was told to do, the computer can do it exceedingly fast, and with great accuracy.


Of course, fast is a relative term. Back on the old Apple 2 days, 1Mhz is fast, but not that fast. Yet, it is still much faster than Charles Babbage Analytical Engine. Nowadays, we have fast computers, but is it really that fast? Newer programs are such a bloat, that huge amount of computer resources are taken, not for working on the problem, but on cute animations that aren't that useful, or even cute, for that matter. So much waste.


We don't really need compilers or programming language, either. Computers are basically a collection of bits and bytes. Ones and Zeros. There's really not much more to it, until we get to Quantum mechanics. We do have CPU, but what is the core difference between a programmable calculator, and a computer? In simple terms, why is The Difference Engine a calculator, while the Analytical Engine a computer?


The most fundamental principle that is uniquely a computer program is, in my view, Conditional Branching. The ability to change the path of computation is fundamental of computer programming. If you have everything else except conditional branching, then you don't have a computer. What you have, then, is a batch processing. Imagine a robot that does a complicated dance, but repeatedly so without any change. Is that a robot? Yes. Is that a computer program? I'd say no. It's a complex mechanical construct, but not a computer. If, say, a car manufacturing robot can only be influenced by On and Off, then it's not a computer program, rather a batch processing. If, however, the robot can sense a car being somehow incorrectly staged and alerts the shop foreman, then it is a computer program. A computer program reacts to changing condition. A batch process cannot.


The simplest implementation of Conditional Branching that I can think of is IF-GOTO. This is true regardless of computer language. It can be Branch if Zero (BZ), Branch if Not Equal (BNE), IF-THEN-ELSE, WHILE/REPEAT LOOP, and other constructs. So, what does it mean, exactly that IF-GOTO exists?


Well, first of all, you need some kind of variables, and that variables can be compared. Variables means pointers. Pointers mean memory addresses to point to. Memory addresses can contain both code and data, but they are really just numbers. This means that GOTO address can be used to call functions. Combined with data stack, and you can call function recursively. You also need CPU because of the explosive combination between operation and data. CPU means you need some kind of flip-flop clock, in order for the CPU to process each instruction cleanly. 


The should also be some means of Input Output available. That means we need System Bus in order to shuffle data from Memory to CPU and vice-versa. We also want the computer system to interact with outside world. So, some kind of external data line, either serial, or maybe GPIO is in order. Interactive element can be Keyboard, Mouse, or Telemetry signal receiver. Output can be Display, Teletype, or maybe just some speakers.


Along the way, we can optimize further with Cache Memory or Co-Processor, but all things considered, the core of computer program is IF-GOTO. The rest is just there to support that process.


Friday, July 15, 2022

Essay 04 Amateur vs Professional Quality

Essay 04 Amateur vs Professional Quality

Does it really matter?


I have seen it too many times. In fact, I have hardly ever seen otherwise. My development environment as well as code style is that of an amateur hobbyist. Other people, even beginner coder, would go professional from the start. The question I'm asking is: Why would you want to handicap yourself to suffer professional quality programs when a simple hobbyist tool suffice?


Do you always get a race car for your daily drive? Do you always get the comprehensive tool cabinet when a tool bag gets the job done? Do you always get a professional studio when a sketchbook is handier? Why would you want to insist that a 4 GB Visual Studio is the only IDE you use, when a simple text editor will do? 


This kind of argument gets really bad. Adobe Studio Tools are definitely top quality, but as professional tools, they are rather expensive. GIMP and Krita are reasonable choices. Microsoft Office are great, too, but I used to just get a cheaper Microsoft Works since it gets the job done just fine. Oracle database is the best in the world, but most people can use MySQL well enough. Why would I want to use GCC with its long compile times, when TCC compiles near instantly?


As a hobbyist, coding should be fun. It doesn't matter that my hobbyist program compiled with TCC runs 3 times longer than a professional code compiled with GCC. The difference between 1 second and 1/3 of a second isn't that much. The fact is, that with TCC, I don't even bother doing the compilation step. There is an option to -run the source code directly! So, that is what I have been doing. It reminds me the easy of use of Perl. Perl is even more convenient!


Are the resulting program any good? I like to think so. Clayton Christensen's The Innovator's Dilemma stated: "Generally, disruptive technologies underperform established products in mainstream markets. [snip] Products based on disruptive technologies are typically cheaper, simpler, smaller, and frequently, more convenient to use." The point is, you don't have to outperform the best in the world. There are other opportunities in the smaller, niche markets. If you can't be a big fish in a big pond, then try to be a big fish in a small pond and make the pond bigger!


There lies the best value of a hobbyist. We don't have to have the best of everything. We just have to have a good enough tools. We don't have to be the smartest. We just have to be not stupid. We don't have to be the cheapest. We just have to provide good value. Coding? That's easy. Design? That's hard. The hard part of a journey isn't in making it. The hard part of a journey is knowing where to go!


Let's talk about professional frameworks a bit. There are many names: Xtreme, Agile, Scrum, and others. For the most part, they deal with the same issue: How to handle communication with clients. How to track progress and manage milestones. How to manage personnel involved in the project. A formal package for deliverables. There may be different philosophical and paradigm involved, but they mostly deal with the same issues.


Professionals need to deal with those issues. Not having proper procedure to deal with those issues will negatively affect client-producer relationship. So, having to follow at least one methodology is an absolutely crucial to the process. 


Hobbyist, on the other hand, don't really need to do that. They are their own clients. If something goes wrong, they can just fix it themselves. They do their own program maintenance. They don't have to worry about the ignorant boss who claims that stream-lining existing code is "a waste of time" even though it will save a lot of time in maintenance later. To that end, hobbyist have the advantage of not having to watch the clock, so to speak.


Expenses can be lower for hobbyist as well. Niche market which big business will never dream of entering is fair game for hobbyist. It's simple math: Less expense yields more profit, even if the overall revenue is less. 


So, my coding is at the amateur hobbyist level. While most people consider that as a handicap, I actually consider that as an advantage! My code is cleaner, simpler, and easier to understand. It works fast enough, and good enough to do the job well. Best of all, if there's something that is less than perfect, I'd just fix it. The source code is right there! It's easy to do because the code is simple and easy to understand. There's none of the complex framework involved as with professional quality codes. I should know, I've been both.


Following the lead of Satoru Iwata: My title may be business owner. My training is that of a computer programmer. But in my heart, I am an artist. I'm not a coder who does art. I am an artist who does code.



 


Monday, July 11, 2022

Essay 1: Introduction

Essay 1: Intro to 100 Days of Code

A journey of 10,000 steps begin with the first one


One fine day, warm and sunny, I decided to take up the 100 Days of Code challenge. This was shortly after I joined Twitter and found out that there are all kinds of groups over there. Elon Musk was in the process of buying Twitter and so I decided to join. Neil Gaiman is active there, too. Well, one thing led to another and I was looking over the hashtags and found one that says "100DaysOfCode" and was sufficiently intriqued.


So, I looked over the tweets, and found out that most of them does not feature any source code. And I may have missed it, but the point of doing 100 Days of Code challenge is to improve yourself, and part of that challenge is to publish the source code and share it with the world. The few that did take screenshot of their code do so with their favorite IDE, which inevitably means tiny, tiny font. Extremely hard to read. May as well not bother.


The suggestion was to publish your code on Github, and there's nothing wrong with that suggestion. I do have a blog account that I still post from time to time, and so I decided to just post it there. As long as it's available, no problem!


Most people actually have some kind of planning, either a book, or maybe, an on-line course. The name Angela Yu is featured with many of the posts. Another favorite of people is LeetCode. As for me, I don't have any established plan whatsoever. So, most of my time is spent trying to find the next feasible projects. The constant worry is running out of ideas to try.


The point of this challenge is to learn, and I decided to learn. That means taking something out that I'm uncomfortable with and improve upon it. As of this writing, 3 weeks into the challenge, it's been mixed projects so far. Leetcode challenges are there, but I actually skip most of them because I want to write actual, usable programs. That's a tall order, as I found out that just implementing the command line parameters alone would take upwards half an hour or so. That's just setting variables, no actual program coding.


As to the actual coding, I firmly believe that most of the program's core are actually very simple. To that end, I would screen capture the code from my blog, which means no tiny font! So far, I've been managing to do so in one screen. Exception is the SVG library, which is rather extensive, even in the first incarnation.


The best part of taking this challenge, however, is that it anchors my day. Excepting rest days, which is Sunday, I always code. If the time is lacking, then I code something simple, such as FizzBuzz. Overall, though, it has been extremely productive sessions. 


And that's the real benefit of the process. My coding skill is getting better every day. Of course, it wasn't lacking to begin with, but doing this challenge forces me to be extremely productive with my time. So far, I've been spending about 2-4 hours per day, including write ups. I'm happy with the progress I'm making, especially since other people would code a challenge, and I would code a whole program.


That cannot be overstated: I wrote a whole new program everyday! Not a little function, but a whole program! Now, the program maybe rough and in need of revising, which I will do as needed later. Also, there may be bugs or missing feature which means I spent some time fixing the bugs, especially if it's a program I'll be using later on the challenge. It's still a program a day, though.


That just goes to show, no matter how skillful you are, there will always be higher mountain to climb, and I have begun making my steps, one day at a time. Today, it's the 18th day, and I'm resting and writing this stream of conciousness for the time to reflect back from the day of completion.


2022 July 03