« first day (3391 days earlier)      last day (1557 days later) » 
00:00 - 19:0019:00 - 00:00

7:00 PM
Oh yeah, definitely. I'll add some useless comments too (probably)
 
How about something very simple, a program that tells you how many days passed, when someone enters hours passed.
That might be a great avenue to showcase how much names can help/hurt readibility
 
Anything with recursion seems to cook newbies' brains despite having no complicated syntax. I don't know if that demonstrates the value of readability though.
def factorial(x):
    if x == 0:
        return 1
    else:
        return x * factorial(x-1)
 
recursion falls into the "excuse" category
 
i'll openly admit recursion cooks my brain more often than not :P
 
Every individual component of this code is something that you would learn in the first thirty minutes of a "learn Python in 24 hours" course, and yet we see a dozen questions a day about how it works
 
7:02 PM
@Aran-Fey I prefer to just show the same function, once with mathy names (a, b, c, I, j, k) and once with speaking names
 
^ this
Essentially what i was thinking
 
there's no use in covering every single aspect of readable code just to get the basic point across
 
def my_function(x):
    return x / 24
^ hours to days converter seems a bit too simple
 
oh. i was thinking you wouldn't just return it directly. store the division, and the remaining hours in stuff like : days
and hours
 
leap seconds?
 
7:04 PM
last time I used something like copy(source, destination, size)
versus cp(s, d, b)
 
Oh that sounds pretty good, source and destination can be easy to mix up
 
Hmm, but you include the function body then it's probably pretty easy to figure out
def cp(s, d, b):
    with open(s) as f:
        with open(d) as g:
            g.write(f.read(b))
 
I think the goal isn't to present something that gives them a headache :P Just, ask them a prompting question: which version would you prefer. Or what is d here, then compare with the version with better name
 
the difference is "easy to figure out" versus "readily apparent without effort"
 
Ideally I want something that people can stare at and think about for a few minutes. That'd really get the point across, y'know?
@ParitoshSingh No, I actually want to give them a bit of a headache :P
 
7:08 PM
something more involved then eh
 
@Kevin nice of you to anonymize it
 
don't make them stare for too long though. You'll lose their attention quickly.
 
@Aran-Fey something with elseless ifs where flags get overwritten incrementally?
 
Yeah, that might happen. Still, I don't think it'll have much of an effect if I go too easy on them. No newbie has ever picked up good practices just because someone told them to. I need something that can convince them
 
"Maybe that user is merely expressing their worry that Stephen will be devoured by toves in the near future", you say. Perhaps. But this still tells me that Stephen remains involved in tove breeding for the next sixty episodes, which rather takes the fun out of the arc I'm currently listening to, where Stephen ponders what his future career track should be.
 
7:11 PM
Besides, they can just stop trying to figure it out whenever they want
@AndrasDeak Hmm. That might work, but I'm having trouble coming up with an actual example
 
function to assign a grade to students for their marks in 5 subjects. Can throw a wrench by also giving grades in best of 4. That might be simple enough but still engaging
 
@Aran-Fey I'll see if fizzbuzz can be spaghettiified like that
(but coffee time right now)
 
Or go for the shopping cart and cashier style of program. Have a list of items they can buy, they give quantities. Calculate total amount, and also change due
 
@ParitoshSingh Sorry, not sure I understand. You're saying there would be 5 inputs (grades for 5 subjects) and the output would be like... an average?
 
Would be a grade based on average. So if the average is over 80, it's A. and so on
that gives you some if elifs to work with
 
7:19 PM
Ok, I see. 5 sequential if statements probably won't be too difficult to figure out, but I'll write it up and see how it looks
The shopping cart idea is interesting
 
use for: if: else: else: if you really want to confuse people
 
yeah, what Andras said
 
it's supposed to convince newbies, not intimidate/put off them
 
One big thing also is, that sometimes things don't click for everyone, even though it seems like the lesson makes it blatantly obvious. New folks often just need time to let the information "sit and settle down" so to speak. So in that sense, I'd also say that don't be too fussed about making it absolutely perfect, repetition of a concept seems to help more than anything honestly
Or well, imo
Just what i've seemed to observe so far.
 
7:24 PM
Grading programs aren't universal across cultures, since an average of 80 is not considered an A everywhere in the world. So take care with that one if it's an online class.
 
(correct, we don't even have grades here :P)
 
ps = {
    'foo': 5,
    'bar': 7
}

def my_func(itms, m):
    c = 0

    for i, q in itms.items():
        c += ps[i] * q

    return m - c
That's pretty good
 
@AndrasDeak I'd be careful about anything that takes more than a few moments to figure out, then. It can be really hard to judge what's too much.
Me: "this is how we define a function" -- Audience: "Huh?"
 
Although, most of the difficulty there is because of the useless variable names. I might need something with more complex control flow
 
@MisterMiyagi I specifically think for-else is obscure, a lot of python people seem surprised/thrown when facing that
 
7:28 PM
Pessimistic take: the value of readable code is proportional to the project's size and life expectancy. If you return to a project after neglecting it for six months and can't understand anything you wrote, the virtue of readability is obvious. It's very hard to replicate that insight with a code snippet that can be digested in thirty seconds.
 
@Aran-Fey isn't that the point, though? the more you get them hung up on other complexity, the less impact they feel from readability.
 
I would be hesitant to make it more involved. The "shock value" of contrasting a badly named program with an identical one with good names is pretty powerful.
Getting them caught in parsing the code itself for too long might end up taking away from that impact somewhat
 
You both have a point
I was thinking I wanted a snippet that needed multiple improvements, not just one (improving the variable names). But on 2nd thought, this isn't too bad - I underestimated the difficulty because I know what the code does
Which, ironically, is one of the things I was planning to address
 
ha. "bad" might be a bit exaggerated, but it's certainly not great
 
7:39 PM
well, yeah, bad considering the amount of code and placement
 
@AndrasDeak Don't disagree on for-else being obscure. But in a lecture, even a few ifs can be too much. Never had much luck with "intermediate" if coding itself wasn't the focus -- either give them really easy tasks, or crush them on purpose.
 
7:54 PM
What do you achieve by crushing them?
 
"hello darkness my old friend"
 
I can think of at least one institute that psychologically crushes their recruits before shaping them in their own image, so it must be somewhat effective or else they wouldn't do it
 
hi, im trying to set up logging, but it is only doing the correct format on the first log, the rest are missing the expected formatting
 
@Aran-Fey You avoid them wasting time on trying to solve a task that isn't relevant. If people feel they could solve some bonus objective with just a little extra work, they will. At the cost of following what you actually want to tell/teach them.
 
# set up logging
logging.getLogger('requests').setLevel(logging.WARNING)
logging.getLogger('urllib3').setLevel(logging.WARNING)
logger = logging.getLogger('Imports')
logger.setLevel(logging.INFO)
file_handler = logging.FileHandler('logfile.log')
formatter    = logging.Formatter('%(asctime)s : %(name)s : %(message)s')
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
 
7:59 PM
Wait, hold up. If you give them an objective, then they should be able to solve it. If they can't, it's not much of an objective
 
Back in college my AI professor was trying to impart the value of search algorithms by handing out a sudoku-esque puzzle and saying "this is too difficult and tedious for a human to solve", and meanwhile I was solving it with enthusiasm
 
They always underestimate your prowess in solving difficult and tedious problems
 
@Aran-Fey Consider your readability example. Is the objective to understand the function, or to realise it's hard to understand? They don't have to solve the programming problem.
 
@Kevin Hahaha. Did you solve the whole thing?
 
My cry of "I got it!" was met with many awkward looks. I still don't know whether they were supposed to convey "are you some kind of robot?" or "yeah, the puzzle isn't that hard and any of us could have done it, but you were the only one that missed the social cue that you weren't supposed to do it, and have lost face by challenging the professor's thesis"
@Aran-Fey Yeah.
 
8:02 PM
@MisterMiyagi So basically it's a way of showing them that they still have a lot to learn
In my case though, I'm going more for a "you can turn this hot mess into this squeaky clean code in 3 easy steps" kinda thing
 
@ThelurkerLurker It looks like you're only adding the file_handler to the "Imports" logger, and not the "requests" logger or "urllib3" logger. Is that intentional?
 
@Aran-Fey The point is to show them they really aren't meant to solve this right now.
 
Ah, I see
 
@Kevin yes i dont want to log any of the urllib3 or requests at all
 
Hmm, in that case I'm out of ideas. If you provide a MCVE I will continue to investigate with enthusiasm
 
8:11 PM
i think im just gonna hardcode my formatting
 
wim
8:21 PM
use a fileconfig or dictconfig
it's easier/better than setting these up manually in Python
 
cbg
 
Thinking about revisiting my project that uses libvlc... I might have to look at VLC's actual source code to figure out how I'm supposed to use the interface
 
@Kevin or just "why are you broadcasting your existence mid-lecture?"?
 
Certainly the thing I want (play a youtube video in a VLC window) is possible, since VLC itself does it, but all my attempts have ended with "your video, which is 0 minutes and 0 seconds long, has downloaded successfully and is ready to play"
Currently downloading 300 MB source repository...
 
*hands Kevin a haystack deneedlifier*
 
8:36 PM
If grep -rsni youtube * doesn't turn up something useful in the first ten hits, I'll probably give up
 
git grep can help too
Spares you a path
 
Fewer hits than I expected. Most of them look like i18n files. I poked through share/lua/playlist/youtube.lua before, but I didn't see any obvious "here's how to play streaming video over HTTP" snippets
 
8:56 PM
does VLC use its own interface?
 
I suspect a good chunk of the src directory is responsible for the UI, if that's what you mean.
 
I just wasn't sure if libvlc is meant as an external thing to interface with (even if undocumented), which could mean that vlc source wouldn't help you necessarily
but you're probably saying yes, it's what VLC itself uses
 
wiki.videolan.org/LibVLC indicates that VLC itself uses LibVLC, and applications that want to embed vlc-like functionality "should" use LibVLC
 
thanks
 
The interface is documented insofar as I can find a docs page for every class and struct and function. It doesn't give me a very high-level understanding of how to glue these things together, though.
wiki.videolan.org/PythonBinding talks about python-vlc, which has an example file vlc.py that plays local mp4 files (after a little bit of smashing square pegs into round holes on my part to account for 2.7isms and environment incompatibilities).
So I can play local mp4s, but I can't stream them from the Internet. It's entirely possible that the changes required to allow this are quite simple. But I have no idea what they might be, so.
Buried ten layers deep in the docs is a single page that says "make sure to set this parameter to True if you need to get data from across a network"
I'd be more comfortable fiddling around with mp4 configuration options if I was even sure that youtube videos arrive on one's machine as mp4s. Youtube themselves don't seem to be very forthcoming about their video format and Google isn't giving me many hits for third party reverse-engineering
Hmm, conflict of interest much, Google?
Dare I... Use Bing for this?
 
9:13 PM
I just found a thread talking about youtube videos not working with libvlc, only for denvercoder to find that the problem is with flv files, whether streamed or local
I suspect you've found all the denvercoders such as forum.videolan.org/viewtopic.php?t=90061 ?
 
I've perused through a couple, but they're even less useful than usual because some of them are talking about the Old Python bindings but I can't tell which
 
I've seen the second reference now to the youtube URL not being The True Address, and there's some parsing to be done. See e.g. stackoverflow.com/a/19522687/5067311 and an android-related post I've already closed that said "lua which is used to parse the URL is not available on android; watching streams is fine though"
 
Anything from 2010ish or previous must be viewed with suspicion
"lua which is used to parse the URL" almost certainly refers to share/lua/playlist/youtube.lua, which contains much url unmangling code. It is certainly available to me, so that's nice.
 
the newest answer on my previous link is from 2015 and has a link to a VLC dev stackoverflow.com/a/29430900/5067311
 
Perhaps a good experiment would be to locate a plain old mp4 file somewhere online, and see if I can play that. Then I would know whether the problem is 1) I can't play mp4s from online; or 2) I can't play mp4s from youtube specifically, perhaps because The True Address was divined improperly
 
9:23 PM
imgur has plenty
 
A little off-color test data is within the Hacker Ethos. Image rendering programs used en.wikipedia.org/wiki/Lenna (SFW), a Playboy centerfold, as a test image for years.
Anyway. I've got a plan, now to execute it.
 
wim
 
where is the /shakeshead icon?
 
wim
I can not hammer it because I had already closed it previously. It was re-opened and self-answered by OP (eyeroll)
 
@wim done
 
9:40 PM
@wim just to be clear the reopening was not (just) OP and the opener badger did not answer
no idea why it was reopened though
 
OP accepting his own answer instead of yatu who was earlier and basically have the same answer.... makes me sad
 
well OP posted "thank you commenters and dupe target" in a comment
 
-insert it's something meme-
 
wim
OP is visiting from , maybe things work differently over there.
<insert optimizing for perls joke>
 
10:28 PM
no MCVE, maybe no repro, old but edited for no reason stackoverflow.com/questions/52695214/…
You've discovered a non-utf-8 character. There are different options to deal with this ... I've used this link: stackoverflow.com/questions/3224268/python-unicode-encode-er‌​rorKyle Hurst 1 min ago
 
11:25 PM
Hi all. I'm working on an interesting bit of code related to the Twister pseudo-random number generator and would like some off-the-cuff ideas for alternatives to the defunct random.jumpahead(n) command. I'm not sure this is worthy of a new thread on S.O. so I thought I'd see if anyone here would like to brainstorm.
 
Yeah, that sounds too broad for SO main.
 
Yeah. Also because my question is specific to my application, SO didn't seem like the right place to ask it.
 
I know at least one regular who is enthusiastic about generating random numbers, so you're in the right place.
 
Sweet. Ok, in a nut-shell here it is..
 
(Whether or not he'll see your problem and when is another matter, but you'll only know if you ask. Anyone can end up responding.)
 
11:30 PM
I've written a bit of script that does a search through random seeds and generates randomint() numbers. Specifically, I'm seeking a seed that will generate the ascii codes spelling out 'helloworld'. It occurred to me that I could double-dip on the seeds by using the random.jumpahead() command, and repeating the search. Sadly, that command is no longer available. Any ideas on standard random methods that I could use for this purpose?
*randint(), not 'randomint()'. lol
A search of the first 100 million seeds revealed one that produces 'hellow'. I don't know the maximum allowable seed and haven't been able to find that information either. Seeds that produce words of 5-characters in length seem fairly easy to find. (I found a seed that will produce my own last name.) Beyond than that, the search gets exponentially harder, but it is still fun.
Anyway, that's my issue. Thanks to anyone who wants to comment. I'll check back from time to time. Cheers! -CW
 
00:00 - 19:0019:00 - 00:00

« first day (3391 days earlier)      last day (1557 days later) »