-
Notifications
You must be signed in to change notification settings - Fork 1
Mentoring session 14 Dec 2011 Arun and Eric
ericgj edited this page Dec 18, 2011
·
3 revisions
[04:45 PM] ericgj: satchmorun: hi I;m back
[04:45 PM] satchmorun: hi
[04:45 PM] ericgj: where do you want to start?
[04:46 PM] satchmorun: i don't have any specific questions at the moment, so maybe we can start with anything that jumped out at you?
[04:47 PM] ericgj: sorry, I'm back
[04:47 PM] satchmorun: no prob
[04:47 PM] satchmorun: i don't have any specific questions at the moment, so maybe we can start with anything that jumped out at you?
[04:47 PM] ericgj: ok
[04:47 PM] ericgj: first thing that jumped out at me was,
[04:47 PM] ericgj: this code looks like how I'd write it :)
[04:48 PM] satchmorun: :)
[04:48 PM] ericgj: not that I've attempted either problem, so some of my impression is superficial
[04:48 PM] ericgj: but generally really like how you organize the code and the documentation
[04:49 PM] satchmorun: thank you
[04:49 PM] satchmorun: i actually went through about 3 iterations of the stacker challenge before i got to a program organization that felt reasonably clean
[04:50 PM] ericgj: that one definitely I could definitely tell you put serious work into
[04:50 PM] satchmorun: the social network one is basically pretty procedural code wrapped up in a class
[04:50 PM] ericgj: on the social network one, do you feel like your graph data structure was useful?
[04:50 PM] ericgj: or would you have done it differently if you tried it again?
[04:51 PM] satchmorun: that's a good question
[04:51 PM] ericgj: it seems like that may be what makes it more procedural and harder to read
[04:51 PM] ericgj: e.g. compute_rest_of_graph
[04:52 PM] satchmorun: right
[04:52 PM] ericgj: if you wrapped some of that in a class
[04:53 PM] satchmorun: i'm trying to think about how i could do that, and i'm not sure
[04:57 PM] ericgj: yeah, I'm not too much help not having studied the problem as you have.
[04:58 PM] satchmorun: it might be that the problem is just kind of procedural in nature
[04:59 PM] satchmorun: because in order to determine the connection from 2nd-order and up, you need to already know the first-order connections
[05:00 PM] satchmorun: so (1) figure out all the first-order connections and (2) use those to iteratively calculate the remaining connections
[05:00 PM] ericgj: yes. I was thinking if you parse the first-order connections into some structure you could easily ask,
[05:00 PM] ericgj: "what's the distance from person A to person B?"
[05:00 PM] ericgj: shortest distance
[05:02 PM] ericgj: then take all combinations of pairs and process them
[05:04 PM] ericgj: I'm no cs major, but it seems like there should be some classic algorithms out there to help
[05:05 PM] satchmorun: me neither, but i do know there are a bunch of famous shortest path algorithms
[05:06 PM] ericgj: right
[05:06 PM] ericgj: the other thing that struck me about this one,
[05:06 PM] ericgj: more of a style thing,
[05:07 PM] ericgj: is that everything is done through the entry point (load_from_file)
[05:08 PM] ericgj: not that it matters here, but I often see code where as little as possible is done in the entry point, initialize or whatever
[05:09 PM] satchmorun: yeah
[05:09 PM] ericgj: the heavy computations often being done in the last possible moment
[05:09 PM] ericgj: so e.g. compute_first_order_connections.compute_rest_of_graph
[05:09 PM] ericgj: called by your dump_graph or whatever
[05:10 PM] satchmorun: the initialize method itself doesn't do very much, i just packed the logic into the load_from_file because it was, well, convenient
[05:11 PM] satchmorun: but i see what you're saying - because if this were real, you'd want to be able to incrementally add tweets
[05:11 PM] satchmorun: and wait to calculate anything until necessary
[05:12 PM] ericgj: practically I guess it's just a question of whether you expect to do anything else with the input,
[05:12 PM] ericgj: - right, or I guess that case too
[05:12 PM] ericgj: but it completely works for the problem at hand
[05:13 PM] ericgj: anyway, anything you feel could be improved on this one?
[05:15 PM] satchmorun: well, i don't really think its exemplar code in the sense of clean, maintanable, clear
[05:15 PM] satchmorun: the comments help a bit with the clarity
[05:15 PM] satchmorun: as it is, i don't know what i'd try to improve on it without rewriting it
[05:16 PM] satchmorun: and experimenting with different approaches
[05:17 PM] satchmorun: there are some small readabilty things where certain small computations could be factored out into methods
[05:17 PM] satchmorun: but ultimately, if i were going to try to improve it, i'd just start fresh, given how small a program it is
[05:18 PM] ericgj: yeah
[05:19 PM] ericgj: well I found it relatively very readable, definitely the comments helped
[05:19 PM] ericgj: shall we move to the stacker problem?
[05:20 PM] satchmorun: sure
[05:20 PM] satchmorun: that's the way more interesting one anyway :)
[05:21 PM] ericgj: could you explain what you mean by 'the main control structures could actually be written in "Stacker" as opposed to in Ruby'
[05:21 PM] satchmorun: yeah
[05:22 PM] satchmorun: so it turns out that real Forths are usually implemented in assembler, with a set of low-level primitive, from which control structures can actually be defined in Forth itself
[05:23 PM] satchmorun: this article explains it better than i can: http://www.yosefk.com/blog/my-history-with-forth-stack-machines.html
[05:23 PM] ericgj: so what would be the primitives here?
[05:24 PM] satchmorun: it would be something like:
[05:24 PM] satchmorun: a 'compile' primitive that switches the system into compilation mode
[05:24 PM] satchmorun: a 'branch' primitive for marking the start of conditional branches
[05:25 PM] satchmorun: a 'jump' for jumping to various points in the stack
[05:25 PM] satchmorun: there would also need to be another stack for storing compiled-words-in-progress
[05:27 PM] ericgj: interesting
[05:28 PM] satchmorun: i had a lot of fun learning about Forth while doing this challenge
[05:28 PM] satchmorun: it's one of those mind-bending languages
[05:30 PM] ericgj: so in terms of your code, does this mean your Builtins would be expanded to define PROCEDURE, etc.?
[05:31 PM] satchmorun: PROCEDURE would be the one control-flow word that would need to be implemented in the machine
[05:31 PM] satchmorun: and then everything else could be defined with it
[05:31 PM] satchmorun: PROCEDURE IF ... /PROCEDURE
[05:31 PM] satchmorun: etc.
[05:32 PM] satchmorun: if you go to the link i mentioned and search for 'conditional primitives', you'll see one example of how it can be done
[05:33 PM] satchmorun: of course that's code from a C implementation, so this would be somewhat different
[05:33 PM] satchmorun: because you wouldn't need certain kinds of pointers when you can just use Ruby arrays
[05:37 PM] ericgj: interesting, so in terms of your code can you say how you would change it to say redefine ADD in terms of stack operation primitives?
[05:37 PM] ericgj: (am I understanding right?)
[05:38 PM] satchmorun: it's kind of like that
[05:39 PM] satchmorun: but you wouldn't do that for ADD, as things like math would be available as primitives, much like they are here
[05:39 PM] ericgj: ah, right
[05:40 PM] satchmorun: but for, say, TIMES
[05:40 PM] ericgj: TIMES, right just about to say
[05:40 PM] satchmorun: you'd pop the top of the stack
[05:40 PM] satchmorun: push it on the return stack
[05:41 PM] satchmorun: set a pointer
[05:41 PM] satchmorun: keep reading and executing words
[05:41 PM] satchmorun: and then when you hit /TIMES, which would be a separate word
[05:41 PM] satchmorun: you'd push 1 SUBTRACT onto the return stack (decrement the count)
[05:42 PM] satchmorun: and jump to the previous marker
[05:42 PM] satchmorun: if it the result of the decrement is 0, do nothing and keep going
[05:42 PM] satchmorun: (or something like that)
[05:43 PM] satchmorun: but it makes the internals a bit more complex than it is now
[05:43 PM] ericgj: gotcha, I understand now
[05:43 PM] ericgj: but an interesting exercise for sure
[05:43 PM] satchmorun: agreed
[05:44 PM] ericgj: regarding your current implementation,
[05:44 PM] ericgj: I liked it a lot,
[05:44 PM] satchmorun: thank you
[05:45 PM] ericgj: but one thing that struck me was your mixins were pretty coupled to your interpreter
[05:45 PM] satchmorun: yeah
[05:45 PM] ericgj: what I've been doing (I don't know if others do this),
[05:46 PM] ericgj: when I need coupled classes like this, I often define them within the class
[05:46 PM] satchmorun: interesting
[05:46 PM] satchmorun: except for the statemachine, the control flow modules were mainly just a convenient namespace
[05:46 PM] ericgj: namespaced within the class
[05:47 PM] ericgj: even if they are separate files - but usually don't separate the files unless they are huge modules
[05:48 PM] ericgj: that way everything it in front of you and you don't have to remember where this instance variable was defined
[05:48 PM] ericgj: et.c
[05:48 PM] satchmorun: right
[05:48 PM] satchmorun: that makes a lot of sense here, because those modules are kind of acting like little classes
[05:49 PM] satchmorun: and all the @times_stack kind of instance variables are a bit of a smell
[05:49 PM] satchmorun: i could just have a @current_compiler instance variable
[05:50 PM] satchmorun: and set it to Times.new, Procedure.new, etc.
[05:50 PM] satchmorun: instead of enter_procedure
[05:51 PM] satchmorun: the one issue would be that those modules need to manipulate the @state instance variable
[05:51 PM] satchmorun: for things to work as they do now
[05:52 PM] ericgj: Times.new(self).compile ?
[05:53 PM] satchmorun: that would work, but something feels weird about passing the outer class instance into the inner class
[05:53 PM] satchmorun: but maybe that feeling is just silly
[05:53 PM] satchmorun: though i think what this is really pointing to is that this stuff doesn't really belong in the Interpreter class
[05:54 PM] satchmorun: and should be either part of the Dictionary
[05:54 PM] satchmorun: or subclasses of a Compiler class
[05:54 PM] satchmorun: i started futzing with the last option
[05:55 PM] satchmorun: at one point, but i got frustrated by having to pass a ton of state between classes
[05:56 PM] satchmorun: i may have just not hit on the right design though
[05:56 PM] ericgj: right, I see what you mean
[05:57 PM] ericgj: but if you go to the more Forth-y implementation, I guess you wouldn't have different compilers
[05:57 PM] satchmorun: right
[05:58 PM] satchmorun: that's a project i definitely plan to play with at some point
[05:58 PM] satchmorun: mainly because i think Forth is really interesting
[05:59 PM] ericgj: yeah, now you have me interested
[05:59 PM] ericgj: I may try this problem after all
[05:59 PM] ericgj: :)
[05:59 PM] satchmorun: :)
[06:00 PM] ericgj: while we have a few minutes left, do you have any questions about the core course?
[06:00 PM] satchmorun: i do
[06:00 PM] satchmorun: i actually had more than i do now, but i read the last post on the rbp blog, which cleared some things up
[06:01 PM] ericgj: that's good
[06:01 PM] satchmorun: my primary question is: what kind of time commitment is expected for those 3 weeks
[06:01 PM] ericgj: we could do a lot better...
[06:01 PM] satchmorun: and related: what are the exact dates again?
[06:02 PM] ericgj: time commitment: generally 10 - 20 hrs a week is what people are finding.
[06:03 PM] satchmorun: (i remember it starting on the 16th, but just wanted to confirm)
[06:04 PM] ericgj: hold on, looking it up...
[06:04 PM] satchmorun: 10-20 is doable - 20 would be a bit uncomfortable, but i expect the discomfort would be worth it
[06:06 PM] satchmorun: and another scheduling-style question: are there times where everyone is in the same digital place at the same time, or is it mostly asynchronous?
[06:06 PM] ericgj: it's mostly if not all asynchronous
[06:07 PM] ericgj: sorry, to clarify: the instructors do set office hours
[06:07 PM] ericgj: when they can be reached for sure on IRC
[06:08 PM] ericgj: but mostly it's done through the university-web assignment and review system
[06:08 PM] satchmorun: got it
[06:08 PM] ericgj: and email to some extent
[06:09 PM] satchmorun: sounds good
[06:10 PM] ericgj: there is always collaborative aspects to the assignments
[06:11 PM] ericgj: so you'll be reading your fellow students' code and vice-versa
[06:11 PM] satchmorun: makes sense
[06:12 PM] ericgj: it's a great experience, and getting better every time the course is given from what I can tell.
[06:12 PM] satchmorun: i'm definitely looking forward to it
[06:12 PM] ericgj: if you can fit in the time...that's always the tricky part!
[06:12 PM] satchmorun: there's a lot about the overall approach that i really like
[06:12 PM] satchmorun: that will definitely be the tricky part
[06:13 PM] ericgj: anyway, do you have any idea what your personal project for the course will be?
[06:13 PM] satchmorun: but, within reason, time can always be made
[06:14 PM] satchmorun: one idea that i've been toying with the last few days (because i could use it at the moment)
[06:14 PM] ericgj: always a good reason...
[06:15 PM] satchmorun: is a good way to use Mustache templates in rails
[06:15 PM] satchmorun: there are a couple of solutions out there
[06:16 PM] satchmorun: but they don't work the way i'd like and don't quite flex the right ways for me
[06:16 PM] satchmorun: but i'm not sure if something like that would be in scope for what this course is looking for
[06:16 PM] satchmorun: or is it? that's actually a useful question to ask
[06:16 PM] ericgj: I think it would, sounds really useful
[06:17 PM] satchmorun: so what kinds of things end up being personal projects?
[06:17 PM] ericgj: lots of folks have done rails related projects
[06:18 PM] ericgj: but many aren't.
[06:18 PM] satchmorun: ah, and i see there's actually a student projects page on the rmu site
[06:19 PM] ericgj: you can see a list http://university.rubymendicant.com/resources/student_projects.html
[06:19 PM] satchmorun: yeah, that's just what's on my mind right now
[06:19 PM] ericgj: oh, btw the course starts on Jan 9
[06:19 PM] ericgj: runs to the 30th
[06:19 PM] satchmorun: did that change? or was that always the way it was?
[06:20 PM] ericgj: I think it usually does start the second week of the month
[06:20 PM] satchmorun: it's not a problem, but i have the number 12 and 16 in my mind
[06:20 PM] satchmorun: and 16 made more sense as it's a monday
[06:20 PM] ericgj: yeah, I confirmed with Jordan, who would definitely know
[06:21 PM] satchmorun: thanks, i appreciate it
[06:21 PM] ericgj: practical projects that would make others lives easier, no matter the technology, are greatly encouraged
[06:22 PM] ericgj: so the Mustache thing sounds perfect
[06:22 PM] satchmorun: excellent
[06:22 PM] satchmorun: i do plan to spend a little time brainstorming to see what else i can come up with
[06:22 PM] ericgj: but Greg will give you feedback about it when the course starts
[06:23 PM] satchmorun: sounds good
[06:23 PM] ericgj: anyway, gotta run, great talking with you
[06:23 PM] satchmorun: you too
[06:23 PM] ericgj: nice code
[06:23 PM] satchmorun: it was interesting to chat
[06:23 PM] satchmorun: :) thanks
[06:23 PM] ericgj: I feel like I learned a lot ! :)
[06:23 PM] satchmorun: :)
[06:24 PM] ericgj: good luck with the course and hope to work with you when you "graduate" !
[06:24 PM] satchmorun: take care, i'm sure i'll be seeing you around
[06:24 PM] ericgj: yep
[06:24 PM] satchmorun: thanks again for taking the time