r/learnprogramming • • Dec 09 '16

Lovable dude does 30 min or less "coding challenges" in Processing while giving in-depth explanations of the process. Really informative and entertaining stuff.

1.8k Upvotes

67 comments sorted by

79

u/[deleted] Dec 10 '16

I wish my professor had a quarter of this guys enthusiasm. im in my last semester of my computer science degree and he had the balls to ask me (in front of the whole class) if i was making the right choice career wise, all because i had asked how to initialize a background worker inside a class method..... im glad i can watch ths guy and get excited about programming again :)

67

u/mynameisdifferent Dec 10 '16

Fuck that guy. Sounds like he's the one that made the wrong career choice if that's his response to someone asking a question.

8

u/PC__LOAD__LETTER Dec 10 '16

A teacher should never say something like this. That being said, I have a sneaking suspicion that we're not getting the entire story here.

9

u/[deleted] Dec 10 '16

I consider myself a good student, never turned in anything late and only missed one class when my son was born. He's just a jerk.

6

u/PC__LOAD__LETTER Dec 10 '16

Well if that's the case, then yeah screw him.

1

u/DASoulWarden Dec 11 '16

Maybe he doesn't consider you a good student...

1

u/iFappster Dec 14 '16

Classic mirroring

16

u/kangaroofie_ Dec 10 '16

If I had a nickel for every time I had to google something simple I would be rich. If you don't use something often then you're not going to remember it. The important thing is that you can navigate the docs. That professor is not doing their job well if that's how they respond to a student asking a question.

3

u/Isoyama Dec 11 '16

I think your comment have conflicting parts. You think that it is a norm to self-learn and relearn technical aspects, why professor shouldn't expect the same? From the description it isn't some basic course. And what is the answer supposed to be? "Just use pthreads"? Student could have gotten that answer within 5 sec with google and he will have to do it anyway to learn exact syntax.

1

u/kangaroofie_ Dec 11 '16

Yeah you have a point. Either way I think that professor should have handled that situation better.

30

u/ishitondreams Dec 10 '16

...What's a background worker?

96

u/dumpster_dinner Dec 10 '16

Are you sure you want to be in r/learnprogramming?

16

u/ishitondreams Dec 10 '16

It's alright, you can go to r/learnedprogramming and be just as helpful there.

37

u/CuteHoor Dec 10 '16

I think he was making a joke!

Anyway, a background worker is essentially a process that runs independently of the main thread. They are useful when you have to do some work where you don't depend on the result right away and it may block the program for a while if done on the main thread.

8

u/swyx Dec 10 '16

Disappointed that this is not a real sub

1

u/coolshanth Dec 11 '16

I think that's really apt. There's no such thing as learned, rather you're always learning.

24

u/PC__LOAD__LETTER Dec 10 '16

It usually means that a thread is launched which will run some code in the background.

Here's a very contrived example in C that doesn't include any error checking. In the main() function, 3 background process are launched. They then just sleep until they're told that they can exit (in a useful program, they would be doing actual work). The main process sleeps a bit, prints some stuff out, tells the workers that they can stop running, and then waits for them all to stop.

thread_example.c

#include "pthread.h"
#include "stdio.h"
#include "unistd.h"

#define NUM_WORKERS 3

/* global variables, accessible by all threads */
static int _thread_id = 0;
static int _keep_workers_alive = 1;

/* function that will be started in the background */
void *
worker_func()
{   
    int id = ++_thread_id;
    printf("    Thread %d created, waiting to exit...\n", id);

    /* sleep until the main thread tells us to stop */
    int slept = 0;
    while (_keep_workers_alive == 1) {
        sleep(1);
        slept++;
    }   

    printf("    Thread %d exiting after sleeping %d seconds\n", id, slept);
}   

int main(void)
{   
    /* an array of structs that will hold our worker references */
    pthread_t worker_infos[NUM_WORKERS];

    printf("Main thread starting up %d workers...\n", NUM_WORKERS);

    /* launch worker threads */
    for (int i = 0; i < NUM_WORKERS; i++)
        pthread_create(&worker_infos[i], NULL, worker_func, NULL);

    /* ensure the final worker has had time to print its status */
    sleep(1);

    /* sleep for a short (arbitrary) amount of time */
    printf("Main thread sleeping...");
    for (int i = 1; i <= 5 /* arbitrary */; i++) {
        printf("%d...", i); 
        sleep(1);
    }
    printf("\nMain thread: telling workers to stop.\n");

    /* flip our switch that tells the workers to quit */
    _keep_workers_alive = 0;

    /* wait for all workers to exit */
    for (int i = 0; i < NUM_WORKERS; i++)
        pthread_join(worker_infos[i], NULL);

    printf("Main thread exiting after all workers have finished.\n");

    return 0;
}

How to build

$ gcc thread_example.c -o thread_example -lpthread

Output

$ ./thread_example 
Main thread starting up 3 workers...
    Thread 1 created, waiting to exit...
    Thread 2 created, waiting to exit...
    Thread 3 created, waiting to exit...
Main thread sleeping...1...2...3...4...5...
Main thread: telling workers to stop.
    Thread 1 exiting after sleeping 7 seconds
    Thread 3 exiting after sleeping 7 seconds
    Thread 2 exiting after sleeping 7 seconds
Main thread exiting after all workers have finished.

Note that all of the threads share the same program memory space, so you have to be very careful if you're sharing variables between them so that they don't step on eachother.

3

u/GreenFox1505 Dec 10 '16

When I met a co-worker, he told me that the he wants to be a teacher. I hope he never lives that dream.

I'm no longer convinced that Indians are hard to understand. Just the ones who want to teach.

-16

u/Antinode_ Dec 10 '16

If that's all it took to discourage you from programming while in your last semester then maybe you should consider the career choice (serious)

14

u/Lusane Dec 10 '16

You're reading a bit much into his comment. He didn't say his lack of excitement for programming was caused by the professor's comment. I think it's totally normal to not be excited to program after waves of class projects and exams

21

u/Vaylx Dec 10 '16

Awesome channel! Any other channel that teaches Python in a fun way?

16

u/ItsAllSoClear Dec 10 '16

HEY it's the Coding Rainbow guy! He's awesome. I just realized that he clearly got slammed with some copyright junk because he removed all references to coding rainbow. It now just says [undefined]. He even edited the coding rainbow song :(

10

u/TribalLion Dec 10 '16

That explains so much. I was confused as to why things were blurred out.

8

u/shiffman Dec 10 '16

Yup, I'm working on a new name!

2

u/ItsAllSoClear Dec 11 '16

Oh man! Bummer folks ruined the fun. I loved the parody song (which is how you might be able to battle for Coding Rainbow?).

Taking the opportunity to say your Programming A to Z is my first introduction to JavaScript. I have a year of programming under my belt but as someone who's incredibly rusty at HTML and didn't have to use JavaScript at the time it was incredibly helpful. It's like comfort food, really. I know the concepts but seeing how it runs side by side with your HTML and you can see the changes in real time really made the whole thing less intimidating. So thank you!

If you're ever taking requests- I will have to teach myself basic SQL over the beak. ;)

Lastly, I know you're a Yale graduate so hello from down the street at UNH, haha. You probably had one Fischer and I have the other.

1

u/[deleted] Dec 12 '16

I've been watching your videos all day. I haven't been this excited about web dev programming since I discovered CSS ages ago. Thanks for that!

10

u/darthirule Dec 10 '16

I knew who you were talking about before I looked at the post. Love this guys videos.

10

u/Jmannm8400 Dec 10 '16

I actually discovered Daniel the other day, when I came across the video where he attempts to create a Snake game in 15 minutes. He seems like quite a good teacher who can make learning programming fun and less intimidating! I'd definitely recommend his videos, which are available on his YouTube channel.

4

u/obviouslyCPTobvious Dec 10 '16

How did you discover his channel? He has been experiencing a large increase in viewers and he was asking if anybody knew where they were all coming from. He's doubled his subscribers to about 100k in the last 2 weeks!

1

u/Jmannm8400 Dec 11 '16

I believe it was a related video on YouTube. That's great, though, that he's seen such a large increase in subscribers recently!

10

u/rob132 Dec 10 '16

Every time I watch his coding challenges I fell like I'm Einstein. When I try to do it on my own I fell like... the opposite of Einstein.

9

u/[deleted] Dec 10 '16

He really makes good content! It's all either in Java or javascript, but it pretty much is applicable to all languages in the way a programmer should think and how to make and fix problems and issues! What a legend.

8

u/[deleted] Dec 10 '16

His one making the snake game is adorable.

6

u/royaltrux Dec 10 '16

That was cool, thanks.

6

u/[deleted] Dec 10 '16

This is great.

6

u/bradgillap Dec 10 '16

I'm not even a coder and Shiffman is on my list of heroes I'd like to meet one day.

11

u/[deleted] Dec 10 '16

His channel is amazing, thanks for sharing

5

u/[deleted] Dec 10 '16

Somehow I knew this was about him before I opened the post.

This guy is really amazing. His enthusiasm is highly contagious, his explanations are easy to follow and he has just the right sense of humor. Not to mention that his content is really interesting too.

4

u/kr0zz Dec 10 '16

wow!! I love the way he teaches. I was planning on sleeping then I saw this thread and saw his entire video. If anyone knows of anyone else who teaches like him (doesn't have to be about programming) please tell me! :)

4

u/[deleted] Dec 10 '16

What is Processing commonly used for?

4

u/Side_order_of_road Dec 10 '16

Looks like its a simple language based heavily on Java to teach those new to the visual side of programming. So not much uses it specifically but it's great to learn with as it teaches ways of thinking that apply to almost any code dealing with 3d and 2d models.

1

u/theswillmerchant Dec 10 '16

The creators of this music video used it to make the projected animations https://www.youtube.com/watch?v=RsQjC5zVnt8

3

u/rakesh11123 Dec 10 '16

I found that dude a week or two ago and I already love him! The best video of his of probably the challenge where he builds the snake game in ~15-20 mins

2

u/pigtailz- Dec 10 '16

My favorite

2

u/nickiter Dec 10 '16

That's awesome.

2

u/AtomicGreenBean Dec 10 '16

This was so cool.

2

u/cartrman Dec 10 '16

I love this. Thanks for sharing.

2

u/Anna_Mosity Dec 10 '16

I need to remember to watch this when I'm not on my cell phone.

2

u/iStayGreek Dec 10 '16

This is really great, thank you.

2

u/Thunderofdeath Dec 10 '16

is this like beginner stuff?

2

u/itsmeBOB Dec 10 '16

Thanks a lot for linking this channel. I immediately subscribed. I cannot wait until I can code the way this guy codes.

2

u/[deleted] Dec 10 '16

Fantastic channel. I recommend watching his videos on fractal trees if you enjoyed this one.

2

u/cs1001001 Dec 10 '16

Man! I want to be as excited as he is while programming!

2

u/[deleted] Dec 10 '16

This is the first time I've heard of processing seems very cool

2

u/im_a_ninjaaaa Dec 10 '16

His name is Daniel Shiffman, and he is the best!!!

2

u/Happy-feets Dec 10 '16

Isn't this the Coding Rainbow series?

1

u/snarleyWhisper Dec 10 '16

Daniel is amazing, his book "The nature of code" was my intro to generative art practices. The entire processing team is really friendly if you get a chance to meet them in person.

1

u/Dreamikoo Dec 11 '16

lol, i knew who you were talking about before I even clicked the link.

this guys great

1

u/damaged_but_whole Dec 11 '16 edited Dec 11 '16

This guy is great!

I ran into a snag right away trying to follow him, though.

His code at 3:53 in this video is:

var flower;

function setup() {
    createCanvas(400,400);
    flower = {
        name: "sunflower",
        col: color(200,220,0)
    }
}

function draw() {
    background(0);

    fill(flower.col);
    text(flower.name, 10,50);
}

Shouldn't this be able to work in the console? It just returns undefined

E: Hm, well I downloaded the p5.js editor that he uses in the video and it works when I put the code in there. I guess it's not straight javascript and some of those functions are part of the p5 library.

1

u/[deleted] Dec 12 '16

Yeah, they are part of p5. https://p5js.org/reference/

0

u/[deleted] Dec 10 '16

[deleted]

17

u/gar2020 Dec 10 '16

Hahahaha same this guy is awesome. One day I'll try to tackle his nature of code book

14

u/fredspipa Dec 10 '16

It might look intimidating, but it's surprisingly easy to follow along and you get a few laughs on the way. It's the first programming book I couldn't put down simply because it was so exciting.

2

u/KyleOrtonAllDay Dec 10 '16

I figured it was a /u/CarlH video

0

u/[deleted] Dec 10 '16

[deleted]

2

u/[deleted] Dec 10 '16

I checked the userpage but it looks like it went through years of inactivity, then a troll appeared and claimed to have faked their suicide... what happened?

5

u/grandking3 Dec 10 '16

raped his son, hung himself in prison.

4

u/[deleted] Dec 10 '16

Fucking fuck.