.pabrobet

A blog about stuff that's on my mind, mostly tech-related, probably.

...with a sidenote on why I think C++ is actually a good programming language for beginners

comic

So it's been a little over a year since my last post here and at that time I though I was going full steam on self-teaching to become a web developer and/or programmer. Then I'm not sure what happened, I guess I lost impulse, tried applying for a few web development jobs here and there, didn't get any, so I took a job as an interpreter. Which is not too bad, but it's also not exactly a dream job (which I'm not even sure exists anymore). After a few months of almost no programming, for some reason I got intrigued by C++, so I've been learning that for about a month now. I've been on and off trying to learn programming for about a decade now and each time I leave it for some time, then I come back and have forgotten most of it, but a little bit remains. One example is, I had never been able to understand classes before, when learning Python and later JavaScript; also function returns, when a function is supposed to return something and when not. The fact that C++ is strongly typed helps a lot to understand many concepts like that, as well as some other things that make C++ (superficially) more complicated, but the advantage is that it makes everything more explicit. sidenote: that is why I think C++ is actually a very good language for beginners. But it does requiere more patience and commitment to get to a point where you can do something “useful”.

You don't know what you don't know

programming with Bob Ross

I've been teaching myself programming and web development, consistently, for the past year or so, but I had been practicing more sporadically on and off, a couple months at a time, since about five years before. Honestly, I cannot say whether I am learning fast or slow, since the only thing I can say with certainty is that, although I have learned a lot, I know, and it becomes more evident with each new thing I learn, that I have orders of magnitude more to learn still.

One thing that makes self-teaching particularly difficult is the lack of structure. A lot of the time it is extremely difficult to know exactly what to study next. But even if you follow one of the millions upon millions of tutorials on YouTube that claim they will teach you how to code, from beginner to advanced in just one video-series; or some other resource like Odin Project or Free Code Camp, there is always something missing. At least that is my experience. And what is missing is not more information, because, some of them at least, can be extremely thorough, well-structured, and made with a lot of effort (really thank you to all the people who spend hours putting out all the amazing free content out there); furthermore, we live in the Information Era, everything is available on the internet just a few clicks away, from casual video tutorials about a particular topic, on pretty much anything you can imagine, to full pdf books that you can download for free and can be as technical as you want (ok, maybe not the most legal thing to do but...). What is actually missing from all of that is the link that ties it all together, because that is what separates information from knowledge.

For me, that link is having a real-world project. And even that can be very hard to find because I am often afraid that I do not know everything I need to know in order to take on a certain project I have in my mind. The hardest part about learning by project is that, as they say, “you don't know what you don't know”; in other words, sometimes you are stuck with a problem and have no idea where to even begin to look for the solution, and it may be in front of your eyes, but how can you see it if you don't even know that it exists?

Another thing that makes it difficult is that it becomes easy to get distracted, or get de-toured following some rabbit-hole that takes you somewhere far away from where you thought you were going... but that is not always a bad thing.

Learning by project and self-teaching in general can be chaotic, full of tangents and rabbit-holes; but it can be much more “organic” in some ways, even more “holistic”, precisely because it is not linear, it can get you researching concepts of advanced MySQL one minute, string formatting in PHP and then refreshing basic HTML form syntax the next; and then, you don't know exactly how, you spent a week mostly learning about BASH scripting and making your own little custom commands for the Linux terminal. Like in my current project of which I might write more soon. But my point here is, there lies the beauty of it.

I don't know if I have found the perfect method for self-teaching or not, I don't even know if I have found the one that works best for me. All I know is I am enjoying the journey, and is there anything more to life than that really?

I'm terrible at keeping my expenses and I really should do something about it. The first part, maybe the easiest, is to keep a registry of expenses that actually makes sense, that is well organized, clear and accesible, so it doesn't become a horrible chore to add new entries... “Where did I leave that little yellow notebook where I was writing down my expenses for like the past three days... can't find it anywhere... meh, I'll use this piece of paper and remember to write it down when I find it, oh, shit, now I need something to write with, ok I'll do it later”... aaand, you never did and now there is no point because what's the use for that data if it's incomplete? Amiright??? The second part, of course, is to do something about that data you have so dutifully registered, but I'll get there when I get there. So I thought about making some simple terminal command that would allow me to quickly enter any new expense, before I forget it, and have a relatively well organized file with all my expenses, even if then I need to manually add the amounts later. Here's what I came up with. The next part would be to make a program that reads the resulting file and takes the numbers from there and add them up. I'm guessing that probably involves regular expressions, tho, and why are they so hard? Or, you know, a sane person would probably tell me “just use a spreadsheet, dude”, but I don't wanna. Incidentally, have you ever tried programming in Spanish? Or any language that is not English, actually. There is no such thing really, us Spanish speakers have to keep switching from one language to another; you can name variables and functions in Spanish, but that is about it. More often than not, for me, it is actually easier ti just think in English.

#!/bin/bash
# appends a string starting with today's date to a file.
# $1: string to input
# $2: file name;

f="[insert directory path here]"$2
str=$1
d="$(date +'%d-%m-%Y')"    # Spanish date format, day-month-year.
day="$(date +'%a')"

# Esta sección es para hispanohablantes, traduce los días de inglés a español.
# Leave this block out if you do not want to translate day names.
case $day in 
	"Mon") day="Lun";;
	"Tue") day="Mar";;
	"Wed") day="Mie";;
	"Thu") day="Jue";;
	"Fri") day="Vie";;
	"Sat") day="Sab";;
	"Sun") day="Dom";;
	*)
esac

d="$day $d"     # generate full date string with day of the week.
new_entry="$d - $1"     # generate complete input string.
echo $new_entry >> $f     # append entry to file.

And that's it. There is probably a lot that can be improved, but it was mostly just an exercise for myself. I learned about switch statements and formatting the 'date' command output.

So after doing the necessary steps to make it executable, it produces something like this:

log "mercado: \$45" gastos.txt

(Remember to escape $ sign if you want to use it).

cat /filepath/gastos.txt =>
Mie 21-01-2021 - mercado: $45

This is my first entry in this here fediverse blog, yay! I've been digging into the fediverse lately and will try to move in permanently.

I'm not so big on introductions, but I'm a beginner web developer, I started learning front-end but have been trying to get into back-end a little more, and I also enjoy learning about Linux and bash scripting. Anyway here's a nifty little bash script I made that creates a new file with today's date as the name, with optional file extension and also gives the option to automatically open the file in a specific program, like vim, mousepad, codeOSS, or whatever.

#!/bin/bash

#create a new file with name of today's date. 
#Optional parameters -p: program to automatically open file (must be valid console command); -f: file extension

# Options 
while getopts p:f: option
do
	case "${option}"
		in
		p) PROGRAM=${OPTARG};;
		f) EXT="."${OPTARG};;
	esac
done

#default date format is dd-mm-yyyy
day="$(date +%d)"
month="$(date +%m)"
year="$(date +%Y)"

file=$day"-"$month"-"$year

# If file extension ($EXT) is set create file name with extension, 
# if not, # only the file name. 
if [ ! -n "$EXT" ]
then
	file=$file
else
	file=$file$EXT
fi
# Create the file
touch $file

# If program ($PROGRAM) is set, open file with that program
if [ -n "$PROGRAM" ] 
then comm="$PROGRAM $file"
	eval $comm
fi

Might be useful if you keep track of things daily or keep some kind of blog.

I will post more later, maybe also about cool things I learn about JavaScript, PHP, MySql and other stuff. Cheers!