Bradley :linux: :debian: :vim: boosted

#toyprogrammingchallenge

@bii @paleBlue @billstclair

Is anyone else interested in the current challenge, before I get ready to drop the next one?

I have shared the first one with some friends outside the fediverse and got some good reaction from them as well.

If you have some friends that might be interested please pass it along. I am not sure how well the #toyprogrammingchallenge tag federates so as I see that people have responded I will try to keep a list and keep you in the loop. If anyone is just interested in watching, either follow the #toyprogrammingchallenge or submit your attempt, or constructive coding recommendations and so forth.

Remember to use the # #toyprogrammingchallenge

Bradley :linux: :debian: :vim: boosted

#toyprogrammingchallenge

Unfortunately, I see no way to follow a tag, but as long as you remember to include the tag in your post all that gets posted against it will be searchable at least.

I am still looking to see more languages, and/or feedback on the entries we have so far. Also, anyone you know that is interested feel free to share it with them.

By the way, I updated my attempt to have a cleaner output by building up a tuple to pass to the print statement so I didn't need multiple output lines.

And thanks @freemo for the gitlab space.

git.qoto.org/Absinthe/ninety_n

Bradley :linux: :debian: :vim: boosted
Bradley :linux: :debian: :vim: boosted

I remember when I first started in computers the most common question (after can you fix my computer?) was "What is the best language to learn?"

Even as a C/C++ programmer I never felt comfortable suggestion a n00b start on such languages. Delphi/Pascal came to mind but wasn't as readily available.

Finally, I am comfortable making a recommendation. And like all my opinions, these are well reasoned, clearly thought out, and obviously 100% correct, and if you disagree, you are probably wrong about other things too :)

So my current answer is Python.

I am open to opinions and experiences. Discussion anyone?

Bradley :linux: :debian: :vim: boosted
Bradley :linux: :debian: :vim: boosted

Vim Window Commands have ex alternatives.

For example <C-w>o closes all other windows and keeps the current one. But you can do the same with :only

This is awesome and you can use the :help to find others.

However things like <C-w>J/K/L/M etc don't have such commands, what then? Well, that's where :wincmd comes in. It is the equivalent to <C-w> so you can use it instead so try :wincmd J or any of the other <C-w> commands...

Bradley :linux: :debian: :vim: boosted
@BradleySmall although not as popular as Debian, Knoppix recently moved away from systemd.
Bradley :linux: :debian: :vim: boosted

Oh, yeah, on that line right above the free(ptr); second from the bottom... That is where you might want to do something with ptr :) Sorry, I meant to put that in there.

Bradley :linux: :debian: :vim: boosted

/* If you are going to use realloc, don't make this common mistake! */

#include <stdlib.h>

int main (void) {

size_t size = 16;

char * ptr = malloc(size);

size = 32;

/* This is wrong!

ptr = realloc(ptr, size);

ptr is allocated. If this call fails ptr will be set to NULL, and
the allocated memory will not be freed.
*/

char * tmp_ptr = realloc(ptr, size);
if (NULL != tmp_ptr) {
ptr = tmp_ptr;
} else {
/* This is the error case */
free(ptr);
ptr = NULL;
}

free(ptr);
}

Cute little trick for gcc or clang users: (run valgrind on it afterwards)

<stdio.h>
<stdlib.h>
<string.h>

__cplusplus
extern "C" {

void raii_char_free(char **);

raii_char_pointer char * __attribute__ ((__cleanup__(raii_char_free)))

__cplusplus
}

void raii_char_free(char **p) {
free(*p);
}

int main (void) {
raii_char_pointer ptr = strdup("abcdefg");
printf("%s\n", ptr);
return 0;
}

Okay, I guess I have caused enough trouble tonight. Have fun...

::wonders aloud:: would people like my C tips better with Cat Ears?

use a Makefile early and often.
Learn how to use a Makefile... Well.

Write unit tests before code.
Write documentation before code.
Use autodocumenting code like Doxygen.

Show more
LinuxRocks.Online

Linux Geeks doing what Linux Geeks do..