« first day (3529 days earlier)      last day (1402 days later) » 
00:00 - 13:0013:00 - 23:00

12:03 AM
cbg
for some reason when i try to run this test the rollMany function is not defined
from Game import Game
import  unittest

class BowlingTest(unittest.TestCase):

    def setUp(self):
        self.g = Game()

    def rollMany(self,n,pins):
        for i in range(n):
            self.g.roll(pins)

    def test_gutterGame(self):
        rollMany(self,20,0)
        self.assertEquals(0,self.g.score())
i also tried defining it inside of the setUp function in case the unittest only inits functions with test in its name, or whats in setUp
no luck, and i also even tried appending test_ in front of all occurrences of rollMany and got the same error
 
12:16 AM
just a simple unittest otherwise, main loop here:
if __name__ == '__main__':
    unittest.main()
 
user6568562
12:31 AM
cbg
 
2:33 AM
@Skyler rollMany(self, 20, 0) should be self.rollMany(20, 0)
 
i knew I was doing something really stupid
all this self stuff really gets annoying at some point, but i suppose its good to be explicit about the scope
 
Annoying perhaps, but that's how self in Python works. So different from other OO languages? Perhaps the explicit self argument in the method signature seems like cruft, but self.method() to invoke method on self is how that would be done in Java and C++ as well.
 
3:06 AM
@PaulMcG If I understood the reasoning correctly, the explicitness allows for something other than self to be passed? First thought is passing cls, but in theory you could pass another object entirely if you wanted to perform some trickery/magic?
Oooh I now have WSL2. Shiny. Of course now I can't remember what I wanted WSL1 to do that it didn't, and thus, the reason why I'm excited about having WSL2..
 
4:08 AM
Well, it's certainly possible to reference the method as class.method(obj). For instance, you could take care of those pesky newlines when iterating over a file using with open('a.txt ' as f: for line in map(str.rstrip, f):
 
@AnttiHaapala What is this I don't even
 
 
2 hours later…
6:35 AM
@toonarmycaptain It also vastly simplifies the implementation, since methods are just functions. The Python compiler has very little work to support classes – mainly name mangling and expanding argumentless super(). The largest bulk of functionality is provided by actual objects, such as type and function – one could in principle implement these in Python directly, and they would work.
 
@PM2Ring That's just awful. Both the initialism and the principle.
 
That's PERL
 
Wow, the more I read about it, the more awful that language becomes.
And Larry Wall seems like a crazy person.
 
Larry Wall has some very interesting notes and research into programming language linguistics. Very insightful, but kinda misses that PLs generally should not be prose but technical.
We have PERL used for some mission-critical middleware, designed for a factor 10 to 100 less of where we are today. It really is awful in production.
 
7:50 AM
@CodyGray :) TIMTOWTDI makes Perl very flexible, but it also contributes to making Perl code harder to read. In contrast, Python's attitude of "There should be one — and preferably only one — obvious way to do it." makes Python code easier to read, once youre familiar with the language.
The "one obvious way to do it" approach means that you get recognizable idioms for many common programming tasks. So when you see code doing unusual stuff, it means that it's either doing something very special, or that the coder is doing something sub-optimal, or downright wrong.
Unfortunately, there are a few features in Python that break the "one obvious way to do it" principle, mostly for historical reasons. The main one being that we have several different ways to do string formatting.
 
Can someone have a look at this question? It's been voted as opinion based, but I don't see that as applicable ("needs details" I would understand). Haven't found a dupe and it's something that wasn't obvious to me, so might be worth salvaging.
 
@PM2Ring Yeah, my experience is more in C++, where there are many ways of doing things, but generally only one right way. :-)
@MisterMiyagi I agree that the question is fine, and I've re-opened it. But perhaps this and/or this are duplicates?
 
8:06 AM
@MisterMiyagi I voted to reopen. The people who voted to close it as opinion-based need to read & understand your answer. ;)
@CodyGray I learned C in 1980. I never got around to learning C++. I figured I'd wait for the language to stabilize, but then it kinda grew out of control. ;)
 
It's been quite stable for a long time now.
New features do get added, but backwards-compatibility is maintained, and you can write perfectly clear, understandable code without knowing all the new features. And you can start integrating them gradually, as you find a need for them. That's what I do. I don't claim to know everything that the language offers.
 
@CodyGray Thanks. I've pondered these dupes targets as well, but they don't really apply. import can be subtle. Talk about having one obvious way to do it... ^^
 
I don't imagine there are very many people who know or use everything Python offers, either.
@MisterMiyagi Cool. I obviously can't make the call whether it's a dupe, so I appreciate the input of a topic expert.
 
@CodyGray Sure, but it's very big. I've heard that it's difficult for someone to master all facets of C++. And I'm getting a bit too old to learn a new language. :)
 
@CodyGray I honestly doubt that anyone uses all of it. It took me years to find use-cases for some things (cough metaclass cough) even when explicitly searching for an excuse to use them.
 
8:14 AM
Yup. Those rare times when you find a practical use-case for some obscure feature just warms the cockles of my heart, though.
 
@CodyGray What Mr Miyagi said. They're similar, but they don't cover the as keyword.
 
Which reminds me, I wanted to offer some folks to write a metaclass for them... ^^
 
What about this and/or this? These do talk about "as".
 
nice find! the first one matches
 
I can merge them.
 
8:20 AM
That would be splendid.
 
@CodyGray Sure. You can be an expert Python coder without learning what features even exist in all of the standard Python libraries, what to speak of the numerous 3rd party libraries. However, the core language itself, minus the libraries, is fairly small. It does have a few obscure nooks & crannies, but they mostly concern fairly advanced stuff that you generally don't need in day-to-day coding.
 
Oh, yeah, libraries. I forget you guys have libraries for everything.
 
Metaclasses being one of those obscure nooks & crannies. :)
 
I don't really consider that part of the language, though.
 
Well, there are a few standard libraries that are pretty important. But most of the others, you can safely ignore, until you need them.
 
I suppose it's a bit like in C, where stdio.h & stdlib.h aren't strictly part of the core language, but you generally need to know them to write useful C code. (Ok, you might not even have stdio in an embedded environment).
 
Indeed, I have worked in such an embedded environment. Although, really, it's more common to lack stdlib's memory allocation functions than stdio's output functions. Most embedded systems have some kind of console for debugging.
 
@CodyGray That comic made me finally get over my objection to the whitespace thing and learn Python.
 
Your decision-making processes may be different than mine...
 
:D
 
8:29 AM
@CodyGray It's a bit of a grey area with Python. The language itself does not include many features associated with it. Writing code without the implicit builtins library is outright impossible, and some specific tasks just aren't practical without library support.
 
@MisterMiyagi That's a lot like C++. There are very few core language features, aside from the syntax. Everything is provided by the standard library.
And C, of course. Except the standard library there is minimalistic.
I originally didn't like that design as much as a monolithic language with all of that baked-in, but I've grown to see the merits of it.
 
I have fond memories of my time with C++ (not so much with C, but for different reasons). I'm just hopelessly out of date.
@CodyGray Python2 print statements! Waaargh! readies the pitchfork
 
Oh no. What changed about the poor print statement?
 
It's a function now. Courtesy of the builtins library. ^^
 
I see. As it should have been from the beginning.
VBScript called; they want their pseudo-function calls that don't use parentheses back.
 
8:34 AM
A part of me misses the ``print >> sys.stderr, 'foo' syntax. Those were the days...
 
@MisterMiyagi I'll fetch the red-hot poker. We can burn it out.
 
That looks awful.
 
@AndrasDeak I hope you don't have any plans for today, there are more of these stored in my head...
 
When he said "those were the days" he meant "those were the terrible days, good riddance"
 
Good old <> operator... sigh
 
8:38 AM
You haven't made it as a language until you have a spaceship operator.
 
I used the old "chevron" file arg to print, too. Mostly for stderr. When I first started with Python, having a print statement instead of a function seemed regressive, like going back to Basic. I even wrapped it a function for a while, but I decided that was just being silly (& inefficient).
 
You know, I'm just now very vividly remembering why I had practically zero qualms about Python3 ditching such crap for good.
 
@MisterMiyagi Aside from the enduring conviction that backwards compatibility is sacred?
 
@MisterMiyagi We'll need some holy water, a senior software dev and a junior software dev
 
@CodyGray The print statement vs function stuff is pretty trivial, and can generally be fixed by the 2to3 conversion program. The biggest backwards compatibility issue is the difference between Python 2 & Python 3 handling of strings and bytes. The Python 2 way had... problems.
 
8:43 AM
@CodyGray it's fine, people will rip off that band-aid and bump up to the new version
 
@CodyGray I can live without long-term backwards compatibility surprisingly well. Most of the things I have to fix at my dayjob are outdated crap that people never bothered to get up to date. Forcing people to maintain code has some appeal.
 
Oh yeah, almost every language that tries to implement it gets strings and bytes wrong. Java is a complete disaster.
 
Of course, it's an awful mess for the code that is mission critical and abandoned... But that's mostly an awful mess anyways.
 
@MisterMiyagi rewrite it in Rust
 
Apr 4 at 13:15, by PM 2Ring
And of course there's a ton of Py 2 code out there in the wild that doesn't handle Unicode properly, it just appears to if it only ever encounters Latin1 encoded stuff. But throw an emoji at it and it will do Bad Things.
 
8:45 AM
@AndrasDeak Bring pizza. 🍕
 
Good thing the whole world is ASCII, right?
 
@AndrasDeak Don't tempt me! I'm still looking for an excuse to use Rust. Mostly, our deployment system is too much of a pain for that, though.
Plus, there's the thing that performance is completely irrelevant for us...
 
@MisterMiyagi That cannot possibly be true.
Performance is always a feature.
 
@MisterMiyagi it's not like you cater to the LHC or something
 
It might be the case that the language is not your perf bottleneck, but perf always matters. Even if only to your users.
 
8:48 AM
Users are the worst
 
@AndrasDeak That's it, basically. The performance of that one Python script taking 10 seconds to deploy some 10k to 100k C++ data crunchers for days is completely irrelevant.
 
Gotcha
 
We're much more mindful about network traffic, and there it's basically having good support to squeeze things in and out of bytes. Python does that.
 
@CodyGray :) In Python 3, it's pretty straightforward: you encode Unicode strings to bytes, and decode bytes to Unicode strings. In Python 2, coders tend to try random combinations of encoding & decoding until they stumble on something that appears to work. Unless they know what they're doing. ;)
 
Do you properly handle the distinction between code points and code units?
Contrary to popular belief, strings are not simply arrays of bytes.
 
8:56 AM
The encoding is an implementation detail. The interpreter is free to switch its internal representation as optimal, which in turn means it cannot expose anything about the underlying bytes, either.
 
:-) I recognize the author's name.
 
In Python 3, strings are immutable sequences of Unicode characters, and we're isolated from the underlying representation. We have an immutable bytes type & a mutable bytearray type for sequences of actual raw bytes.
 
Ah, immutable strings. Excellent.
I become more in favor of immutable types all the time (with a few exceptions for strictly performance reasons).
 
yeah. Python is pretty bad at that, though. :/
 
Performance? Yeah...
 
8:59 AM
Everything that isn't one of the few builtin immutable types is practically Play-doh.
 
The real anti-pattern is attempting to index into strings.
 
@CodyGray Good thing we have C and C++ for that. ^^
 
@MisterMiyagi PREACH!
 
On immutability:
Apr 27 '18 at 7:35, by PM 2Ring
Hi @abarnert! It's great to see that you're active on SO again. FWIW, one of my favourite lines on SO comes from one of your answers: "It doesn't make sense for a = 2 to turn the number 1 into the number 2 (that would give any Python programmer way too much power to change the fundamental workings of the universe); what it does instead is just make a forget the 1 object and point at the 2 object instead".
 
That is another anti-pattern, though: everything is a reference/pointer. :-(
 
9:03 AM
Well, admittedly, it does impact performance. OTOH, it does mean that Python's OOP is very pure. We don't have primitives & objects, we only have objects.
 
@CodyGray That wouldn't be quite as bad if we had immutable types...
 
Still bad. Both for performance and for security.
 
But as mentioned earlier, performance isn't really an issue. Eg, a program that needs to do a lot of number crunching uses Numpy to do the heavy lifting, and the Numpy stuff runs at compiled speed.
 
So, perhaps a ridiculous question, but one that I cannot answer. Why is there not a Python compiler that can take Python code and compile it into machine code? It could be as simple as a front-end for Clang or GCC, which would then leverage the toolchain's existing backends that generate machine code. All you'd need to do was turn Python into an intermediate code.
 
The problem is mutability.
Literally anything can be changed at runtime.
 
9:06 AM
That would give you the best of both worlds. You have a nice, modern language, and one that can be interpreted (e.g., for super simple debugging and investigation), but when you're finished, you can compile it into something efficient.
 
You can swap out function code, for example.
 
@MisterMiyagi Sure, but that's true in other languages. It's certainly true in C. That has no problem being compiled.
 
In Python, we don't optimize for running speed, we optimize for development speed. I.e., good Python code is code that's fast for humans to write and to read.
 
@PM2Ring Right, right. I get that. I'm saying why not have both?
 
@CodyGray But C has the escape hatch of undefined behaviour. Python is always well-defined, no matter how stupid the code is.
 
9:08 AM
@MisterMiyagi The compiler would take care of that.
 
Not practically.
 
C has undefined behavior to make compiler writers lives easier and to prioritize speed above all else.
But plenty of other compiled languages don't have a concept of UB.
 
You can try using Cython to compile Python semantics to C. It gets you about 2x performance and massive bloat.
 
I don't want bloat. :-(
I am a huge fan of compilers for two reasons: (1) generation of more efficient code, and (2) compile-time correctness checking (i.e., static checks for types, behavior, etc.).
 
@CodyGray But their core parts are usually static, e.g. classes and fields in Java/C#. Python just lets you rip that all apart as you feel like.
 
9:10 AM
@MisterMiyagi What exactly does that mean?
 
Classes in Python are maleable. You can add and remove methods, fields and attributes at any time. You can change the inheritance at any time. You can swap the type of an instance at runtime.
 
@CodyGray Well, with stuff like Numpy, and libs that use GPUs, you kinda do. The native Python stuff is mostly handling the top level organization of the data, and compiled code handles the grunt work.
But even with pure Python, some stuff is relatively fast, eg list methods can internally loop at C speed, which is a lot faster than an explicit Python for loop. Which leads to the situation where the performance of Python code doesn't appear to conform to traditional big O analysis.
 
@PM2Ring Wait, wait. That last assertion doesn't follow. Big-O is still correct. A list method is still running a loop internally. You have to know what your code is actually doing in order to do the analysis. You can't just count statements or look for loops in your high-level language.
@MisterMiyagi Hrm... that sounds not great.
But still not convincing for why it cannot be a compiled language. All of that information is available ahead of time to the compiler, just as it's available to the runtime, which is itself compiled ahead of time.
 
Basically, we have two groups of compilers for Python: A) Those that add some sneaky restrictions which usually do not hurt. E.g. Cython has immutable classes and functions. B) Those that JIT to separate the ugly parts from the good ones. E.g. PyPy looks if you do evil stuff. But those are really top-of-the-line JITs (a large inspiration for Graal VM) and still run slower than languages made for compiling because there are so many escape hatches needed.
 
So Cython is compiled?
 
9:17 AM
Yes.
 
@CodyGray What I mean is that say you have 3 algorithms to perform some task, X, Y, Z. If you implement them in C, X is slower than Y which is slower than Z. But in Python, the nearest equivalents may have Z slower than X for typucal
 
@PM2Ring Yeah. That's not unusual for interpreted languages. MATLAB has the same behavior with respect to vector operations, for example.
 
Cython is seriously outdated, though. Its type system does not lend itself to doing interesting things, being basically sugar around C. For example, "templating" means that you predefine what variants of a type there are. There are no generics.
 
@CodyGray What I mean is that say you have 3 algorithms to perform some task, X, Y, Z. If you implement them in C, X is slower than Y which is slower than Z. But in Python, the nearest equivalents may have Z slower than X for typical data sizes of say a few hundred items, but X is slower than Z when you deal with a million items.
 
It drives people like me crazy, people who are used to looking at the implementation details and prefer to have that control.
@MisterMiyagi I see. Yeah, that doesn't sound too good.
It also sounds like it is a bit of a fork/modification of the language itself, which is sub-par.
To do it correctly, it needs to be exactly the same code that you can run in the standard Python interpreter as you would run through the ahead-of-time static compiler.
 
9:21 AM
Yep, and I don't see how that is possible until Python itself adds a concept for immutability.
 
Maybe I made my point more clearly here: stackoverflow.com/a/47845960/4014959
The relative execution speeds of algorithms implemented in CPython may be different to what one would expect from a simple analysis of the algorithms, and from experience with other languages. That's because Python provides many powerful functions and methods implemented in C that can operate on lists and other collections at close to the speed one would get in a fully-compiled language, so those operations run much faster than equivalent algorithms implemented "manually" with Python code.

Code that takes advantage of these tools can often outperform theoretically superior algorithms that
 
@PM2Ring No, I get it.
 
There is a bit of a problem here due to Python by its nature not being used for all-out performance. That means the community lacks drive+knowledge to really tackle the problem consistently. Python compilers are usually made to solve problems of specific groups, and do not generalise well.
 
@MisterMiyagi Yeah, I guess that is really my question. In my mind, I don't see it as a technical problem/limitation, but rather a (A) limitation of vision, and (B) lack of resources.
I'm not sure if you're right about the lack of immutability posing insurmountable technical problems in terms of statically compiling Python.
But I certainly didn't know that was a language feature. And the thought of it does make me slightly uncomfortable...
 
Not sure if the problems are insurmountable. But I fell they are needless. Basically a lot of time is wasted teaching compilers tricks that they should not need in the first place.
 
9:25 AM
Like what?
You mean just how to deal with mutability in core language features?
 
Mostly, finding out when people do evil stuff.
 
That's one of the advantages of a compiler, though.
 
@CodyGray I get that, and it did make me feel like I was losing a vital connection to the CPU when I first started with Python. Mind you, I had about 5 years of experience coding in assembler before I learned that C existed.
 
Even more than performance, one of my primary missions as a programmer is to figure out how to move as many potential errors as possible from runtime to compile time. In my ideal world, if the code compiles, it should be free of all but logic errors.
 
For example, if you look at PyPy that is basically (from very high up) a "regular" compiler plus an entire "does the user code do stupid" framework. Their limiting factor is the latter, not the former.
@CodyGray We have that one surprisingly well covered. Basically static analysis tools just assume you don't do stupid. Then Python is easy to check.
 
9:30 AM
A static analysis tool that assumes you don't do stupid is worthless! You see, we are always doing stupid.
 
Stupid as in "advanced stupid". Metaclass stupid, ripping out internals stupid.
We trust consenting adults to know what they are doing here. ^^
 
I see. Stuff other languages might call "reflection".
 
@CodyGray Good point. And I do miss that in Python, although as MisterMiyagi says, there are analysis tools that kind of address that defect. Of course, Python's data model and the whole "duck-typing" thing does make static code analysis much harder.
 
But I'm talking about insane stuff to move as many errors from runtime to compile time. Static bounds checking, for example. You don't represent months as an integer, because valid months are only from 1-12. A compiler won't catch out-of-range errors if you represent a month as an integer. That means you can end up with runtime out-of-range errors. That's bad.
Some of this is perhaps colored by the fact that I work on high-availability systems. Runtime errors are evil.
 
@CodyGray Yeah. As someone using these dark arts myself, I have to say it is surprisingly workable. Basically it forces you to have the ugly stuff encapsulated and well-tested. The user just sees some Java'esque, regularly-typed stuff.
 
9:34 AM
@MisterMiyagi What is the advantage of this, over doing it the "right" way? C++ doesn't have reflection. I've never missed it. Even though I used to use it back when I did C#/VB.NET.
 
Basically, we have more power and flexibility behind the scenes. E.g. the metaclass stuff allows for some truly groundbreaking stuff. All of enums, abstract classes, protocols (structural typing), and type annotations run on metaclasses. I'm currently cooking up some metaclass-based concurrent error handling scheme.
 
@CodyGray numba does that when it can. Or when you promise not to usefancy python types numba.pydata.org
 
These things aren't reflection, they form self-contained contained.
But note that I'm very unhappy that our annotation type system does a cop-out here. I feel it's a huge wasted opportunity.
 
@MisterMiyagi Ah, right. As a C++ programmer, I handle this with static metadata, e.g., templates.
@AndrasDeak Oh, cool! Yeah, that's similar to what I was thinking of/looking for. I never found that in my admittedly brief research.
 
Well, seeing how C++ templates are turing complete, there really isn't anything you are missing out on. ^^ But compared to the entire range of languages that use Generics, non-first-class types and such, there's a huge capability difference.
 
9:39 AM
That would have been really useful about a year ago, when I had a really good algorithm developer working with me who knew Python but no other languages (since he wasn't trained as a programmer). His algorithm implementations were solid, but I had to port all of them to a real language to have any hope of efficiency. (Or running on embedded systems.)
About 4 months in, I persuaded him to learn C++. He never looked back. :-)
He decided that C++17 was basically "Pythonic".
 
@CodyGray it's a well-developed library by now. Works nicely, but you often have to fiddle with it (like changing list literals to numpy arrays to help infer types)
But you're going to use it with your bottlenecks anyway...
 
I'd rather use it with everything...
I've grow weary of mixing things.
 
@CodyGray as the others have said that would only work with Typethon
 
That's a thing?
Why are there so many Python things?
 
@CodyGray no :P
 
9:42 AM
Haha
It is actually.
 
Jun 9 at 11:39, by Andras Deak
I'd be OK with a fork called Typethon. Typhon?
 
Typhoid?
 
@CodyGray I was hoping for Julia in that regard. But they're way too far down the PERL'y side of code consistency/readability for my liking.
 
yeah, my brief run-in with julia made it seem promising for this
 
@MisterMiyagi That's because they're aiming for MATLAB friendliness.
Which is a total disaster of a language.
 
9:44 AM
Honestly, the major reason why I use Python is that I can collaborate with any imbecile and still figure out what's proper. Usually, that imbecile is me at 3 AM.
 
I couldn't get myself to learn yet another language as a hobby...
@CodyGray they are? Ugh
 
@MisterMiyagi I just don't buy that as an explanation, honestly. Even drunk me at 3 AM has no trouble writing correct C++ code. It's all what you get comfortable and familiar with.
 
some of numpy's weirdest warts come from ancient MATLAB friendliness
 
@AndrasDeak Yeah, they've inherited a lot of MATLAB stuff. Then thrown it in the blender with non-MATLAB stuff.
 
Yup. They want Julia to be a migration path for those afflicted with MATLAB, which does make a lot of sense as a design goal in the abstract, but it means a lot of ugliness creeps in.
 
9:47 AM
Might as well use MATLAB. That also jit compiles now... just don't expect much in the way of non-numeric programming
 
@CodyGray I don't mean correct. I mean "figure out what this metaclass/decorator/import hook" does.
I still highly regard C++, but the code that my students produce with C++ is utter...
 
You can almost certainly take out "with C++" from that sentence without losing any accuracy.
The code that most "programmers" produce with any language is horrific.
 
@CodyGray we already have python to escape to... :P
 
this is why I've been looking into test driven development
 
@AndrasDeak It helps with everything but performance...
 
9:48 AM
for the first time i feel like i might actually be writing some clean thats easy to follow along
 
@CodyGray Yeah. Unless your problem is numpy-heavy, which MATLAB often is
good MATLAB code I mean
Although due to jit loops aren't as evil there now
 
@Skyler TDD solves some subset of problems, but I'm not sure it really helps with readability/elegance.
@AndrasDeak Yeah, haven't kept up with modern MATLAB. Still stuck on version 2011b, which I use because I have no choice (legacy code + "programmers" who only speak MATLAB).
One of the things I've done at work is port numeric algorithms from MATLAB into C++, where I've witnessed anywhere from a 60 to 100 times performance increase. It's absurd, honestly.
 
Sometime after 2012b they added jit to every function,and the execution engine got an upgrade making it much faster, allegedly
 
turning a bowling game into 14 lines of very readable code with some other 1 line helper functions is pretty powerful imo, not useful in every context but quite elegant in some ways
 
@CodyGray just use MEX /s /s /s
 
9:52 AM
@AndrasDeak That's what some MathWorks representative told me at a conference some time back. I asked him by what factor the code was improved. It wasn't 60-100x....
@AndrasDeak I'm not smart enough to use that.
 
@CodyGray you mean you're smart enough not to use that
 
@CodyGray It's purely a personal impression, I admit. In my experience, beginners of Python do not have access to the advanced/evil stuff and thus tend to write boring, straightforward code. In other languages, macros/generics/templates is something you learn from day 2 already.
 
"Bane of my existence" vibes every single time I used it
 
Python seems to have a higher chance (not guarantee) that code is either proper or obviously junk.
 
@MisterMiyagi Anyone who is teaching macros to budding C++ programmers is doing it wrong. There is pretty much a single valid use-case for macros in C++, and that is run-time asserts so you can get all kinds of juicy metadata automatically inserted. That should be handled by a library, freeing you from ever writing any macros yourself.
 
9:54 AM
this is pretty elegant for a bowling game (I'm making a python equivalent atm so this is a screencap off a vid)
almost every other method there is a 1 liner that does exactly what it says it does
 
@CodyGray Every language has their own evil – macros are indeed not something I'd weight against C++. But take Rust for example. I really like that one, but they introduce Macros right at the start of the language documentation.
 
I can't really take Rust as an example, since I haven't learned it. I would like to, I think, but I just don't have the time. (This is unlike Go, which I have already decided I'm not especially interested in learning.)
 
@CodyGray That feeling I can share wholeheartedly. ^^
 
@Skyler I see a lot of repeated code there.
 
And I see a lot of camelcase
 
9:57 AM
Java do as java does
 
No excuses!
 
but any refactoring of the "repeated" segments from there would probably almost negatively impact readability
 
Oh, and a bunch of semicolons... :P
 
Oh, I like camelCase.
Underscores are too hard to type.
 
@CodyGray you see? You say such things yet you're still welcome. For now...
 
9:59 AM
That's actually one of my stronger-held opinions.
Every code standard I have control over will require camelCase, rather than ugly_underscore_case.
 
Python prefers snake_case for most things by default. And I personally find camelcase a lot harder to read
 
Isn't that just a matter of getting used to?
 
Yeah, like having a metal spike in your frontal lobe
 
I definitely think camelCase is a lot easier to read.
The underscores spread it out too much. Besides underscores being too darn hard to type.
 
I come from a land where we have another "quick brown fox": "árvíztűrő tükörfúrógép"
 
10:08 AM
Do we have a dupe target for "Why does (...) not make a tuple?"? I've only found the opposite in canon.
 
(That being said I don't really use our keyboard layout and it's impossible to write code with it)
 
Well, yeah, some languages are just white noise. :-p
 
I code with a German keyboard layout. Anything is hard to type. Makes you appreciate lean code... ^^
 
Thanks. Being able to add several dupe targets really is worth all the years of answering questions of questionable quality... ^^
 
10:12 AM
It is, though!
 
@MisterMiyagi Should I add this one, with an answer by Martijn? stackoverflow.com/q/15412055/4014959
 
Hi!
 
A string + a comma == a tuple? Something is wrong with this math.
 
@Noé Hello
 
@PM2Ring go for it!
 
10:19 AM
Done
 
How did I not find the previous questions before asking my own... I guess I searched the wrong way
 
@CodyGray You can visit this website.
 
@R.B. that needs lots of practice
 
@CodyGray It's one of the warts of Python. Parentheses are really overloaded in subtle ways, and they are optional when there is no conflict.
Commas make tuples, not the parentheses. Unless it's a list. Or a signature. Or a set. Or...
 
@CodyGray Commas make tuples. The parentheses are only required for tuples in situations which would be ambiguous without them. So we can do stuff like a, b, c = 2, 3, 5
 
10:21 AM
@Noé I saw exactly that website. It seems to be wrong, as it says that the parentheses are what make a tuple. I trust Martijn over that website.
@PM2Ring Ugh, what? One of the members of that tuple is the result of assignment?
 
The assignment operator statement can unpack iterables.
 
Repeating myself: "Ugh, what?"
 
@Noé that's terrible, as usual for w3schools
 
It has the same result as a = 2; b = 3; c = 5.
 
Oohh.
Yeah, that's ugly. :-(
 
10:23 AM
@CodyGray there are two things there. Creation of a tuple on the rhs and unpacking a tuple on the lhs
 
@CodyGray We have two tuples there. It could be written as (a, b, c) = (2, 3, 5). And yes, it performs 3 assignments, essentially in parallel.
 
Usually, unpacking is used when you already have a sequence. So x, y, z = coord3d would be a more idiomatic usecase
 
Sorry about the triple ping. I'm on a phone & my fingers are getting clumsy...
 
@CodyGray a common idiom is a, b = b, a to swap two values
You can omit a tmp name with that
 
I'm pumping Eminem so loud that I can't hear the pings anyway, so no worries. :-)
 
10:26 AM
Ha, I always took you for more of a Mozart fan
 
If you want to convert cURL to python-requests, you can use this tool: curl.trillworks.com/#python
 
@AndrasDeak See, that's what I don't get. In what universe is that any more clear or readable than just using a temporary variable? It's too damn clever. You're trying too hard.
 
@Noé who asked for that?
 
@AndrasDeak Uh, well, I do like classical music. But it's not something I listen to on a regular basis. Stravinsky is one of my favorite composers, for example.
 
I'm just giving informations...
 
10:28 AM
If you want to buy a 6502 chip, you can check here for suggestions
 
@Noé giving information that nobody asked for is spam
 
Oh sorry
I didn't know
 
@CodyGray this is one of those "one obvious way you recognize" things
 
@Noé W3Schools has a bad reputation on Stack Overflow. They have improved tremendously, but they're still not ideal. And they have wrong or misleading info regarding Python. Also see w3fools.com
 
@AndrasDeak Yes, pattern-matching. I get it. But why do I need to learn these new weird patterns, instead of doing things the obvious way?
 
10:29 AM
Takes a lot fewer mental CPU cycles to write and parse than a swap with tmp
@CodyGray it's obvious in python ;)
 
@AndrasDeak Wait, wait, wait, wait. What?
 
@AndrasDeak Knowing the assignment statement rules, I'm not too sure about that...
 
If you don't like python don't be surprised not to like its patterns
 
I don't know Python, so I can't exactly say that I "don't like" it.
 
@MisterMiyagi I'm specifically talking about swapping two values
 
10:31 AM
But I think my mental CPU is wired differently than yours.
 
@CodyGray probably
 
Because nothing about unpacking a tuple suggests "swap two values".
I can see how there would be powerful uses for that, but... swapping two values is not one of them I imagine.
 
@AndrasDeak Oh, right. They have a ByteCode for that. Was surprised to see that a few days ago.
 
@CodyGray for the swap you also need the left-hand side...
 
"unpacking a tuple into a tuple", I suppose is what I should have said
 
10:32 AM
@MisterMiyagi you did read "mental" in "mental CPU cycles", right?
 
@AndrasDeak Only after you edited it :-p
 
Jul 26 '18 at 14:00, by PM 2Ring
FWIW, years ago the W3C requested that w3schools change their name because it was too close to W3C, and they didn't want people thinking that w3schools is somehow affiliated with or endorsed by the W3C. You may note that the w3schools site even looks similar to the W3C...
Jul 26 '18 at 14:13, by PM 2Ring
I got that W3C vs w3schools info from my xkcd buddy Tab Atkins, who is on the W3C CSS Working Group (as well as being a developer at Google). W3C didn't just ask once, they've asked repeatedly, to no avail, and they don't want to waste money taking it to court. I guess they also don't want the possibility of not winning the case.
 
@CodyGray It's mostly something we get for free from the more powerful use-cases.
 
@CodyGray true, I was missing a space and a letter...
Pesky mobile non-keyboard
 
@MisterMiyagi Yes, plenty of things fall out for free in the implementation of powerful features. I get that, obviously. What I take issue with is the claim that it is somehow more clear/obvious than simply using a temporary variable to swap a value.
 
10:35 AM
@AndrasDeak My mentalparser did not parse that correctly. :P
 
@CodyGray well there's Fibonacci's prev, now = now, now + prev but you will like that even less :P
 
There's also the XOR swap. But yes, I like that even less.
 
@CodyGray Well, it kinda is if you are used to the other stuff.
 
@CodyGray unlike that, in python you just swap the labels of the existing two objects
 
Yeah, everything's a reference. It's just like Java!
(This is me snarkily implying something which you do not want to be like.)
 
10:37 AM
XOR swap probably brings in new objects (give or take cpython implementation details)
 
...only if integers are immutable
 
@CodyGray We're well ahead with the self deprecation
 
Meh. I like final.
 
"Motivation [...] This is a common feature in other object-oriented languages (such as Java)"
 
It should be the default, though. You should have to explicitly indicate that a particular function is designed to allow overriding, not the other way around.
 
10:39 AM
Who doesn't want assignments in all the wrong places?
 
I'm sure it's perfectly harmless once you get used to it.
 
I kinda don't understand why programmers are so averse to writing code.
You want to do an assignment? Great. Write a line of code that does the assignment.
 
There's one objective use case in Python, namely if-elif chaining.
Can't insert an assignment statement between the elements of a if-elif chain.
 
Some people like dense cryptic looking code. Especially if it's all packed into one line. This goes against Kernighan's maxim, and Python's philosophy of optimizing for readability.
 
Granted, there are also tons of use cases which are an incomprehensible mess with asspressions...
 
10:44 AM
@MisterMiyagi and calling expensive functions once
 
Right. Can't do that. Think of the children performance!
 
@MisterMiyagi Why would you want to? Do the assignment in one of the if blocks, not in-between.
@AndrasDeak Solved by... wait for it... introducing a temporary variable!
 
It's technically useful if you have an API such as the one for regex. Then you first need to check whether you have a match before using the match in the block.
 
Yeah, chaining a bunch of elif match := re.match(...): statements is prettier than having to add another level of nesting for each
 
@CodyGray in some cases that needs another level of indentation
What Aran said
@CodyGray because writing readable code is so 2010
 
10:49 AM
2010 was a good year
 
if do_thing:
    thing = expensive_call()
    if thing:
        thang(thing)
 
@CodyGray that's easy to say in 2020 (:
 
@AndrasDeak meh, I just use memoization for these things.
 
OK, it's usually just DRY-friendly rather than expensive
 
@AndrasDeak Yes, that is readable code.
What decade is it from?
 
And shadowing str...
@MisterMiyagi or an empty tuple
 
No wonder people prefer LISP! At least parentheses make sense there...
 
@MisterMiyagi I see you prefer to render non-preferred languages in ALL CAPS.
 
Poor angry man
He might make president chancellor one day
 
I'm hoping that some day soon, the fad of making the angriest, craziest, clownest person the Supreme Ruler will die off.
 
11:09 AM
@CodyGray Now that you mention it, I should probably cut back on coffee.
 
@MisterMiyagi JAVA reference!
 
:-)
 
11:28 AM
@Hakaishin "funny" is not the right word and I'd rather not go into that here
 
@AndrasDeak sure, I will leave it at short snarky remarks ala @CodyGray
 
short, snarky and general, yes
 
I'm not good at "short"...
 
for you we can allow long long...
 
 
1 hour later…
12:47 PM
@PM2Ring I don't believe so, but I'll be happy to contribute to one.
 
@holdenweb Thanks. Maybe that article by dabeaz that Andras linked will be ok. But I think it'd be nice to have something a bit larger.
 
00:00 - 13:0013:00 - 23:00

« first day (3529 days earlier)      last day (1402 days later) »