|
vOv posted:Didn't Python's built-in HTTP library not actually verify HTTPS certificates by default for a long time, or am I thinking of something else? Yeah, until late 2014 (some 2.7.x maintenance release) or so.
|
# ? Jan 20, 2016 08:28 |
|
|
# ? May 14, 2024 14:52 |
|
I've read several of Rob Pike's papers and watched some of his talks about the design of Go, and I think he has a very different definition of "simple" than I do. It seems Guido is in a similar camp to Rob. For loops are very flexible and can be used to produce solutions to many problems. That's one kind of simplicity. map, reduce, filter, scan and friends each have a very specific purpose, and expose fewer "moving parts"- no loose variable definitions, no opportunities for off-by-one errors. I find that a more satisfying kind of simplicity. By having a more specific use case in mind, they convey more meaning to both a reader and potentially a compiler.
|
# ? Jan 20, 2016 08:36 |
|
The problem with list comprehensions is that they're only reasonable to use in trivial cases, but list comprehensions aren't a trivial feature of python, they're a whole embedded domain specific language, complete with it's own nesting and order of operations. For instance guess what this does:Python code:
Pavlov fucked around with this message at 20:40 on Jan 20, 2016 |
# ? Jan 20, 2016 09:13 |
Pavlov posted:The problem with list comprehensions is that they're only reasonable to use in trivial cases, but list comprehensions aren't a trivial feature of python, they're a whole impeded domain specific language, complete with it's own nesting and order of operations. For instance guess what this does: I've always thought it was really confusing how python orders nested for's in a list comprehension. This: Python code:
|
|
# ? Jan 20, 2016 10:09 |
|
List comprehensions are kind of dumb because they aren't extensible. List comprehensions are only more readable because the language didn't prioritize good syntax for the superior alternative: composing higher order functions. here are some examples of different syntaxes for chaining together higher order functions: code:
code:
code:
|
# ? Jan 20, 2016 11:17 |
|
Internet Janitor posted:Python is a depressingly mediocre language. There are slower languages, more dangerous languages and worse-designed languages, but it is a master of nothing. Arguably it's intended to fulfil that jack of all trades role. But I don't really like the implication that we should want to program in a "more dangerous" language because it's less "mediocre" by somebody's idiosyncratic idea of what is and isn't mediocre. Yes the rocket veered off course and blew up, but on the other hand, the programmers writing the code were enjoying themselves! (Yes I am aware that you wouldn't write a rocket guidance system in Python) quote:From syntax to semantics it is riddled with inconsistencies and "convenient" special cases. What inconsistencies and special cases are you thinking of (give me some worst offenders in your view)? I'm curious because Python has always seemed to me a quite carefully designed language that's had a lot of thought put into it. And they're not afraid to make breaking changes to eliminate bad choices from the past (see Python 2/3). VikingofRock posted:I've always thought it was really confusing how python orders nested for's in a list comprehension. This: I agree, but I've learned to accept the fact that those of us for which this makes more sense are in a minority (sadly).
|
# ? Jan 20, 2016 11:45 |
|
I remember that I looked at one of the popular online Intro to Programming* courses (Coursera's maybe), and chuckled when one of their first examples was riddled with completely unexplained implicit type coercions. "2. + x / 3." where x was set to an integer or something like that. It was something that I understood instantly, but if you're new to the language and don't notice those little periods you're going to get some weird, frustrating outputs. Admittedly, this is probably the fault of the course more than Python's, but I'm not a huge fan of implicit type coercions in general. If you're going to do that, I think Julia's method where you have to explicitly request integer division is better so all numeric types are treated equally. So 3/2 = 3.0 / 2.0 = 1.5. I like it because if you're an experienced programmer it's perhaps a bit unusual, but easy to pick up, and if you're just a person who wants to run some calculations and doesn't have a big understanding of why computers have strange idiosyncratic numeric types it's completely intuitive. * It's possible it was actually the machine learning course, since I think that one didn't require background in Python and was going to teach it to you as you went. Either way, it was "beginner to Python" in some way. Linear Zoetrope fucked around with this message at 11:59 on Jan 20, 2016 |
# ? Jan 20, 2016 11:54 |
|
Jsor posted:I remember that I looked at one of the popular online Intro to Programming* courses (Coursera's maybe), and chuckled when one of their first examples was riddled with completely unexplained implicit type coercions. "2. + x / 3." where x was set to an integer or something like that. It was something that I understood instantly, but if you're new to the language and don't notice those little periods you're going to get some weird, frustrating outputs. Admittedly, this is probably the fault of the course more than Python's, but I'm not a huge fan of implicit type coercions in general. If you're going to do that, I think Julia's method where you have to explicitly request integer division is better so all numeric types are treated equally. So 3/2 = 3.0 / 2.0 = 1.5. Fixed in Python 3, which is what I am generally referring to when I speak of "Python" without further specifying (and so should everyone else be, it was released in 2008 for crying out loud). I will defend the Internet honour of Python 3, I will not defend Python 2
|
# ? Jan 20, 2016 12:06 |
|
To contribute properly to the thread, our company is working on a project that involves units to be deployed remotely that have a GPS receiver in them. The purpose of this is to keep track of where they are. The units have to be programmed in Lua (because that's what's installed on them or something, I don't know). It turns out that Lua supports only one numeric type: you can have single or double-precision floating point, but not both. The people deploying these units configured the Lua to have single-precision floating point numbers. This is not precise enough to keep track of where something is in the world to the nearest metre. Someone at our company ended up having to write Lua code to make ersatz double-precision numbers from the single-precision ones available.
|
# ? Jan 20, 2016 12:30 |
|
Hammerite posted:Fixed in Python 3, which is what I am generally referring to when I speak of "Python" without further specifying (and so should everyone else be, it was released in 2008 for crying out loud). I will defend the Internet honour of Python 3, I will not defend Python 2 Should, maybe, but isn't. There's still an absolute ton of Python 2 out there, so yeah you do kind of need to specify.
|
# ? Jan 20, 2016 12:51 |
|
comedyblissoption posted:
In Haskell in this particular case you could also use do-notation: code:
Of course, Haskell also has list comprehensions, but they're not used much from what I've seen. Subjunctive posted:I'm not sure what my favourite part of that is. The wafting Go aroma of interface {}, or that he decided to name the map operation "apply". It blows my mind how many different names people can come up with for these extremely basic list operations. Off the top of my head I can name: map/apply/transform/collect/select, filter/where, fold/reduce/aggregate/accumulate, car/head/first and cdr/tail, and that's from just a handful of languages.
|
# ? Jan 20, 2016 14:10 |
|
Strewn about the project I inherited are C files, in these C files are bullshit like this:C code:
Edit* I copy and pasted the whole c file. FlapYoJacks fucked around with this message at 14:44 on Jan 20, 2016 |
# ? Jan 20, 2016 14:40 |
|
LOOK I AM A TURTLE posted:In Haskell in this particular case you could also use do-notation: Haskell also has monad comprehensions They are equivalent
|
# ? Jan 20, 2016 14:40 |
|
ratbert90 posted:Strewn about the project I inherited are C files, in these C files are bullshit like this: Are they meant to be exec()'d from another process? That would explain closing all the file descriptors since the new image inherits open file descriptors from the exec()ing process.
|
# ? Jan 20, 2016 15:33 |
|
csammis posted:Are they meant to be exec()'d from another process? That would explain closing all the file descriptors since the new image inherits open file descriptors from the exec()ing process. I'm not worried about the closing of the fd's. Why does this program exist? Why didn't they just call the two whole things from the main program? Why are they not checking return codes? Why does this thing EXIST?
|
# ? Jan 20, 2016 15:58 |
|
Subjunctive posted:Do you think they run Lua in their CDN asset serving code path? They might, CDN systems usually have CPU to spare.
|
# ? Jan 20, 2016 15:59 |
|
LOOK I AM A TURTLE posted:fold/reduce While I agree with you that people spend too much time coming up with stupid new "friendlier" names, folds and reduces are not the same thing. A (left-)fold is of type (a -> b -> a) -> a -> [b] -> a, where a reduction is of type (a -> a -> a) -> a -> [a] -> a. This is pretty important if you actually want them to be parallel (folds aren't).
|
# ? Jan 20, 2016 16:01 |
|
ratbert90 posted:I'm not worried about the closing of the fd's. Why does this program exist? Why didn't they just call the two whole things from the main program? Why are they not checking return codes? Why does this thing EXIST? Yeah, my guess is that there was a need to launch a couple of things from a program but they had to run as root so a little fork()/exec() setup was created with a bunch of tiny programs that do nothing but clean up from having been exec'd and then run their commands. As for why they're not checking return codes, lovely developers do lovely things, who knows?
|
# ? Jan 20, 2016 16:16 |
|
Subjunctive posted:It is both of those things, but that doesn't make it clearer. In fact, "more powerful" usually means "more opaque" when it comes to syntax. Internet Janitor posted:I've read several of Rob Pike's papers and watched some of his talks about the design of Go, and I think he has a very different definition of "simple" than I do. It seems Guido is in a similar camp to Rob. A good general rule I've found to make my code clearer is to always use the least powerful construct that will do the job. In many places people will do this by convention but it's good to have the general principle. Never use a while loop when you could use a for loop; never use a case statement where a simple if would suffice; never use goto when there's anything else available. In this case for example the list comprehension is more powerful than the filter, so I would use a filter. By choosing the less powerful construct you limit the mental burden on the person reading you code because you've limited what the code itself could do. One of the things I like about functional languages (or those that have borrowed their ideas) is that they tend to have finer grained constructs in this regard. map, reduce, filter, scan, fold etc all do things you could do with a for loop in an imperative language yet they communicate so much more. Also I couldn't agree more about Rob Pike. Every time I read something by that guy I find myself disagreeing with it, his philosophy is like the exact opposite of mine.
|
# ? Jan 20, 2016 16:27 |
|
In what way is for less powerful than while?
|
# ? Jan 20, 2016 16:40 |
|
Steve French posted:In what way is for less powerful than while? You can't always modify the loop counter in a for.
|
# ? Jan 20, 2016 17:00 |
|
The comprehension is clearer to me because I don't immediately remember which argument to filter is supposed to be the sequence (and like someone else said, have internalized sequence syntax) and meaningless and/or single-character variable names are depressingly common in the wild vOv posted:Didn't Python's built-in HTTP library not actually verify HTTPS certificates by default for a long time, or am I thinking of something else? IIRC the manual also said it's only meant for local testing.
|
# ? Jan 20, 2016 17:09 |
|
If you try to write a program in a language like it's Java, you're an idiot. If you try to write a program in a language like it's Haskell, everyone responsible for that language is an idiot. (I like functional programming. (Not everything has to be functional programming.))
|
# ? Jan 20, 2016 17:10 |
|
Hammerite posted:Arguably it's intended to fulfil that jack of all trades role. But I don't really like the implication that we should want to program in a "more dangerous" language because it's less "mediocre" by somebody's idiosyncratic idea of what is and isn't mediocre. I think you misunderstood what I was saying. I'm not at all suggesting that people use more dangerous languages because it is exciting. My point is that Python is not as bad as some really terrible options out there (from the perspective of general runtime safety it is better in some ways than C, for example), but you could do much better along that axis- even Java permits catching more issues at compile time and allows programmers to express and enforce better contracts throughout large applications. quote:What inconsistencies and special cases are you thinking of (give me some worst offenders in your view)? I'm curious because Python has always seemed to me a quite carefully designed language that's had a lot of thought put into it. And they're not afraid to make breaking changes to eliminate bad choices from the past (see Python 2/3). If I list specific cases they're going to get picked to death and some will seem rather petty, but here are a few which come to mind: - Double inequalities. Python special-cases expressions of a form like x < y <= z as described here. This has some unintuitive consequences for operator precedence, and while it is a syntax which is often valid in a math class it doesn't generalize and in my experience it gives students a totally wrong initial understanding of how logical expressions work. - I'm not fond of Python's scoping rules, and I think they interact poorly with the decision to make variable declaration implicit. A classic example: code:
code:
- Mutable default values. Not strictly inconsistent, but surprising and unhelpful for common use cases.
|
# ? Jan 20, 2016 17:19 |
|
Every time anyone posts stuff like that about any language I find myself going "oh yeah that's terrible, what a dumb language". Then later I find myself using said language without it ever bothering me. For example, I avoided JS for years because every discussion about it ever highlights all kinds of bullshit. Then I started using it and...it just doesn't bother me. I'm not claiming that odd/wrong/stupid stuff in a language can't be bad for programmer sanity, because I don't believe that. However, I wonder if talking about an issue just makes it seem worse than it actually is. Also there's the issue where different things wax and wane in importance depending upon the environment you're working in...
|
# ? Jan 20, 2016 17:39 |
|
Pretty much. List comprehensions look like line noise to me, so I just never use them.
|
# ? Jan 20, 2016 17:40 |
|
xzzy posted:Pretty much. List comprehensions look like line noise to me, so I just never use them. Oh yeah, I meant to say that I find most list comprehensions in the wild to express intent better than most usages of filter in the wild.
|
# ? Jan 20, 2016 17:43 |
|
Steve French posted:In what way is for less powerful than while? In addition to what fritz said, I was referring to a "typical for loop" where you just loop from one value to another. Doing weird poo poo is normally obvious, although not always. I'm not a fan of the c style for loop party for this reason. For example you could modify the iteration variable in the loop, which is why you should use foreach in place of for where possible (in languages that have it), again because it's less powerful. HappyHippo fucked around with this message at 17:47 on Jan 20, 2016 |
# ? Jan 20, 2016 17:43 |
|
If you're mostly writing new programs you can use a sane subset of a language and avoid its warts. If you want to read or modify existing programs, though, there's a good chance you'll have to deal with warts. In practical projects it comes down to the amount of discipline in your team and how well you agree with one another over how the language should be used.
|
# ? Jan 20, 2016 17:44 |
|
HappyHippo posted:In addition to what fritz said, I was referring to a "typical for loop" where you just loop from one value to another. Doing weird poo poo is normally obvious. What's your criteria for a language construct to be more or less powerful than another? I'm asking because I personally consider foreach loop to be more powerful than a simple for loop. And to be more confusing, I agree with you that foreach should be used where possible instead of a simple for loop.
|
# ? Jan 20, 2016 17:59 |
|
For can be used for everything foreach can, but not vice versa. Therefore for is more powerful.
|
# ? Jan 20, 2016 18:03 |
|
List comprehensions are at best equivalent to a map(filter(li, f), g) and it's hilarious that guido thinks a language level construct is needed. Guido is a very arbitrary person who much like Pike should not be in charge of a language. See also "x if cond else y". Python is a stillborn language. There's enough of the community that will literally never stop using Python 2. All the courses I've been taking at university that use Python don't even mention what version to use but will depend on Python 2-only packages and what have you. Breaking packages was very stupid. It put the community in the position of "I won't migrate until the libraries I depend on are migrated to Python 3" and the library devs in the position of "I won't migrate until people are actually using Python 3." I have never heard of a new language version making it impossible to use libraries built with the previous version of the language except Python. That said, the best teaching language is still Beginning Student Language from How to Design Programs. edit: I guess some of the illegible list flattening stuff won't work with map. You need flatMap or SelectMany or something. brap fucked around with this message at 18:13 on Jan 20, 2016 |
# ? Jan 20, 2016 18:11 |
|
At least people are using Python 3. Or starting to. Unlike Perl 6.
|
# ? Jan 20, 2016 18:15 |
|
Plorkyeran posted:For can be used for everything foreach can, but not vice versa. Therefore for is more powerful. Yeah, often people say "powerful" to mean "does more stuff for me", but in the context of languages I think a better definition is "can be used to do more things". I also like filter/map over comprehensions because you can extend the set of operations consistently with your own functions, whereas with list comprehensions you end up mixing comprehensions with functions, giving you the worst (IMO) of both worlds. fleshweasel posted:I have never heard of a new language version making it impossible to use libraries built with the previous version of the language except Python. I think Perl5/Perl4 had that problem, and it's certainly common enough with frameworks which have other libraries around them (angular, react, etc.). Also, Swift breaks poo poo all the time.
|
# ? Jan 20, 2016 18:17 |
|
Plorkyeran posted:For can be used for everything foreach can, but not vice versa. Therefore for is more powerful. Subjunctive posted:Yeah, often people say "powerful" to mean "does more stuff for me", but in the context of languages I think a better definition is "can be used to do more things". Thanks, that makes sense.
|
# ? Jan 20, 2016 18:23 |
|
fleshweasel posted:Breaking packages was very stupid. It put the community in the position of "I won't migrate until the libraries I depend on are migrated to Python 3" and the library devs in the position of "I won't migrate until people are actually using Python 3." Ehh, I avoided Python 3 for several years because I always ran into packages that didn't work on it yet. Now I almost always use it because I very rarely run into that problem. Of course, that's going to be dependent upon what kind of work you do. I mean, yes, its a big clusterfuck, but the situation is way better now and you can tell its getting better.
|
# ? Jan 20, 2016 18:35 |
|
Thermopyle posted:Ehh, I avoided Python 3 for several years because I always ran into packages that didn't work on it yet. Now I almost always use it because I very rarely run into that problem. Of course, that's going to be dependent upon what kind of work you do. OS X still ships with 2.7, alas.
|
# ? Jan 20, 2016 18:37 |
|
Plorkyeran posted:For can be used for everything foreach can, but not vice versa. Therefore for is more powerful. Here we also see that just because something is more powerful doesn't mean it's better. forEach should almost always be used over for(;;).
|
# ? Jan 20, 2016 18:39 |
|
Python: at least it's not perl.
|
# ? Jan 20, 2016 18:40 |
|
|
# ? May 14, 2024 14:52 |
|
qntm posted:Here we also see that just because something is more powerful doesn't mean it's better. forEach should almost always be used over for(;. Yes, indeed I think you should always use the least powerful construct out of your choices. (Similarly, give your programs the least privilege you can.)
|
# ? Jan 20, 2016 18:41 |