- Joined
- Feb 8, 2021
Either way is fine, really. Just pick what's consistent with the rest so that you don't have some functions which take a from_end argument and some which don't.[...]
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Either way is fine, really. Just pick what's consistent with the rest so that you don't have some functions which take a from_end argument and some which don't.[...]
This is one of my favorite parts of functional programming. FP is really more of a mindset above anything, since every function composition is a new reference frame.So Ocaml is a functional language. All its variables are immutable. But unlike, say, Haskell, it isn't purely functional.
I do think functional programming will improve your code, it makes things more debuggable and readable, and harder to fuck up.
But some algorithms simply are easier to reason about with side effects. Not all, and I do encourage people to try and reimagine their algorithms in a functional way. Functional programming, where it works, does pay dividends.
But it's not universal. Again, I'm not a purist.
Could you elaborate on the last point? I don't know enough about FP to comment exactly but was reminded of the following book by Rudy Rucker:Managing side effects in a purely functional sense is like constructing a mini world and defining the rules by which an observer can interact with it. It's hard not to draw the obvious parallels with life, the universe, and the human experience.
Sure. The big no-no in pure functional programming is the existence of unmanaged side-effects. But who's to say we can't just manage them instead? What if we reframe our perspective a little and start explicitly describing an environment (or "world") in which these effects can occur? This is where it gets really interesting.Could you elaborate on the last point? I don't know enough about FP to comment exactly but was reminded of the following book by Rudy Rucker:
Angry Penrose noises.What if everything is a computation?
I see your angry Penrose noises and raise you aAngry Penrose noises.
The biggest reason to not have this is privileging one split over the other for no good reason. Unlike the "list" (which isn't a real list in python), the string is immutable and doesn't have a privileged end. At any time you want rsplit instead of the regular split, you also want max_splits. So it's two arguments to cut something off the other end. But it doesn't seem to me like wanting the first x items comes up more often that wanting the last x items. If split was one function and took an optional argument, more people would want a "partial" shorthand for "split from end" than there are people who decide from which end to split at runtime.So instead of using rsplit(), why not have something like split(from_start=False)? Something like that.
I've done verbose variable naming like this before but ultimately realized it can go too far. Would I rather see names likeOne criticism that I have in mind is that if you really need to separate these two splitting functions, you should name them appropriately, we are not programming in C in the 80's anymore:split_from_left
andsplit_from_right
let you immediately understand what they do instead of havingsplit
andrsplit
.
itertools
become iterator_tools
and so forth until the code can't fit on single lines? Certainly not. One area where Python definitely nails it is statements like import pandas as pd
and import numpy as np
which don't pollute the global namespace like R does but are still reasonably compact.ObviouslyWould I rather see names likeitertools
becomeiterator_tools
iteratorTools
is the correct answer I would argue passing boolean as argument is in most of cases a code smell.Is there something else as a reason, or just this?
s.split(true)
? s.split(false)
? I 100% agree. As a rule of thumb, a specific form/implementation is best when I can glance at it and understand it in one quick step. The more verbose you are, the more data your brain has to strip away to isolate the basic meaning of what's written. Also,I've done verbose variable naming like this before but ultimately realized it can go too far. Would I rather see names likeitertools
becomeiterator_tools
and so forth until the code can't fit on single lines? Certainly not. One area where Python definitely nails it is statements likeimport pandas as pd
andimport numpy as np
which don't pollute the global namespace like R does but are still reasonably compact.
rsplit
can be distinguished from split
by using the first few letters. split_from_{left,right}
requires traversing the whole phrase to do this. All of this mental effort (I'm being serious here) adds up quickly when you consider how much you need to parse on average every second. We were built for simple stuff like poke bear with big stick; hope bear doesn't poke back.It's up to you to be competent enough to understand when a variable's name becomes too verbose. Part of your job (and to make things easier to you and/or other programmers that might read your code later on) is to document your code on what it does (the *how* is not that important most of the time) and self descriptive variables coupled with clear and concise comments can seriously save you a lot of time in the future when you decide/need to get back to your code base.I've done verbose variable naming like this before but ultimately realized it can go too far.
"How many screens up do I need to scroll to read the original context of this name?"It's up to you to be competent enough to understand when a variable's name becomes too verbose.
idx
or res
(for result) or things like that. But that's just personal taste.Console.WriteLine("Windows" + 1 + 1);
"one day you will need this so that you can be talked down to and lectured on stackoverflow for not understanding it"Could they not come up with an example of how any of this shit would be used in the real world?
I don't think anyone would, but it might serve as example of how operator overloading works?Console.WriteLine("Windows" + 1 + 1);
The ability of overloading operators is super niggerlicious.However being able to concat string and integer with + operator is very niggerlicious indeed.
Distinguishing between operators and functions at all is niggerlicious.The ability of overloading operators is super niggerlicious.
Lisp truly is the white man's language but nothing will compare God's own programming language HolyC, provided by the blessed messenger Terry Davis.Distinguishing between operators and functions at all is niggerlicious.
std::cout << "Windows" << 1 << 1 << std::endl;
.I have recently started to play around with Guile.Lisp truly is the white man's language
When you decide it's time, I strongly endorse syntax-rules for the merely eccentric.Haven't played with macros yet