From 1ba0614e451168bc703df1c7b59730d3a83b7703 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 29 Jan 2022 22:15:04 +0000 Subject: Publishing new version --- computer-operating-systems-i-use.html | 128 +++++++++++++++++++++ gemfeed/2016-11-20-methods-in-c.html | 82 ------------- ...20-object-oriented-programming-with-ansi-c.html | 94 +++++++++++++++ gemfeed/atom.xml | 46 +++++--- gemfeed/index.html | 2 +- index.html | 2 +- 6 files changed, 253 insertions(+), 101 deletions(-) create mode 100644 computer-operating-systems-i-use.html delete mode 100644 gemfeed/2016-11-20-methods-in-c.html create mode 100644 gemfeed/2016-11-20-object-oriented-programming-with-ansi-c.html diff --git a/computer-operating-systems-i-use.html b/computer-operating-systems-i-use.html new file mode 100644 index 00000000..95fdf6af --- /dev/null +++ b/computer-operating-systems-i-use.html @@ -0,0 +1,128 @@ + + + + +Computer operating systems I use + + + + +

Computer operating systems I use

+
+              /(        )`
+              \ \___   / |
+              /- _  `-/  '
+             (/\/ \ \   /\
+             / /   | `    \
+             O O   ) /    |
+             `-^--'`<     '
+            (_.)  _  )   /
+             `.___/`    /
+               `-----' /
+  <----.     __ / __   \
+  <----|====O)))==) \) /====
+  <----'    `--' `.__,' \
+               |        |
+                \       /
+           ______( (_  / \______
+  (FL)   ,'  ,-----'   |        \
+         `--{__________)        \/   "Berkeley Unix Daemon"
+
+

Published by Paul at ????-??-??

+

This is a list of Operating Systems I currently use. The list is in no particular order. This site might gets updated over time. Once in a while I try to out new things and switch forth- and back from one to anther. I prefer free and open source software over proprietary software. I didn't manage to libreboot my devices yet, though. That's mostly due to the lack of time I have.

+https://libreboot.org/
+

Fedora Linux

+

Fedora Linux is the operating system I use on my primary (personal) laptop. It's a ThinkPad X1 Carbon Gen. 9. Lenovo officially supports Fedora Linux on this Laptop (I already saw hardware firmware updates being installed directly through Fedora from Lenovo). Fedora is a real powerhouse, cutting-edge and reasonably stable at the same time (well, it's baked by Red Hat after all).

+

I also use Fedora on my Microsoft Surface Go 2 convertible tablet. Fedora works quite OK (and much better than Windows) on this device. It's also the perfect travel companion.

+

I use the GNOME Desktop on my Fedora boxes. I have memorized and customized a bunch of keyboard shortcuts. But the fact that I mostly work in the terminal (with tmux) makes the Desktop environment I use only secondary.

+

EndeavourOS

+

I had to make a choice what to do with my old ThinkPad X240. I could have sold it on eBay, but I decided to try out another Linux distribution instead.

+

Until 2021, I never used Arch as my main Desktop OS. There was a lot talking about Arch and Arch-based distros and I wanted to know what's the fuzz all about. However, I was lazy performing an Arch install from scratch. As a result I decided to give EndeavourOS a shot, as it comes with an easy installer and is still as close as you can get to plain Arch without actually using plain Arch.

+

So far, It's not bad. While working form home, I always have my X240 next to my work laptop for things like playing music and online radio, for personal note taking and occasional emailing and instant messaging.

+

Other than Fedora, Arch Linux and EndeavourOS are purely backed by the community. So there is no big corporation in the backyard lurking around. They won't give you the firmware updates out of the box, though. But they are still a very good choice, especially for hobbyist and also for older hardware where future firmware updates are less likely required.

+

As the Desktop environment I use Xfce here, which feels very snappy and fast on the X240 which I purchased back in 2014.

+https://endeavouros.com/
+

FreeBSD

+

I have run FreeBSD in many occasions. One of my former employers even allowed me to install FreeBSD on my main workstation (which I actually did and used it for a couple of years).

+

FreeBSD always had a place somewhere in my life:

+ +

Debian GNU/kFreeBSD is now dead (same is my experiment).

+https://www.debian.org/ports/kfreebsd-gnu/
+

But I still have saved and old uname output :-):

+
+[root@saturn /usr/jail/serv14/etc] # jexec 21 bash
+root@rhea:/ # uname -a
+GNU/kFreeBSD rhea.buetow.org 8.0-RELEASE-p5 FreeBSD 8.0-RELEASE-p5 #2: Sat Nov 27 13:10:09 CET \
+  2010 root@saturn.buetow.org:/usr/obj/usr/srcs/freebsd.src8/src/sys/SERV10 x86 64 amd64 Intel(R) \
+  Core(TM) i7 CPU 920 @ 2.67GHz GNU/kFreeBSD
+
+

Currently, I use FreeBSD only on my home NAS server for storing all of my personal data (which is a regular PC with a bunch of hard drives and a ZFS RAIDZ (with 4x2TB drives) + a couple of external backup drives) but I have plans to replace the CentOS 7 box (see below) with FreeBSD soon.

+https://www.FreeBSD.org
+

CentOS 7

+

While CentOS 8 is already out of support, I still use CentOS 7 (which still gets security updates until 2024). CentOS 7 runs in a cloud VM and is the home to my personal NextCloud and Wallabag installations. You probably know already NextCloud. About Wallabag: It is a great free and open source alternative to Pocket. Yes, you can pay for a Wallabag subscription, but you can also host it for free on your own server.

+NextCloud
+Wallabag
+

The reason I use Linux for these is Docker. With Docker, it's straightforward to get these up and running. Before CentOS 7 runs out of support, I will have to switch to another OS. It might be CentOS Stream, Rocky Linux, or, more likely, I will use FreeBSD. On FreeBSD there isn't Docker, but what can be done is to create a self-contained Jail for each of the web-apps.

+

I have been operating FreeBSD Jails for fairly complex LAMP stacks before I started to use CentOS. The reason why I switched to CentOS (it was still CentOS 6 at that time) some years back here was that I wanted to try out something new. It doesn't hurt to switch OSes once in a while. FreeBSD is so convenient: When something goes wrong with an update, just roll back to a previous ZFS snapshot. That's especially convenient for PHP based web-apps. :-)

+https://www.centos.org
+

OpenBSD

+

I use two OpenBSD boxes for my "public facing internet frontends". The services I run there are:

+ +

OpenBSD is a complete operating system. I love it due to it's "simplicity" and "correctness" and the good documentation (especially the manual pages). OpenBSD is also known for its innovations in security. I must admin, thought, that most Unix like operating system would be secure enough for my personal needs and that I would not need to use OpenBSD in particular here. But nevertheless, I think it's the ideal operating system for what I am using it.

+

The only software which are not part of the base system and I had to install additionally were the Gemini server (vger) and Git (both were available as pre-compiled OpenBSD binary packages). So, besides of these two packages, it is indeed a pretty complete operating system for my use case (mainly httpd, OpenSMTPD, nsd, relayd, inetd, cron).

+https://www.openbsd.org
+

macOS (proprietary)

+

I have to use a MacBook Pro with macOS for work. What else can I say but that this would have never been my personal choice. At least macOS is a UNIX under the hood and comes with a decent terminal and there are plenty of terminal apps available via Brew. And it's better than Windows (I suppose). Some of the inner workings of macOS were actually forked from the FreeBSD project.

+developer.apple.com: BSD in macOS/Darwin
+

LineageOS (mobile)

+

At some point I got fed up with big tech, like Google and Samsung (or Apple, but personally I don't use Apple), spying on me. So I purchased a Google phone (a midrange Pixel phone) and installed LineageOS, a free and open source distribution of Android, on it. I don't have anything from Google installed on it (not even the play store, I install my apps from F-Droid). It's my daily driver since mid 2021 now.

+

So far the experience is not great but good. The main culprits are not having Google Maps, Google Gboard and the camera app. The latter lacks some features on LineageOS (e.g. No wide angle lens support). Also, I can't use my banking apps anymore.

+

But the whole point of switching to LineageOS was to get away of big tech and therefore I should not complain :-). What I do like is that 95% the things I used to do on a mobile phone also can be done with LineageOS.

+https://lineageos.org/
+

Samsung's Stock Android (mobile proprietary)

+

Unfortunatley, I still have to keep my proprietary Android phone around. Sometimes, I really need to use some proprietary apps which are only available form the Google play store and also require the Google services installed on the phone. I don't carry this phone around all the time and I only use it intentionally for very specific use cases. I think this is the best compromise I can make.

+

iOS (mobile proprietary)

+

I have to use an iPhone for work. I like the hardware but I hate the OS (you can also call it spyOS), but it's the necessary's evil, unfortunately. I don't have it usually with me and shut off or in airplane mode when I don't need it. I also find it quite unintuitive to use.

+

Other OSes

+

InfinyTime (smartwatch)

+

I use it on my PineTime smartwatch. Not much to write about it yet, as I just got started with it recently and am only using it because of its fancy watch face and also I use it as a pedometer. AstroidOS seems also interesting for smartwatches nowadays, but I haven't looked into it yet. I will list it here anyway in case you want to check it out.

+https://www.pine64.org/pinetime/
+https://infinitime.io/
+https://asteroidos.org/
+

motionEyeOS

+

Before I travel, I always install an army of RaspberryPi 3's in my house. All are equipped with an camera and have motionEyeOS (Linux based video surveillance system) installed. There's a neat Android app in the F-Droid store (also in Google Play Store) which let's me keep an eye on everything. I make the Pi's accessible from the internet via reverse SSH tunnels though one of my frontend servers.

+https://github.com/ccrisan/motioneyeos
+

Kobo OS (proprietary)

+

I use a Kobo Forma as my e-reader device. I have disabled the Wifi and I only sideload ePubs on it. Otherwise, it would call home to Rakuten. I would like to replace it one day with an open source e-reader device like the PineNote. There are also some interesting attempts installing postmarketOS Linux on Kobo devices. It boots already, but is far from being usable as a normal e-reader.

+The PineNote
+Kobo Clara HD becomes an e-link Linux tablet
+

NetBSD

+

I have been using NetBSD on an old Sun Sparcstation 10 as a student. I also have run NetBSD on a very old ThinkPad with 96MB!!! of RAM (even with X and ratpoison WM). I also installed (but never really used) NetBSD on an HP Jornada 680. But that's all more than 10 years ago. I haven't looked at NetBSD for long time. I want to revive it on an "old" ThinkPad T450 of mine which I currently don't use.

+https://netbsd.org
+

Android TV (proprietary)

+

A Android TV box is used for watching Netflix. Currently in the process of being replaced by OSMC.

+https://osmc.tv/
+

SailfishOS (mobile proprietary)

+

Before switching to LineageOS, I gave SailfishOS a shot. To some degree it works. It can even run Android apps. But I don't like that SailfishOS also includes closed source components.

+https://sailfishos.org/
+

E-Mail me your comments to paul at buetow dot org!

+Go back to the main site
+ + + diff --git a/gemfeed/2016-11-20-methods-in-c.html b/gemfeed/2016-11-20-methods-in-c.html deleted file mode 100644 index 072abd76..00000000 --- a/gemfeed/2016-11-20-methods-in-c.html +++ /dev/null @@ -1,82 +0,0 @@ - - - - -Methods in C - - - - -

Methods in C

-

Published by Paul at 2016-11-20

-

You can do some sort of object-oriented programming in the C Programming Language. However, that is very limited. But also very easy and straightforward to use.

-

Example

-

Let's have a look at the following sample program. All you have to do is to add a function pointer such as "calculate" to the definition of struct "something_s". Later, during the struct initialization, assign a function address to that function pointer:

-
-#include <stdio.h>
-
-typedef struct {
-    double (*calculate)(const double, const double);
-    char *name;
-} something_s;
-
-double multiplication(const double a, const double b) {
-    return a * b;
-}
-
-double division(const double a, const double b) {
-    return a / b;
-}
-
-int main(void) {
-    something_s mult = (something_s) {
-        .calculate = multiplication,
-        .name = "Multiplication"
-    };
-
-    something_s div = (something_s) {
-        .calculate = division,
-        .name = "Division"
-    };
-
-    const double a = 3, b = 2;
-
-    printf("%s(%f, %f) => %f\n", mult.name, a, b, mult.calculate(a,b));
-    printf("%s(%f, %f) => %f\n", div.name, a, b, div.calculate(a,b));
-}
-
-

As you can see, you can call the function (pointed by the function pointer) the same way as in C++ or Java via:

-
-printf("%s(%f, %f) => %f\n", mult.name, a, b, mult.calculate(a,b));
-printf("%s(%f, %f) => %f\n", div.name, a, b, div.calculate(a,b));
-
-

However, that's just syntactic sugar for:

-
-printf("%s(%f, %f) => %f\n", mult.name, a, b, (*mult.calculate)(a,b));
-printf("%s(%f, %f) => %f\n", div.name, a, b, (*div.calculate)(a,b));
-
-

Output:

-
-pbuetow ~/git/blog/source [38268]% gcc methods-in-c.c -o methods-in-c
-pbuetow ~/git/blog/source [38269]% ./methods-in-c
-Multiplication(3.000000, 2.000000) => 6.000000
-Division(3.000000, 2.000000) => 1.500000
-
-

Not complicated at all, but nice to know and helps to make the code easier to read!

-

The flaw

-

However, that's not really how it works in object-oriented languages such as Java and C++. The method call in this example is not a method call as "mult" and "div" in this example are not "message receivers". I mean that the functions can not access the state of the "mult" and "div" struct objects. In C, you would need to do something like this instead if you wanted to access the state of "mult" from within the calculate function, you would have to pass it as an argument:

-
-mult.calculate(mult,a,b));
-
-

How to overcome this? You need to take it further.

-

Taking it further

-

If you want to take it further, type "Object-Oriented Programming with ANSI-C" into your favourite internet search engine, you will find some crazy stuff. Some go as far as writing a C preprocessor in AWK, which takes some object-oriented pseudo-C and transforms it to plain C so that the C compiler can compile it to machine code. This is similar to how the C++ language had its origins.

-

E-Mail me your comments to paul at buetow dot org!

-Go back to the main site
- - - diff --git a/gemfeed/2016-11-20-object-oriented-programming-with-ansi-c.html b/gemfeed/2016-11-20-object-oriented-programming-with-ansi-c.html new file mode 100644 index 00000000..0ed5a4c0 --- /dev/null +++ b/gemfeed/2016-11-20-object-oriented-programming-with-ansi-c.html @@ -0,0 +1,94 @@ + + + + +Object oriented programming with ANSI C + + + + +

Object oriented programming with ANSI C

+
+  ___   ___  ____        ____ 
+ / _ \ / _ \|  _ \      / ___|
+| | | | | | | |_) |____| |    
+| |_| | |_| |  __/_____| |___ 
+ \___/ \___/|_|         \____|
+                              
+
+

Published by Paul at 2016-11-20, updated 2022-01-29

+

You can do a little of object-oriented programming in the C Programming Language. However, that is, in my humble opinion, limited. It's easier to use a different programming language than C for OOP. But still it's an interesting exercise to try using C for this.

+

Function pointers

+

Let's have a look at the following sample program. All you have to do is to add a function pointer such as "calculate" to the definition of struct "something_s". Later, during the struct initialization, assign a function address to that function pointer:

+
+#include <stdio.h>
+
+typedef struct {
+    double (*calculate)(const double, const double);
+    char *name;
+} something_s;
+
+double multiplication(const double a, const double b) {
+    return a * b;
+}
+
+double division(const double a, const double b) {
+    return a / b;
+}
+
+int main(void) {
+    something_s mult = (something_s) {
+        .calculate = multiplication,
+        .name = "Multiplication"
+    };
+
+    something_s div = (something_s) {
+        .calculate = division,
+        .name = "Division"
+    };
+
+    const double a = 3, b = 2;
+
+    printf("%s(%f, %f) => %f\n", mult.name, a, b, mult.calculate(a,b));
+    printf("%s(%f, %f) => %f\n", div.name, a, b, div.calculate(a,b));
+}
+
+

As you can see, you can call the function (pointed by the function pointer) with the same syntax as in C++ or Java:

+
+printf("%s(%f, %f) => %f\n", mult.name, a, b, mult.calculate(a,b));
+printf("%s(%f, %f) => %f\n", div.name, a, b, div.calculate(a,b));
+
+

However, that's just syntactic sugar for:

+
+printf("%s(%f, %f) => %f\n", mult.name, a, b, (*mult.calculate)(a,b));
+printf("%s(%f, %f) => %f\n", div.name, a, b, (*div.calculate)(a,b));
+
+

Output:

+
+pbuetow ~/git/blog/source [38268]% gcc oop-c-example.c -o oop-c-example
+pbuetow ~/git/blog/source [38269]% ./oop-c-example
+Multiplication(3.000000, 2.000000) => 6.000000
+Division(3.000000, 2.000000) => 1.500000
+
+

Not complicated at all, but nice to know and helps to make the code easier to read!

+

That's not OOP, though

+

However, that's not really how it works in object-oriented languages such as Java and C++. The method call in this example is not a method call as "mult" and "div" in this example are not "message receivers". I mean that the functions can not access the state of the "mult" and "div" struct objects. In C, you would need to do something like this instead if you wanted to access the state of "mult" from within the calculate function, you would have to pass it as an argument:

+
+mult.calculate(mult,a,b));
+
+

Real object oriented proramming with C

+

If you want to take it further, hit "Object-Oriented Programming with ANSI-C" into your favourite internet search engine or follow the link below. It goes as far as writing a C preprocessor in AWK, which takes some object-oriented pseudo-C and transforms it to plain C so that the C compiler can compile it to machine code. This is similar to how the C++ language had its origins.

+https://www.cs.rit.edu/~ats/books/ooc.pdf
+

OOP design patterns in the Linux Kernel

+

Big C software projects, like Linux, also follow some OOP techniques:

+https://lwn.net/Articles/444910/
+

C is a very old programming lanuage with it's quirks. This might be one of the reasons why Linux will also let Rust code in.

+

E-Mail me your comments to paul at buetow dot org!

+Go back to the main site
+ + + diff --git a/gemfeed/atom.xml b/gemfeed/atom.xml index a24c268f..d31eac3d 100644 --- a/gemfeed/atom.xml +++ b/gemfeed/atom.xml @@ -1,6 +1,6 @@ - 2022-01-23T22:20:22+00:00 + 2022-01-29T22:10:52+00:00 foo.zone feed To be in the .zone! @@ -1986,21 +1986,29 @@ Total time: 1213.00s - Methods in C - - https://foo.zone/gemfeed/2016-11-20-methods-in-c.html - 2016-11-20T18:36:51+01:00 + Object oriented programming with ANSI C + + https://foo.zone/gemfeed/2016-11-20-object-oriented-programming-with-ansi-c.html + 2016-11-20T22:10:57+00:00 Paul Buetow comments@mx.buetow.org - You can do some sort of object oriented programming in the C Programming Language. However, that is very limited. But also very easy and straight forward to use.. .....to read on please visit my site. + You can do a little of object-oriented programming in the C Programming Language. However, that is, in my humble opinion, limited. It's easier to use a different programming language than C for OOP. But still it's an interesting exercise to try using C for this.. .....to read on please visit my site.
-

Methods in C

-

Published by Paul at 2016-11-20

-

You can do some sort of object-oriented programming in the C Programming Language. However, that is very limited. But also very easy and straightforward to use.

-

Example

+

Object oriented programming with ANSI C

+
+  ___   ___  ____        ____ 
+ / _ \ / _ \|  _ \      / ___|
+| | | | | | | |_) |____| |    
+| |_| | |_| |  __/_____| |___ 
+ \___/ \___/|_|         \____|
+                              
+
+

Published by Paul at 2016-11-20, updated 2022-01-29

+

You can do a little of object-oriented programming in the C Programming Language. However, that is, in my humble opinion, limited. It's easier to use a different programming language than C for OOP. But still it's an interesting exercise to try using C for this.

+

Function pointers

Let's have a look at the following sample program. All you have to do is to add a function pointer such as "calculate" to the definition of struct "something_s". Later, during the struct initialization, assign a function address to that function pointer:

 #include <stdio.h>
@@ -2035,7 +2043,7 @@ int main(void) {
     printf("%s(%f, %f) => %f\n", div.name, a, b, div.calculate(a,b));
 }
 
-

As you can see, you can call the function (pointed by the function pointer) the same way as in C++ or Java via:

+

As you can see, you can call the function (pointed by the function pointer) with the same syntax as in C++ or Java:

 printf("%s(%f, %f) => %f\n", mult.name, a, b, mult.calculate(a,b));
 printf("%s(%f, %f) => %f\n", div.name, a, b, div.calculate(a,b));
@@ -2047,20 +2055,24 @@ printf("%s(%f, %f) => %f\n", div.name, a, b, (*div.calculate)(a,b));
 

Output:

-pbuetow ~/git/blog/source [38268]% gcc methods-in-c.c -o methods-in-c
-pbuetow ~/git/blog/source [38269]% ./methods-in-c
+pbuetow ~/git/blog/source [38268]% gcc oop-c-example.c -o oop-c-example
+pbuetow ~/git/blog/source [38269]% ./oop-c-example
 Multiplication(3.000000, 2.000000) => 6.000000
 Division(3.000000, 2.000000) => 1.500000
 

Not complicated at all, but nice to know and helps to make the code easier to read!

-

The flaw

+

That's not OOP, though

However, that's not really how it works in object-oriented languages such as Java and C++. The method call in this example is not a method call as "mult" and "div" in this example are not "message receivers". I mean that the functions can not access the state of the "mult" and "div" struct objects. In C, you would need to do something like this instead if you wanted to access the state of "mult" from within the calculate function, you would have to pass it as an argument:

 mult.calculate(mult,a,b));
 
-

How to overcome this? You need to take it further.

-

Taking it further

-

If you want to take it further, type "Object-Oriented Programming with ANSI-C" into your favourite internet search engine, you will find some crazy stuff. Some go as far as writing a C preprocessor in AWK, which takes some object-oriented pseudo-C and transforms it to plain C so that the C compiler can compile it to machine code. This is similar to how the C++ language had its origins.

+

Real object oriented proramming with C

+

If you want to take it further, hit "Object-Oriented Programming with ANSI-C" into your favourite internet search engine or follow the link below. It goes as far as writing a C preprocessor in AWK, which takes some object-oriented pseudo-C and transforms it to plain C so that the C compiler can compile it to machine code. This is similar to how the C++ language had its origins.

+https://www.cs.rit.edu/~ats/books/ooc.pdf
+

OOP design patterns in the Linux Kernel

+

Big C software projects, like Linux, also follow some OOP techniques:

+https://lwn.net/Articles/444910/
+

C is a very old programming lanuage with it's quirks. This might be one of the reasons why Linux will also let Rust code in.

E-Mail me your comments to paul at buetow dot org!

diff --git a/gemfeed/index.html b/gemfeed/index.html index 00d95c6c..c0c0ab8b 100644 --- a/gemfeed/index.html +++ b/gemfeed/index.html @@ -22,7 +22,7 @@ 2021-04-24 (0802 words) - Welcome to the Geminispace
2021-04-22 (2122 words) - DTail - The distributed log tail program
2018-06-01 (2176 words) - Realistic load testing with I/O Riot for Linux
-2016-11-20 (0318 words) - Methods in C
+2016-11-20 (0385 words) - Object oriented programming with ANSI C
2016-05-22 (0512 words) - Spinning up my own authoritative DNS servers
2016-04-16 (0248 words) - Offsite backup with ZFS (Part 2)
2016-04-09 (0425 words) - Jails and ZFS with Puppet on FreeBSD
diff --git a/index.html b/index.html index 038225c4..ccd20c2e 100644 --- a/index.html +++ b/index.html @@ -58,7 +58,7 @@ 2021-04-24 - Welcome to the Geminispace
2021-04-22 - DTail - The distributed log tail program
2018-06-01 - Realistic load testing with I/O Riot for Linux
-2016-11-20 - Methods in C
+2016-11-20 - Object oriented programming with ANSI C
2016-05-22 - Spinning up my own authoritative DNS servers
2016-04-16 - Offsite backup with ZFS (Part 2)
2016-04-09 - Jails and ZFS with Puppet on FreeBSD
-- cgit v1.2.3