These are chat archives for learnclang/general

2nd
Jan 2015
Marcus Ottosson
@mottosso
Jan 02 2015 09:08
I did add a version for Clang here, but it might be a good idea to add one for Clang on Windows too as it's a little more tricky.
Marcus Ottosson
@mottosso
Jan 02 2015 09:33
Visual Studio is an 11gb install, that's immense!
Marcus Ottosson
@mottosso
Jan 02 2015 10:53
It's much too immense to make a simple tutorial for, I'll put that on hold until we encounter a reason to use it.
Marcus Ottosson
@mottosso
Jan 02 2015 13:44
Adding @Byron who's got experience in C/C++!
Hello, @Byron!
Sebastian Thiel
@Byron
Jan 02 2015 13:48
Hi, and ... happy new year !
Marcus Ottosson
@mottosso
Jan 02 2015 13:48
HNY :)
We're talking about making a Python-to-C screencast video
By first writing a program in Python, and translating that into C, was that right?
Sebastian Thiel
@Byron
Jan 02 2015 13:49
This would be one way
another one would be to do it straight in C, but describe the differences in a fashion suitable for python programmers
Marcus Ottosson
@mottosso
Jan 02 2015 13:50
Which would be a live, non-recorded stream for anyone interested in joining?
Might be more interesting doing it live
Sebastian Thiel
@Byron
Jan 02 2015 13:51
I have no experience in streaming, and my upstream is 1Mb/s - maybe that's enough for a shell and an editor though ;)
Marcus Ottosson
@mottosso
Jan 02 2015 13:51
Me neither, but there's a first time for everything. I also think Google Hangouts can do that, that way folks can use their Gmails to join.
Sebastian Thiel
@Byron
Jan 02 2015 13:53
True - this would also make it into some sort of guided lesson
Marcus Ottosson
@mottosso
Jan 02 2015 13:53
Sure, people could chime in whenever anything is unclear.
Sebastian Thiel
@Byron
Jan 02 2015 13:53
Initially I thought it would be fascinating if you would do all the writing, because doing it yourself is still much better than watching others
Marcus Ottosson
@mottosso
Jan 02 2015 13:54
Yeah, a follow-along type of screencast.
What program would be good to go through?
By now, we can assume that we know how to setup our environment and compile a single .c file.
And I like the idea of doing it in Python first, as it may be how we do things in real life later on, as we're also assumed to know Python or Lua here.
Sebastian Thiel
@Byron
Jan 02 2015 13:55
If the .c file is compiled into an executable, anything goes
Marcus Ottosson
@mottosso
Jan 02 2015 13:56
Some of us are interested in making Maya plug-ins for example, and Python might be one way of getting started with a program for that.
Sebastian Thiel
@Byron
Jan 02 2015 13:57
Maya plugins require C++, which looks quite a bit different compared to standard C
Marcus Ottosson
@mottosso
Jan 02 2015 13:57
Yeah, I know, but I meant as a general workflow, to sketch it up in Python
We'll eventually move into C++, that's the idea anyway
Sebastian Thiel
@Byron
Jan 02 2015 13:57
Ah, of course
To my mind, writing a simple commandline program that takes a few arguments, and produces a result, will be all that's needed to learn a lot about C already
Marcus Ottosson
@mottosso
Jan 02 2015 13:58
A 45 minute screencast, at a specific date and time, making a commandline program, with you narrating and us following along and asking questions.
Sebastian Thiel
@Byron
Jan 02 2015 13:59
You can be as creative as you like in terms of what the "result" should be
Marcus Ottosson
@mottosso
Jan 02 2015 14:00
It might be better to assume we'll all be copying what you write, character by character. At least this early on.
I won't be able to be creative in C in real-time anytime soon, anyways. :)
Sebastian Thiel
@Byron
Jan 02 2015 14:00
Ideally, the python program is already prepared so one can start with the C program right away
Marcus Ottosson
@mottosso
Jan 02 2015 14:01
Sounds good to me.
Sebastian Thiel
@Byron
Jan 02 2015 14:01
Marcus, if you like you can present me with a 20 line python program that should be converted to C
Marcus Ottosson
@mottosso
Jan 02 2015 14:01
Let's let it simmer in the chat-room for a little while, see what people think when they get a chance.
Sure, I'll try and think of something.
Maybe a simple RPG?
Sebastian Thiel
@Byron
Jan 02 2015 14:02
we have 45 minutes, is that even possible ?
Ævar Guðmundsson
@agudmund
Jan 02 2015 14:02
yes!
Marcus Ottosson
@mottosso
Jan 02 2015 14:02
"You see a door, what would you like to do?"
  1. Enter
  2. Walk away
Haha, I don't know :)
Sebastian Thiel
@Byron
Jan 02 2015 14:02
45 lines of C code in 45 minutes, that's the limit
Marcus Ottosson
@mottosso
Jan 02 2015 14:02
Simple numeric options
Okay, a text-based RPG in 45 lines of code? :)
Aevar, you in?
Sebastian Thiel
@Byron
Jan 02 2015 14:03
there will be plenty of stuff to talk about when digging in, which takes time as well.
Ævar Guðmundsson
@agudmund
Jan 02 2015 14:03
as much as time allows, I'm in
45 lines of C code in 45 minutes, that's the limit == sounds awesome
Sebastian Thiel
@Byron
Jan 02 2015 14:03
Something simple like: Add all numbers given on the commandline
add 1 2 3
outputs 6
"add 1 2 foo" outputs 3
Marcus Ottosson
@mottosso
Jan 02 2015 14:04
I honestly think an RPG would require less code than a calculator.
Sebastian Thiel
@Byron
Jan 02 2015 14:05
As long as you can make it in 20 lines of python code, it should be fine
Marcus Ottosson
@mottosso
Jan 02 2015 14:06
Challenge accepted.
When is a good time for you to do the screencast?
Sebastian Thiel
@Byron
Jan 02 2015 14:13
For now anytime
And even though an RPG sounds fancy, I don't believe it's within the range of a 45 minute presentation that will try to teach you think C .
Trust me, even processing commandline arguments will be an enterprise on its own ;)
Marcus Ottosson
@mottosso
Jan 02 2015 14:15
We can always do more videos :) I think it's important to make videos interesting first and foremost.
Marcus Ottosson
@mottosso
Jan 02 2015 14:26

Epic RPG Storyline concieved.

image

Here's the options for the hero.

image

The game will not have any pictures I think, but rather reflect what happens through text.
Sebastian Thiel
@Byron
Jan 02 2015 14:36
My point is that I think everything about C is interesting and somewhat different when coming from python, and writing a fun RPG is not the point here. It's getting a gradual idea on how C ticks. Everything in my body is objecting writing an actual mini-RPG for demonstration purposes.
Marcus Ottosson
@mottosso
Jan 02 2015 14:37
Okay, no worries. It's better you decide what you would like to talk about.
Sebastian Thiel
@Byron
Jan 02 2015 14:37
Let's keep the slope gentle :)
Marcus Ottosson
@mottosso
Jan 02 2015 14:46

How about meeting in the middle? :)

Instead of adding numbers, we'll do a Rock-Paper-Scissor program?

$ rps Rock + Paper
Player 1 wins
$ rps Scissor + Paper
Player 2 wins

In which the first argument is Player 1 and the second argument is Player 2

Ævar Guðmundsson
@agudmund
Jan 02 2015 14:46
hehe, sounds excellent to me
Marcus Ottosson
@mottosso
Jan 02 2015 14:47
Actually, my example is inverted, but you get the idea :)
Ævar Guðmundsson
@agudmund
Jan 02 2015 14:47
if you randomize the second player you have a literal minigame
$ rps Rock
player 2 Paper, player 2 wins
Marcus Ottosson
@mottosso
Jan 02 2015 14:48
An excersize left to the reader. :)
We can add a difficulty level too, "Hard" means the machine always wins.
Ævar Guðmundsson
@agudmund
Jan 02 2015 14:49
haha
Sebastian Thiel
@Byron
Jan 02 2015 15:35
I like that one !
Marcus Ottosson
@mottosso
Jan 02 2015 15:46
Here's one way of doing it in 17 lines.
import argparse
choices = ["rock", "paper", "scissors"]

parser = argparse.ArgumentParser()
parser.add_argument("player1", choices=choices)
parser.add_argument("player2", choices=choices)

args = parser.parse_args()

beats = {"rock": "scissors",
         "paper": "rock",
         "scissors": "paper"}

if beats[args.player1] == args.player2:
    print "Player 1 wins!"
else:
    print "Player 2 wins!"
In Python, that is. :)
Sebastian Thiel
@Byron
Jan 02 2015 15:49
When done in C, there will be about zero resemblance, hope that's OK ;)
Marcus Ottosson
@mottosso
Jan 02 2015 15:49
As long as it's within 45 lines, all is well.
Should we also constrain it to not allowing multiple statements per line?
Otherwise, we'll just end up obfuscating the code to fit the line-length, and that's not really the idea I think.
Sebastian Thiel
@Byron
Jan 02 2015 15:50
45 lines - it's my arbitrary choice to make sure the example stays simple.
thus it can also be more if needed, but shouldn't be
There could even be multiple different styles of writing this program in C to learn different aspects about it.
Marcus Ottosson
@mottosso
Jan 02 2015 15:59
I think we should set a hard limit at 45 lines or less.
Cesar Saez
@csaez
Jan 02 2015 16:00
Oh man, this python to C mini-project sounds great! :D
I hope we can pick a date/time according to our timezones for the live streaming... Anyone not in Europe in the group?
Marcus Ottosson
@mottosso
Jan 02 2015 16:02
Yeah, that's the thing. If we're all in either Europe or US/Canada we should be able to fit everyone. But if New Zealand/Australia/Asia wants in too, we're in trouble. :)
Just to throw out a time of day, my ideal would be around 8 pm GMT+0/UTC+0. (Not sure about the formatting of those)
Cesar Saez
@csaez
Jan 02 2015 16:06
I'm in Chile at the moment (UTC/GMT -3) and hopefully will be in Australia from mid February onwards.
Marcus Ottosson
@mottosso
Jan 02 2015 16:07
Cool, @Byron is in Germany I think so that would be GMT+1
Sebastian Thiel
@Byron
Jan 02 2015 16:12
That's still correct
Marcus Ottosson
@mottosso
Jan 02 2015 21:07
Welcome @timmwagener and @sonictk!