r/AskComputerScience • • Jul 02 '20

How exactly knowing about computer architecture and boolean algebra has helped you in your software engineering career?

The title is self explanatory. I took a class on applications of boolean algebra to computer architecture this last semester and I was wondering how and if this knowledge is directly used in software development.

Edit.: Thanks so much everyone for their great answers. Apparently boolean algebra is used by most people when comparing statements or refactoring code and knowing computer architecture helps people make better decisions about efficiency.

38 Upvotes

19 comments sorted by

2

u/[deleted] Jul 02 '20 edited Jul 02 '20

Caching has been the biggest one. There are critical differences between hardware caches and software caches, but I always have a higher order understanding than my peers when discussing caching. And we discuss caching a lot. It really is the same problem in different domains, all of the same problems and patterns show up, but with different best practices.

Boolean algebra is the no-brainer, just doesn't feel like it's all that important since I use it every single time I write a boolean statement. And yes, you may not realize it, but you have a better understanding of basic logic because you learned boolean algebra. You'll notice it when you try to discuss some crazy if-statement another developer wrote.

Another one that comes to mind is Amdahl's Law. This is probably my favorite Theory to come out of CompSci because it is readily applicable to many problems outside of engineering. Any process should be analyzed and improved with Amdahl's Law in mind.

1

u/printerrboi Jul 03 '20

Thanks for that. If you don't mind, how do discussions about cache come up on software development exactly. I know very little about the subject. I have only a superficial knowledge about how it works.

55

u/wolverineoflove Jul 02 '20

You use boolean algebra every day when coding. Dont forget DeMorgan's law when refactoring!

8

u/IAmNotNathaniel Jul 02 '20

DeMorgan's law

I'd forgotten the name, but not what it was. I like knowing the names though, thanks for the reminder.

25

u/Sqeaky Jul 02 '20

Knowing about computer architecture makes it easier to understand v space trade offs. A simple example would be to use this to choose a sorting algorithm. On modern machines the CPU keeps getting faster relative to the memory. So a sorting algorithm that works on CPU cache sized chunks even if it has a bunch of extra math is likely to be faster than one that appears to have less math but allocates memory the size of the working set.

Knowledge of branch prediction informs decisions about sorting working sets before iterating over them. If the branch predictor can be made more accurate speculative executive can account better for memory latency.

As for boolean algebra, it just helps me structure better conditions.

11

u/emasculine Jul 02 '20

certainly helped when i wrote my preemptive multi-threaded OS before "threads" were even a thing.

4

u/VolcanicAshThief Jul 02 '20

Wow, impressive, I am new to OS architecture, and currently I am reading a Tanenbaums book about operating systems. Can you guide me what to do next, I really want to understand how operating systems work under the hood.

4

u/emasculine Jul 02 '20

sure, get a raspberry pi and play with its GPIO pins. that's sort of a Hello World of playing with hardware registers. you can emulate pretty much an entire processor using various primitives like SIGALRM for timers, SIGUSR1 for interrupts. heck, i even gave an assignment to a friend to do context switching using setjmp/longjmp and some glue asm. another good exercise might be to emulate a UART which gives you insight to queuing, mutual exclusion, interrupts, and how you move data to/from os queues to user land via read(2) and write(2).

since almost everything is about networks today, write your self a pseudo network stack with addressing, packetization multiplexing, routing and emulating L1, L2, and L3. it doesn't have to be IP, just enough to move packets around a bunch of threads emulating each endpoint. read up on TCP, UDP and now QUIC. all of the things you did with your UART, more or less apply to networking too: getting data in and out of user land, dealing with hardware with interrupts and DMA, etc.

once you do some of that, you can start looking at OS source code to see how it's done in real life. while you can clearly look at Linux, there might be simpler OS's for teaching. iirc, Minix begat Linux as a teaching OS.

3

u/VolcanicAshThief Jul 02 '20

Reading all of this I understand that I have a lot of work to do, and to learn, that's good, and very interesting. Can you recommend some books or tutorials? Thank you!

1

u/emasculine Jul 02 '20

i dunno, you're reading Tanenbaumn already so maybe do little programming projects that implement each chapter? i mean, just think like a prof of what they'd make you do as an assignment. like, for example, if it's on how file systems work, give yourself an assignment, say, to allocate a block of file space and be able to mkdir, creat, open, close, read, write, and unlink. it doesn't have to be masterpiece, mainly to go through the motions so that it isn't mysterious. or even a subset of that like, say, what is the data structure that is appropriate for a directory? what are its requirements? would a hash table be preferable over a tree? that sort of thing.

2

u/VolcanicAshThief Jul 02 '20

Thank you very much for advices. I Will do so, hope it will help me to understand the depths of the programming as I am a C# developer.

4

u/Audiblade Jul 02 '20

Boolean algebra is the single branch of mathematics that comes up the most often when I'm programming. Every time I write or read an if statement, making sure I get the condition right involves understanding boolean statements! Luckily, it's usually very straightforward, the more obtuse work you had to practice simplifying expressions or wrangling expressions with a large number of variables rarely comes up in practice. And when it does, it's usually more a sign that you should simplify or refactor your code than that you need to do big brain math.

Knowing computer architecture doesn't affect my day-to-day development directly. But every now and then, I'll read an article about or need to understand machine-level code or how to squeeze better performance out of the computer. You need to have a good sense of how a computer works to keep up with these discussions. In my experience, unless you're going into bare-to-the-metal programming, you don't need to have a deep understanding, but a general understanding just makes you more conversant about a wide range of programming topics.

As long as you pass your classes and don't completely forget everything after taking them, you'll probably know enough from these two topics to hold your own in most professional software shops.

7

u/jhaluska Jul 02 '20

I once used boolean algebra to optimized some code and proved them equivalent.

Knowing computer architecture, especially caches, helps explain why slowdowns happen when they do. This becomes important when optimizing software or working in real time areas.

4

u/SteeleDynamics Jul 02 '20

^ This

Real-Time systems definitely require knowledge of computer architecture in order to produce hyper-optimized code. For example, having cache-aligned data structures in order to keep frequently accessed data (in tight loops) within the same cache line.

As far as Boolean algebra relating to computer architecture, refactoring code in order to obtain tight loops with cache-local data pays dividends in performance.

2

u/IAmNotNathaniel Jul 02 '20

Both things are especially useful if working with SQL and databases.

3

u/jeffbell Jul 02 '20

Knowing that a Boolean Algebra can be defined as complemented distributed lattice helped me think about lattice mathematics in general.

Knowing De Morgan's law help me literally refactor code.

Knowing how compilers do code generation let me relax about creating intermediate variables for partial results. I can use that variable name as a kind of code documentation knowing that any optimizer is going to avoid wasting memory on it.

Understanding caching is essential when thinking about performance.

2

u/rnsbrum Jul 02 '20

it helped me to understand how thing really run "under the hood".

2

u/javaHoosier Jul 02 '20

Have you ever gone to a restaurant and wondered why your food might be taking too long? If you have ever worked in a kitchen then you’ll understand the process of how servers, cooks, and managers work together. What could cause things to go wrong.