Comment on: C or C++: Which is the language you prefer?
6 08 Sep 2016 14:09 u/HentaiOjisan in v/programmingComment on: 400,000 GitHub repositories, 1 billion files, 14 terabytes of code: Spaces or Tabs?
You mean whats the advantage of tabs to using spaces?
Easy. Anyone can change the visual size of the indentation without having to touch your code. Some people like 2 spaces, others 4, others 8. If you have tabs, just changing the visual size of a tab is enough. You don't have to touch the code. If you have spaces, on the other hand, you must change the whole project or be forced to the indentation of the original devs.
Spaces are used for alignment. For example, a long line split into two:
<tab>if(check1 == bar && check2 == baz &&
<tab>...check3 == foo && check4 == 42)
<tab>{
<tab><tab>whatever();
Dots represent spaces, <tab> tabs. That way the conditions are aligned even if the visual size of the tab changes.
It is more difficult to make errors (like coping from a website or something like that that uses a different indentation; also, tabs are only using for indentation, while spaces are used also for other stuff). And they use less space (although this is no longer a problem...).
That way everyone is happy. Spaces don't have any advantage other than people being lazy with the alignment, and some IDEs using that by default.
Have some flamewars: http://programmers.stackexchange.com/questions/57/tabs-versus-spaces-what-is-the-proper-indentation-character-for-everything-in-e
Comment on: 400,000 GitHub repositories, 1 billion files, 14 terabytes of code: Spaces or Tabs?
Why? You cant change the spaces equivalent to a tab in Solaris?
Comment on: What is your favorite comment you came across in code?
I like this one:
// sometimes I believe the compiler ignores all my comments
And this one;
#define TRUE 0 // Happy debugging suckers!
#define FALSE 1
Comment on: Resources to learn C?
Yeah, I really recommend them too! However maybe they are a bit hard for someone who has never programmed at all... And for the C one you need (or at least it's highly recommendable) to use linux too. And if he is new to all that it can be a bit overwhelming.
I quote their "The setup" part about Windows:
Windows
For Windows users I'll show you how to get a basic Ubuntu Linux system up and running in a virtual machine so that you can still do all of my exercises, but avoid all the painful Windows installation problems.
On the other hand... learning linux at the same time never hurts! And we are very friendly at /v/linux :D
Comment on: Converting Binary to Image
Now with moar 1337 bro!
#define HEIGHT 42
typedef uint16_t data_type;
extern data_type data[HEIGHT];
signed int x, y=0;
data_type *ptr = data;
data_type bit;
while(ptr < data + HEIGHT)
for(x=sizeof(data_type)*8-1, bit = *(ptr++); x>=0; x--, bit = bit >> 1)
{
bit & 1 ? paint_black(x,y) : paint_white(x,y);
if(!x)y++;
}
Comment on: Converting Binary to Image
The /v/programming way:
#define BITS_IN_DATA 16
#define HEIGHT 42
extern uint16_t data[HEIGHT];
unsigned int x,y;
for(y=0; y<HEIGHT; y++)
for(x=0; x<BITS_IN_DATA; x++)
{
if(data[y] & (((uint16_t)1) << (BITS_IN_DATA - x - 1))) // :D
paint_black(x,y);
else
paint_white(x,y);
}
your welcome m8
Comment on: 6 tips for teaching kids to code
I did love programming when I was a kid (and I still do). Specially dark low level stuff. One of my first programs was some kind of game of life thing and just loved creating my own "life" and worlds. I saw on the TV that someone was experimenting with something like that and I tried to mimic it. It didn't have any particular purpose but I still loved programming it. And I was like 12 or so.
I did also program my calculator and I also loved it. I once finished my math exam waaay too early and my teacher told me to stay quiet in the classroom until the time was over, I was bored so I just programmed a small game in my HP calculator (it was one of those now old RPN calculators that only had 2 rows of characters).
So my opinion is that kids can love coding, even if it doesn't make a hard task simple again. For me programming has been like playing with lego and meccano: create what you want.
This. I don't like that in most universities they teach you first stuff like Java and the like, and then move to lower level. You need to understand how the computer works internally to be able to program good imho, and high-level programming languages teach you the other way around. They are very useful, but once you know how the lower bits work!