Conversation started Nov 1, 2016 at 6:10.
Nov 1, 2016 06:10
I'm going to continue ranting for a bit, some stuff fresh in my mind.
Feel free to ignore anyone present.
I'd say I'm productive in C because I'm close to the hardware, that sounds like some cliche generic thing you'd hear but its true.
C is a very small language but has several quirks and older compilers can be annoying, (Dev C++, Borland circa 2007 anyone)
@iKlsR w... w.. ww... word???
ow....
Funny enough I never understood pointers for like 2 years until one day I read an article where they used physical addresses and it just clicked. Granted I had very limited resources a decade ago.
Getting back on track.
@someonewithpc Just explained pointers to me the other day
Anyone with basic computer knowledge should know that at the core processors are basically 1s and 0s.
Made everything much clearer (the syntax is really the most confusing part)
Nov 1, 2016 06:15
Some scattered bits here, lots of stuff on my mind now.
For a few years I used C and compilers and treated them like black boxes, ie I knew what X did but not how it did it.
@gandalf3 I'll give you a good explanation in a bit. Go uses pointers as well.
So one day I wondered, how does C work?
Languages don't really exist in a sense, they are interpreted (run in a virtual machine) or they are converted back to bytecode for the computer to run them linearly.
So your fancy loops and generators and closures in your high level language are for your ease of use. When the compiler is finished with it all the computers sees is 00 FA EC etc
So yeah, I did some research and found out some stuff.
Imagine a small hiearchy like this
Microcode -> Bytecode -> Assembly -> C -> (Python, blah blah blah)
And then below microcode imagine LOGIC GATES, transistors
and below that imagine the simplest thing or its complement, boolean algebra in a sense
AND | OR | XOR | NOT
this is what makes up your fancy i7
basically a circuit takes some input/current and turns bits (transistors on and off)
for example the arguably simplest computer you can build is a HALF ADDER
which is simply 3 gate to add two bits
very basic VERY VERY basic
it only gets complicated when you start looking at larger numbers, you make full adders, start adding 8 bit numbers etc, basic computer, add a timer (because these things run fast)
See
So yeah, in a nutshell to understanding C we somehow went back 50 years
we can now even make a 8 bit cpu in some logic program like logic.ly
you can even design your own and then program it as seen above
So yes, when Intel makes their processors they write in something called microcode and there is something even below that I think
these are hardcoded into the processor so when it sees certain sequences it does X, Y, Z
for FAST FAST access we have registers in the cpu, imagine these as temporary variables
we introduce new concepts like stack pointers, instruction pointer
at the core your cpu executes stuff linearly, your program of bytes is loaded into memory and the cpu executes the instructions in order, functions are simple jumps to another set of memory then back using the stack
So yeah, now who wants to write programs in bytecode / HEX, nobody thats who
remember early computers were programmed with switches and buttons, on off
then punchcards then basic languages with mnemonics that were still converted to bytecode
So introduce something like FORTRAN or lets just use assembly
microsofts dos .com is an exception I think, keeping this dumbed down and loose
So yh again these languages are just to make our life easier
so assembly MOV EAX, 12 puts the value 12 into a register for us to use later
that is easy for us to read, the computer as output from that will get whatever the OPCODE that stems from the MICROCODE corresponds to and perform some toggling of bits inside the cpu
But assembly is still hard to understand as shit
introduce C
C compiles down to assembly which in turn goes to bytecode
So that in a nutshell is how I can be efficient in C
I know assembly ( a bit ) or the basics of what it does.
I know the pipeline
And this is basically how old portable devices worked
instruction sets
thats how we can have emulators
blah blah blah
write a basic virtual machine
so yeah if you can break down what is happening under the hood you can get super productive
you can optimize your code directly via assembly, gcc -S file.c you will get assembly output, intel syntax is nice
Python is written in C
python is an interpreter, it also has its own special instruction set that then maps to a C runtime methinks
use python's dis module to get "assembly" output of your code, ever notice .pyc files? these are bytecode that ur file gets converted to to run very fast
Same for java .class files
bytecode that the JVM (remember this above) runs
Python and Java are more protable than C because they provide a layer that runs their specific bytecode as opposed to raw C that generates for the architecture you are on hence why you have to recompile
Then we get cute things like ELF and PE file formats
etc etc
END RANT
Nov 1, 2016 06:36
s/rant/book/
I wrote a bit about blackboxes here ricardolovelace.com/vim-is-not-a-black-box.html
using Vim as an example
If anyone is generally interested in this, I can go for hours.
:D
This is how you get to be a good programmer, breaking down a problem into tiny digestable bits.
Understand something at its core and you're suddenly in control.
Once you get the connection everything you've ever read or learnt falls into place, logic gates, algebra, circuits etc
For example you might wonder how a touch screen works?
remember... 1s and 0s
there are many types but the most common is capacitive
behind this thin layer we have a flat bed of inputs that are say set to 0
swipe you turn on some and this motion gets translated into some movement that then uses to execute some motion
same thing applies to Infrared
you can easily reverse engineer your home remote with a breadboard, arduino and a IR sensor
So yeah. I can be productive in C.
Thanks.
and PHP is written in C
aha!
php is in itself a framework already for C in a sense so PHP frameworks are already on a framework layer
AND ALL OF THIS APPLIES EVERYWHERE
web, packets?? 1s and 0s
UDP TCP are simply sets of bytes
your Wifi
For anyone who has seen the matrix, when Neo understands and starts seeing the matrix for what it is, a simulation/code. That is how your eyes will open when you understand that everything computing is 1s and 0s.
quantum computing is another good rant where we can have super states
schrodinger, time crystals? maybe some space civilization out there with there advanced tech uses 10 base digits instead of 2
that could make our fastest processor look like a chip in a smart fan
so to repeat myself, once it clicks the possibilities are endless
Pointers
C syntax
We declare a pointer like this int gift = &present;
Quick fact, did you know you can have a pointer to a pointer to a pointer ... int ***a, uses are not so useful tho.
So a pointer simply points to the address of another variable.
Say present = 5;
Lets look at our program in memory
address | value | symbolic name
0001 | 5 | present
0005 | 0001 | gift
see that gift holds the address of present
this means that if present is changed, the address will remain the same regardless, it already has its position in memory on the stack.
gift will always have the address of present
to get the value at that address we use the dereference operator *
so *gift = 5;
while gift = 0001;
we use the reference operator to get addresses
this is more powerful in C++ a bit...
you might have also heard about copying by value vs copying by reference
so yeah what is the point of pointers
these are mostly used to allocate memory
when you run your program there is a part of it that has space for your declared vars and that is limited
so local variables are declared on something called the stack
pointers are on the heap (global memory)
we tell pointers to go into ram and secure memory as needed
malloc
new
dynamic!
when we are done with this additional requested memory we should free it (return it back to the os) so other apps can use
delete
free
hope that gives a bit more context @gandalf3
1s and 0s...
Nov 1, 2016 07:00
yes, that all makes sense
ok
A real life example would probably be buying a house and having to take a loan from the bank.
 
Conversation ended Nov 1, 2016 at 7:01.