|
Fergus Mac Roich posted:And it doesn't have tail call elimination QuarkJets posted:I know all about Julia and played around with it when it was 0.2, and then again when it was 0.3, and then again when it was 0.4. It didn't really suit me in beta form due to poor documentation and some weird undocumented stuff going on some of the time, so I'm hoping to return to Julia once it's in 1.0 and stable and well-documented. In the meantime I mostly write Python for development speed and versatility, and if I need certain bits of code to run faster then I compile them with Numba. Dominoes fucked around with this message at 21:37 on Apr 3, 2016 |
# ? Apr 3, 2016 21:32 |
|
|
# ? May 29, 2024 21:52 |
|
Cingulate posted:Certainly not prioritized, but it does seem to me it's quite possible to do tasks of moderate complexity in idiomatic Python in a functional way. E.g., toolz. I'd say low complexity; it's definitely possible to do things like aggregate operations (map/filter/fold/et al), but with lack of good support for things like algebraic data types, currying, and pattern matching, it ends up being pretty painful past simple list processing. Plus, even the most OO of OO languages, Java, can do map and reduce now with streams, and it even has lambdas.
|
# ? Apr 3, 2016 21:40 |
|
You can curry with toolz.
|
# ? Apr 3, 2016 21:58 |
|
Dominoes posted:Video criticizing OOP. I wish this guy had used a few more metaphors to explain how OOP leads to jumbled programs. It would have made it easier to overlook the fact that he doesn't have any solutions to offer, or really any specific complaints at all.
|
# ? Apr 3, 2016 22:19 |
|
Asymmetrikon posted:I'd say low complexity
|
# ? Apr 3, 2016 22:41 |
|
Actually, low complexity was not really a good choice of words on my part, sorry; I suppose I mean that Python is good at using functional concepts to augment its imperative, procedural nature, but the problems it solves well are complex in a different way than problems a functional language would be good at.
|
# ? Apr 3, 2016 22:45 |
|
Dominoes posted:Yea; I wish it did. It sort of does though; you're free to create your own types, they just can't have their own methods. It's partial OOP, which is fine for what julia is designed to do (scientific computation)
|
# ? Apr 4, 2016 00:03 |
|
Nippashish posted:I wish this guy had used a few more metaphors to explain how OOP leads to jumbled programs. It would have made it easier to overlook the fact that he doesn't have any solutions to offer, or really any specific complaints at all. I watched some more of his videos and he rewrote some NES emulator written in golang to be more procedural. While he did "fix" some things, I think it got taken to quite an extreme.
|
# ? Apr 4, 2016 17:33 |
|
It's a pretty good rule of thumb that you can dismiss the opinion of anyone taking an absolutist position.
|
# ? Apr 4, 2016 18:10 |
|
Like, I can highlight the downsides of just about anything and then declare that thing is bad. edit: Doublepost! edit2: You'd probably get more/better discussion by posting this video in the general programming questions megathread. Thermopyle fucked around with this message at 18:14 on Apr 4, 2016 |
# ? Apr 4, 2016 18:11 |
|
It's true, everything is bad.
|
# ? Apr 4, 2016 18:13 |
|
Thermopyle posted:It's a pretty good rule of thumb that you can dismiss the opinion of anyone taking an absolutist position. Also any video (or speech) that claims to be "the most important video that you're ever going to watch" is definitely garbage. It does this like 3 times at the start
|
# ? Apr 4, 2016 18:55 |
|
Although I did like the bit where he compared Java to the Nazi regime
|
# ? Apr 4, 2016 18:58 |
|
QuarkJets posted:1. Totally fine for a project of this size, for a larger project you might do one class per screen, one file per class. Thanks for the help. I do want to split the program up into several files (one for each tab in the QTabWidget), and so I built a separate class for the third tab (Simulation Parameters): Python code:
code:
Python code:
|
# ? Apr 4, 2016 19:06 |
|
Jose Cuervo posted:Thanks for the help. I do want to split the program up into several files (one for each tab in the QTabWidget), and so I built a separate class for the third tab (Simulation Parameters): Change "class SimParamsTab(QtGui.QWidget())" to "class SimParamsTab(QtGui.QWidget)".
|
# ? Apr 4, 2016 19:14 |
|
QuarkJets posted:It sort of does though; you're free to create your own types, they just can't have their own methods. It's partial OOP, which is fine for what julia is designed to do (scientific computation)
|
# ? Apr 4, 2016 19:15 |
|
accipter posted:Change "class SimParamsTab(QtGui.QWidget())" to "class SimParamsTab(QtGui.QWidget)". DOH! Thank you!
|
# ? Apr 4, 2016 19:31 |
|
Fergus Mac Roich posted:And it doesn't have tail call elimination Not as a built-in language feature, but one of the "good" things about Python is you can pretty much do whatever you want, such as programmatically rewrite recursive calls in tail position for a given function's AST.
|
# ? Apr 4, 2016 20:10 |
|
Pie Colony posted:Not as a built-in language feature, but one of the "good" things about Python is you can pretty much do whatever you want, such as programmatically rewrite recursive calls in tail position for a given function's AST. You're right, that is "good". edit: Oops I'm posting in GBS too much. Fixed capitalization. Also yeah Python isn't perfect in terms of functional programming but I find that first class function objects and map() and stuff get me most functional-esque stuff I'd like to express in my imperative code. Fergus Mac Roich fucked around with this message at 20:14 on Apr 4, 2016 |
# ? Apr 4, 2016 20:11 |
|
FWIW my favorite anti-OO screed is Object Oriented Programming is an expensive disaster which must end
|
# ? Apr 5, 2016 00:46 |
|
People sure are mad about programming
|
# ? Apr 5, 2016 01:49 |
|
mine is Goodbye, lovely Car extends Vehicle object-orientation tutorial
|
# ? Apr 5, 2016 03:42 |
|
Is there an easy, simple answer for why, and when, things are faster on my Macbook Air than on our Xeons and Opterons? Particularly, code:
I understand this doesn't benefit at all from our Xeons being dual-CPU, 12-core, but I'd still not expect my MBA to be faster at basically anything but maybe for disk access due to it having an SSD. Edit: this, too %time for _ in range(10000000): 2**2**3**2 + 2**2**3**2 Cingulate fucked around with this message at 10:34 on Apr 5, 2016 |
# ? Apr 5, 2016 10:22 |
|
Cingulate posted:Is there an easy, simple answer for why, and when, things are faster on my Macbook Air than on our Xeons and Opterons? The first three are probably due to the MBA having faster memory; all that you're really testing is how quickly you can access a memory address and how quickly you can create a pointer to that memory address. You're not testing computational power at all with those lines of code. Instead of making shallow copies of lists, try calling sha1 on the list instead (do this with map() or a list comprehension). The edit is bottlenecked by function calls (which are expensive), so you're really just testing to see how quickly you can access the pow function (either on the disk or in memory). Again, not much of a CPU test.
|
# ? Apr 5, 2016 12:08 |
|
QuarkJets posted:The first three are probably due to the MBA having faster memory; all that you're really testing is how quickly you can access a memory address and how quickly you can create a pointer to that memory address. You're not testing computational power at all with those lines of code. Instead of making shallow copies of lists, try calling sha1 on the list instead (do this with map() or a list comprehension). And this is why benchmarks are hard
|
# ? Apr 5, 2016 14:10 |
|
QuarkJets posted:The first three are probably due to the MBA having faster memory; all that you're really testing is how quickly you can access a memory address and how quickly you can create a pointer to that memory address. You're not testing computational power at all with those lines of code. Instead of making shallow copies of lists, try calling sha1 on the list instead (do this with map() or a list comprehension).
|
# ? Apr 5, 2016 15:23 |
|
I am still having some trouble knowing what to specify as a parent when adding buttons, etc to the GUI. Here is the code for one of the tabs in the GUI:Python code:
Further self.scenario_file_browse_btn is a QtGui.QPushButton that is placed in a QHBoxLayout, the QHBoxLayout is placed in a QVBoxLayout, and the QVBoxLayout is placed in a QGroupBox. So should self.scenario_file_browse_btn have the QHBoxLayout as its parent, the QHBoxLayout have the QVBoxLayout as its parent, the QVBoxLayout have the QGroupBox as its parent, and the QGroupBox have self as its parent? Lastly, I am declaring everything using self. since I am in the __init__ function. Is this correct?
|
# ? Apr 5, 2016 15:28 |
|
Jose Cuervo posted:I am still having some trouble knowing what to specify as a parent when adding buttons, etc to the GUI. Here is the code for one of the tabs in the GUI: Either answer can be correct, but ideally the parent should be tab_hbl. Note that some methods will cause an object to take ownership of other objects automatically. In this case, QWidget.setLayout and QLayout.addWidget will result in objects being re-parented, so you don't need to set the parent in these cases (or if you do anyway, just know that this parent info will get overwritten). quote:Further self.scenario_file_browse_btn is a QtGui.QPushButton that is placed in a QHBoxLayout, the QHBoxLayout is placed in a QVBoxLayout, and the QVBoxLayout is placed in a QGroupBox. So should self.scenario_file_browse_btn have the QHBoxLayout as its parent, the QHBoxLayout have the QVBoxLayout as its parent, the QVBoxLayout have the QGroupBox as its parent, and the QGroupBox have self as its parent? This seems like a reasonable parent hierarchy to me; think of layouts as containers, so if your layout has 3 widgets inside of it then you want those 3 widgets to have the layout as a parent. You're using addWidget and setLayout, so your parentage is probably all okay already quote:Lastly, I am declaring everything using self. since I am in the __init__ function. Is this correct? It's not strictly necessary, using self implicitly means that you want to be able to access the content of those variables later. Due to the way in which Qt parent/child relationships and signal/slot mechanics work, you could not use self for the vast majority of Gui elements so long as you've got parentage sorted out. But definitely use self for variables that you'll need later.
|
# ? Apr 5, 2016 19:37 |
|
I've been using Python for bullshit scripts for a few years, but now I'm working on my first real-rear end app. Coming from C++, duck typing feels weird and wrong to me. Now that the abc module's been around for a while, what's the general sentiment? Is it pythonic?
|
# ? Apr 8, 2016 03:47 |
|
GameCube posted:I've been using Python for bullshit scripts for a few years, but now I'm working on my first real-rear end app. Coming from C++, duck typing feels weird and wrong to me. Now that the abc module's been around for a while, what's the general sentiment? Is it pythonic? Maybe abc now interacts somehow with the new type annotations to more clearly define what's expected of an implementation? But I feel like whenever you start asking those kinds of questions, you're really asking why should you be using Python for that task in the first place?
|
# ? Apr 8, 2016 04:00 |
|
KICK BAMA KICK posted:I've never done anything more than hobbyist stuff, but I liked using abc when I was learning Python as my first language. Then when I got some experience in statically typed languages with actual interfaces, I felt like abc was just a crutch that could never really fulfill what I wanted when I tried to use it. Just my vague opinion though. I kind of feel like this. I had a personal project I was working on recently (still not got anywhere with it) that I started out trying to write in Python, realised after a while that I was trying to write C# in Python, switched to trying to do it in C# instead, but then got frustrated with some of the roadblocks that C# puts in your way that feel unreasonable after you've gotten used to being able to play a bit fast and loose like you can in Python*. Then I went back to Python trying to use the new type annotation stuff but it still wasn't what I was looking for. Basically I'm in an unhappy point in between the two languages and it is pretty annoying. * like not having a notion akin to Python's "class methods", where you have an essentially static method but it cares which class you used to call it
|
# ? Apr 8, 2016 10:55 |
|
Some thought after posting the video about OOP a few days ago and the responses. I think I like making classes for cases that fit the progamming-101 paradigm of managing concrete members of a category; this is why they make sense for database ORMs. I don't like using them for abstractions.
|
# ? Apr 8, 2016 14:38 |
|
Hammerite posted:* like not having a notion akin to Python's "class methods", where you have an essentially static method but it cares which class you used to call it Extension methods don't do what you want?
|
# ? Apr 8, 2016 18:21 |
|
I'm just beginning to learn Python, and I was wondering what the best way to create a list of variable length filled with copies of one thing is. Specifically, I want to create the list [[],[],...,[]] where there are k empty lists. Right now, I'm looping over k and appending empty lists to my growing list of empty lists. I can't do [] * k because modifying one of the [] modified them all. More generally, my setup is that I need k containers that I will fill with numbers. I do not know how many numbers will go in each container. Is there a better way to do this than a list of empty lists? I'm using NumPy/SciPy if that's any help.
|
# ? Apr 8, 2016 18:52 |
|
You can use a list comprehension to do that cleaner. Or you could use a dict of lists.
|
# ? Apr 8, 2016 18:59 |
|
drainpipe posted:I'm just beginning to learn Python, and I was wondering what the best way to create a list of variable length filled with copies of one thing is. Specifically, I want to create the list [[],[],...,[]] where there are k empty lists. Right now, I'm looping over k and appending empty lists to my growing list of empty lists. I can't do [] * k because modifying one of the [] modified them all. from itertools import repeat
|
# ? Apr 8, 2016 19:00 |
|
drainpipe posted:I'm just beginning to learn Python, and I was wondering what the best way to create a list of variable length filled with copies of one thing is. Specifically, I want to create the list [[],[],...,[]] where there are k empty lists. Right now, I'm looping over k and appending empty lists to my growing list of empty lists. I can't do [] * k because modifying one of the [] modified them all. The list comprehension thing that vikingstrike mentioned would go like this: Python code:
Basically there might be a better way to accomplish whatever you're trying to do without resorting to lists of lists QuarkJets fucked around with this message at 19:46 on Apr 8, 2016 |
# ? Apr 8, 2016 19:43 |
|
QuarkJets posted:The list comprehension thing that vikingstrike mentioned would go like this: Possibly slightly better: code:
|
# ? Apr 8, 2016 20:04 |
|
I'm coding up the k-means clustering algorithm for a homework assignment. I'm given a list of data points (each with two coordinates) and I need to put them into k clusters. The way I'm doing it is to define k empty lists and fill them up with indices of my data points according to which cluster they belong to. I just realized that adding an extra column to the data array to indicate cluster assignment might work just as well. edit: actually, that probably wouldn't be good since I need to calculate the means of a cluster and accessing the points of a cluster would be much harder if I had to read it from a field. drainpipe fucked around with this message at 21:05 on Apr 8, 2016 |
# ? Apr 8, 2016 20:52 |
|
|
# ? May 29, 2024 21:52 |
|
drainpipe posted:I'm coding up the k-means clustering algorithm for a homework assignment. I'm given a list of data points (each with two coordinates) and I need to put them into k clusters. The way I'm doing it is to define k empty lists and fill them up with indices of my data points according to which cluster they belong to. I just realized that adding an extra column to the data array to indicate cluster assignment might work just as well. Have you looked into pandas? Stuff like this seems like it would be suited well. For example, to find the mean of a cluster is a simple groupby function call. Accessing the data points of a cluster is just indexing, etc.
|
# ? Apr 8, 2016 21:06 |