
Helloooo! I am Moose! They/Them/He/Him I am a embedded software engineer with autism, depression and anxiaty ( Wooo! ). I post about... whatever I want... software things, mental health things... whatever I feel like Feel very wellcome to send me asks about... anything that strikes your fancy :3
266 posts
What Are Strings???
What are strings???
So, on the codeblr discord there was a question which is hard to answer unless you already fully understand what a string is... So, what is a string?
And this is a great question! Because to answer it we will learn a hell of a lot!
To answer this, one needs to know what an array really is. This is important in any language you write in. But in most languages it only becomes important to know when you get to optimizing code.
So for most, it is fine to think of arrays simply as collections. But in C, you need to know what they truly are to work with them (Which is why newbies are often taught C to learn these things)
I will use drawings and links to godbolt code examples I made, to help you understand things.
To explain what strings and arrays are, I will use a trick that you may also want to copy if you have a hard time learning concept in programming or electronics.
Try to to "re-invent" it. By going step by step into the things that required it to be invented, and how it was done.
So arrays. They are a way of storing many variables in one place, and work on them very very efficiently.
We start with having variables. Each variable have an address where they are in memory, and a value at that address.
An address is just a number. Nothing more. But to make it clear when we are talking about them, traditionally you write it in HEX. These numbers are marked with "0x", as in, to write "6" in Hex, we write "0x6"
Now, on each address you can store 8 bit. To store values that are larger, we use more than one memory address.
Ok, with all info, let us draw the example we will use, and write the code:
We will have 3 numbers. Each takes 16 bits:

https://gcc.godbolt.org/z/cse64Kd6x
(Notice that the adresses counts DOWN. This is for stack and heap reasons we will not explain here. But just know that we count DOWN, not up when it comes to adresses on the stack, which is all we will work with here.)
If we know the type of a variable, we also know how much space it takes.
So to really know a variable, we need to know its type, and its memory address.
Now, if we create these variables one after the other they will be placed right next to each other in memory.
Then we can create a pointer! A pointer have a type they point to, so it knows how much space the variables takes, and a memory address. We will create it pointing at the first variable!
Let us draw it on the example:

https://gcc.godbolt.org/z/9abqMjrs3
And now, if we want to work on all of our values, we simply do whatever we want, and then subtract 2 from the pointer to get to the next value, and then work on that one, and so on.
If we want to add 1 to every value, we could do this:
Step 1, add 1

Step 2: Move pointer

Step 3: Add 1

And so on and on! :D
https://gcc.godbolt.org/z/7KGadT868
This is how arrays works. But instead of us having to remember to count DOWN, and what size variables are we have gotten all this build into the language. It also GARANTEES that the variables are placed next to each-other in memory (This is not actually guaranteed when you use single variables like we have in the examples... NAUGTY US!)
So this code does exactly the same as we just did. And as you can see it is MUCH easier:
https://gcc.godbolt.org/z/KWxc939v4
So as you can see, a array is... more or less a pointer that you cannot change (because it always point at the first element), also known as a const pointer. And instead of moving the pointer, we use the index... which is just "The adress of the first variable, and then move it down as many times as the variables size times the variable number we want"
And a string... is a specific kind of array we often need, because we often need strings of characters. A string is a array containing elements that are characters.
If you are using ASCII, that is 8 bit signed values
If you are using UTF-16 then it is 16 bit signed values
See? It is super easy to explain what strings are!
... IF you know what arrays are... and why we use them....
-
nourhanlwt reblogged this · 1 year ago
-
nourhanlwt liked this · 1 year ago
-
nothingbutwaffles liked this · 1 year ago
-
iceshaadow liked this · 1 year ago
-
batmanslemontea liked this · 1 year ago
-
frog707 liked this · 1 year ago
-
khoidi liked this · 1 year ago
-
cyberfolktale liked this · 1 year ago
-
codemerything reblogged this · 1 year ago
-
codemerything liked this · 1 year ago
-
quietmarie liked this · 1 year ago
More Posts from Moose-mousse
Managers are mostly incompetent
I freaking hate people sometimes. Talked a bit casually with the boss of the software department at my internship. Mentioned that no one is hiring freshly educated software engineers (unemployment is at 12% after a year here). Only ones already working in firms during their study (IE, studying worse because they have to work next to it) gets hired.
This is much like the carpenter firms always bitching that they need more journeymen, while none of them take in apprenticeships. They are complaining about a problem, while THEY are creating the problem. He basically said that he agrees, but that THIS firm do not exclude newbies. But when I asked him how many newbies they hire, he had to admit the number was 0. Because they found better candidates for those jobs you see! He DID not get the point. You NEED to force your firm or industry to to hire freshly educated people as a percentage of new hires. It is called a Ulysses pact, it is NOT a new idea.
If you only judge on a job to job basis who would be best…
Then you will only hire experienced people. Experienced people are basically always better than fresh ones.
So if you do not have a policy in place, you are making a implicit choice to not hire newbies. Choosing not to do something, is STILL a choice. I know systems, software and programming, in order to be a software developer. So why do managers not know basic managing?
WOOOOOOO!
IF ALL GOES WELL IM GETTING TESTOSTERONE SOON
That's amazing! Big congratulations! I really hope everything goes well so that you can get started on it soon! ❤️
A beginners guide to GIT: Part 4 - How to use GIT as 1 person
Table of content: Part 1: What is GIT? Why should I care?
Part 2: Definitions of terms and concepts

Part 3: How to learn GIT after (or instead of ) this guide.
Part 4: How to use GIT as 1 person

Part 5: How to use GIT as a group.

When it comes to not getting in each other's way, working alone is the simplest (It has a lot of other drawbacks). This is the simplest way to use GIT. You can do it with an external repository as a backup or just locally on your computer. It depends on how important your project is. If your laptop crashes tomorrow, which projects would you have a really hard time losing? Better to have an external backup for that. Github is often used for this (Maybe less now that Github makes machine learning AI’s, and so ARE stealing your code to train their AI on.) but you can also use Bitbucket (Which... may also steal your code...) and there are many many others out there. GIT is often used in certain patterns, called “workflows”. These have you working in more or less rigid ways to make it simple to work together. But since you are working alone, you do not risk others changing your code while you are working, so you can do it the simplest way :D
I will be doing a step by step guide that you can follow along. I will be doing it on a completely empty project and making a tiiiiiny program in C. This is because it is super simple. You do NOT have to know C to follow. You can also follow the steps with your own already existing project.
I PROMISE you, GIT cannot hurt you. Worst case scenario is that you fiddle around and break the repository part. (Meaning the files in the .git folder). But your files will always be safe.
(If you do not have git installed, check out part 3 for that)
First, I make a folder, navigate my shell into it, and call git init:

By the way, you can get used to GIT messages like this that tell you all your options, and explain what GIT has done for you. GIT is very good about giving you as much help and info as possible,
Now I will teach you the most important command in GIT.
It is more important than any other. Ready?
git status

This makes GIT tell you what git thinks is happening right now. What issues there are and what files are tracked, untracked or have been changed. Use this command often, especially while you are new to GIT, run it after every other command. It is how you learn what GIT is doing and thinking :3
Since our repo is empty it tells you what branch you are on (master. The only branch we will need since we are working alone)
and that you have not made any commits.
It also tells you the commands git think you will want to use on files. Since our repository is empty, it tells us to create some files, and then how to add them :3 So let's do that:
I have added my tiny program, as you can see:

Now let us see what GIT thinks we did:

Now, since there have been changes, git shows us them.
Files can be untracked tracked and not changed (In which case, git status does not show them) tracked and changed.
Right now, main.c is untracket. Which basically means GIT have no idea about this file, other than it is in the folder.
Ok, let us commit(save) the file. GIT tells us this is done with git add <File> . So we will write git add main.c
Then we use git status again to see what happened git status

And yeah, our file is now ready to be committed. So lets do it! git commit -m “My first commit!”
The “-m” option is to write the git update explanation directly in the console instead of using an external program to do it. Done You have now committed your code! It is now saved!
git status shows that everything in the working tree is as it was last time we committed (Duh. We JUST committed)

I will now make some changes to the main file:

Git status shows us main.c was changed...but what if we wanted to know what was changed in more detail? How will we get status to do that for us? Let us find out! git help status
git then shows the help page for status And there we can see this part:

So if we write status with 2 -v arguments, we get all the details. Let us try:

And look! It shows us EXACTLY what lines were changed! I stage the changes and commit:

And you have now learning enough about GIT to use it.. You now have all your work saved, in different commits. If you ever want to know all the commits you have made, write git log:

And if you want to know what a specific commit did, you copy the name of the commit, and write git show:

Now, everytime you want to save your work, you
1: Write/change the files you want
2: Add the files you want as part of this commit
3: make the commit These three steps are your workflow.
If you have a remote repository, then you add them steps
4: push to remote repository
To do this step, you can actually just write
git push
If you have set up a remote repository, then it just works. If you have not, then git will tell you what to do Whichever remote repository you use will tell you if you need to do other steps, like setting up passwords or ssh keys. They will also tell you how to set up the remote repository (That is not a GIT thing, that is a bitbucket or a github thing, so refer to whichever of those sites you want to use) And that is all! Every time you commit, your project is saved (it is smart to commit often, but usually only commit when your project can be compiled.) And whether you use a remote repository or not, you now have a fully valid GIT repository, and all the git tricks can be used on your project!
FINALLY got done with the Beginners guide to GIT
So a long time ago I made a poll to help me make a Begginers guide to GIT because a lot of people seem to have trouble with it. https://www.tumblr.com/moose-mousse/722172571753365504/going-to-make-a-getting-started-with-git-post?source=share
And I know for a fact that my University taught it horribly. (Or rather... did not teach it at all)
I REALLY tried making this guide as short as I possibly could. Explaining only what you need to know, while trying to clarify what most people find confusing. But it still is too long for a single post. So, I have split it into 5. The post each links to each other, so you should be able to go back and forth easily.
This guide is going to be pure GIT done via the command line. 2 reasons for this:
1: GIT GUI’s are really handy, but they abstracts away a lot of the newbie help GIT is trying to give you. Bitbucket, Github, Jira, and other services use GIT but usually add extra bits that are specific to them. So to know how they are different, it is smartest to learn pure GIT first. And since they are 99% GIT, you will be able to use them with no/little trouble.
2: Because I use the command line, it is easy to build your own automation tools. Simply have a program write git commands to the shell and/or read outputs from git commands and use them to visualize whatever you want, however you want. That way you can have whatever shiney graphics your heart can code up. All the tools you can find (Like Github desktop or gitk) are simply doing this. (incidentally, if any of you make a pretty visualization of GIT? Show me! I wanna see a dog themed GIT graph! I wanna see pink log outputs! Make it yours!)
Table of content: Part 1: What is GIT? Why should I care?
Part 2: Definitions of terms and concepts

Part 3: How to learn GIT after (or instead of ) this guide.
Part 4: How to use GIT as 1 person

Part 5: How to use GIT as a group.

I just downloaded a program, as a git repository. It allowed you to have it work in several different ways. Which was achieved by simply using "git checkout" to check out whatever branch you want. I love it. That is so smart!