« first day (3911 days earlier)      last day (1259 days later) » 
01:00 - 16:0016:00 - 22:00

01:44
cbg
 
2 hours later…
03:45
Has anyone else noticed a higher-than-average number of questions lately where the asker is using mmap in a completely useless way? E.g., stackoverflow.com/q/68188964/7509065 stackoverflow.com/q/68053344/7509065 stackoverflow.com/q/68049601/7509065 Is there some professor teaching that mmap is a magical "make it faster" function?
 
3 hours later…
06:21
@NickAlexeev Looking beyond the simplicity of the language's design, and its readability, mostly it'a good at string processing because strings are a built-in type with a rich set of methods and no need for garbage collection.
In C#, C and C++ strings all need much more careful memory management. In Python, memory lalocation and deallocation is automatic.
@CoolCloud No, this is the Python room. That's not even a question about programming (so not SO material), but about Operating Systems. Try SuperUser.com and Windows user sites.
^ RO Ouroboros more appropriate than flagging as offensive
06:42
Hmmm I was planning to ask at superuser once I get the error code or something, anyway got it now, thanks for the info
@CoolCloud When joining a new chat room on Stack Overflow, please read the description at the top-right corner of the page. Generally, as in this case, it will contain either the room rules directly or a link to them. Here are the Python room rules. It's also good to just, you know, read the name of the room and assume what is probably welcome based on that.
Super User has chat rooms, too.
The reason I brought it up here is because we also do have alot of off topic discussions, but this is kind of like asking for help, so I get it.
@JosephSible-ReinstateMonica That professor is probably named "The Internet".
It's a common cargo cult trick. Look at it this way: at least they're trying to do some reading and improve their code! Even if they're doing it wrong.
cbg folks
hm, i didnt know what mmap was (still dont i suppose) and i went looking. looks like i found the source of the mmap code verbatim :P link
It creates a memory-mapped file.
Basically, it maps a file on your disk into virtual memory so you can access it as if it were actually an object in memory.
It can be useful to speed up random-access operations to a file.
mmap is, in my opinion, a rather poor choice of name. But Python used it because it's the standard POSIX name for the same concept.
06:53
am i correct in assuming that if i open and read a file's contents anyways, mmap wouldn't really do much for me?
@ParitoshSingh That appears to be code demonstrating the use of mmap in Python, not the actual source code that implements mmap.
since once the string is in memory, it's all in-memory operations anyways. one write at the end i suppose
@ParitoshSingh That's correct. If you open a file once and read its contents into memory, there is no advantage of memory-mapping (mmap).
In fact, using mmap in that case would almost certainly result in more overhead.
cool, good to know, thanks
Apparently, the Python documentation is here.
Under the hood, it's going to be using mmap on POSIX systems (e.g., Linux, macOS), and MapViewOfFile on Windows.
So any background information you want to know that isn't covered in the Python documentation can be learned by reading about the OS-level functions that do the heavy lifting.
06:58
Cody in Python again? The end is nigh! :P
Depends on how annoyed I get :-)
Just last night I explained some python to a C-strong good friend of mine. Needless to say he wasn't crazy about name binding behaviour, but he wasn't as difficult as some people
So you aren't very good at explaining?
He wasn't able to grasp the true horrors?
I will grant you one thing: Python is not as bad as JavaScript.
Small victories.
@CodyGray It would seem so
@CodyGray I'll take it
In truth, I don't know what is so bad about its name binding behavior.
Maybe the broken scoping in try/with/for blocks?
07:08
@AndrasDeak Some people hate it and it just feels like a grumpy guy saying in the past everything was better
No, plenty of things in the past sucked. And C is still here with us in the present.
Although there are plenty of things suboptimal about C. That's why they had to ++ it.
@CodyGray he was unhappy with the usual "names are like poibters but aren't" and "python's neither pass by value, nor pass by reference" descriptions
Unlike some C people, my good friend approached with an open mind :P
@AndrasDeak just let it happen :) That's usually what I tell c programmer. Don't try to understand it, just let python do it's magic. Let go of your need to know every little detail of how things work and focus on getting things done
I've discovered that keeping my mind too open risks things falling out.
The magic usually gets in the way of me trying to get things done...
@Hakaishin well you still need to understand the actual mechanics
07:12
Programming productivity is measured in WTFs/minute. When the language itself and/or its basic syntactical constructs are producing a significant number of WTFs/minute, that's a problem.
meh, I still have no clue what a python variable actually is and how things get passed around, no problem in using it though
We were chatting as he was reading nedbat's "facts and myths about python names" post
I need to be able to predict the behavior in order to write correct code.
@CodyGray you easily can. There are only a handful of gotchas
@CodyGray i C yes, in python you can iterate so fast you can figure out what the code does by just running it quickly with small alterations :P
07:13
@Hakaishin This is why modern computer science education sucks. Joel wrote an article on it: joelonsoftware.com/2005/12/29/the-perils-of-javaschools-2
@CodyGray grumpy old guy detected :P
@Hakaishin Which leads to horrible programming practices. You don't write good, correct code by just throwing things at the wall and seeing what sticks. Even if you "prove" it runs in one circumstance, that doesn't prove it will work in others.
how do you walk?
@CodyGray yeah, no, that's not what we do
@Hakaishin The same way I write C code: by falling down a lot at first, and then intuiting it so I never have to think about it anymore.
07:15
Intuit? Sounds a lot like magic :P
@CodyGray same thing works for python. You don't need to understand every detail to walk, you just do it
When you understand it, it stops being magic.
I... understand every detail about walking...
@CodyGray Did you study neuroscience, otherwise I doubt that
I've got to leave for a while. Don't get the room frozen in the meantime, you two stubborn people :P
Hmm, yes, actually. :-)
07:16
oh cool me too :P
where?
Texas
Zürich here :)
My major was microbiology, not human stuff.
Ok take any other process you know to do on an intuitive level but don't know all the details
So... I know a lot more about neural development in C. elegans than in humans. But, close enough!
@Hakaishin Heh. So... Andras can probably vouch for this, but... that's not really how I do things. :-)
07:17
my point is there are abstractions, ofc they are leaky, but very often they are not
But, I'm with you up to a certain point. I very much like abstractions, and I don't think about low-level memory allocation or whatever every time I write code.
But if you don't actually understand what's happening, the moment something starts to break down or behave in an undesirable or unexpected way, you're SOL.
And that's an uncomfortable and undesirable situation to be in when you're a software developer. Or... any kind of... anything.
Obviously, I can and do work at multiple levels of abstraction. There are times when I'm probing signals with an oscilloscope, which is about as low level as you can reasonably get. I write assembly for fun (and read it sometimes when debugging complex problems or compiler issues.) But I obviously don't spend very much time working at these low levels of abstraction because one cannot be very productive there.
Totally, my point is just there are many things in python which I never had to learn how python does them, because they just never break down. I agree that you have to know the lower levels the leakier the abstraction, but python is a very good abstraction that nearly never breaks down :)
Hah. That I doubt.
Everything around me breaks down on a fairly regular schedule. :-)
The abstraction is as reliable as your understanding of it
That's part of it, but not all of it. There are a variety of externalities that can have an effect, too.
07:32
Those should be included in your understanding :P
Hmm. Sometimes, they're out of your control.
Are we talking about sunspot activity and weather balloons? My code is always self-contained.
It still runs on things like real hardware and relies on things like operating systems and TCP sockets.
At that point no language can save you, right? I'm probably just missing your point because I don't have anything to do with these nooks and crannies of IT.
(insofar as you have a point)
Are you calling me blunt?!
07:37
no, I'm saying you're rambling
Hmm. I thought my pun was better.
but I got the pun (eventually :P)
Haha, that's good.
I'm always surprised that pip is case sensitive
Fortunately only partly: project names are allocated case-insensitively, so you can't squat with different casing.
07:39
That does seem somewhat surprising; I don't know of any other package managers that are case-sensitive.
Case sensitivity is mostly just a footgun.
Yeah the uninstall command is not case sensitive, but the install is, wth
Hmm... It doesn't seem like it's supposed to be: python.org/dev/peps/pep-0426/#name
> All comparisons of distribution names MUST be case insensitive, and MUST consider hyphens and underscores to be equivalent.
nvm, typo
lol
I didn't remember either way
07:47
If you ever run into something that is case-sensitive, you tend to remember...
@CodyGray About twenty years ago there was a brief discussion about making Python source code case-insensitive, but even back then the weight of potential code-breakage and (worse) undetected bug injection to existing source code outweighed the desirabiliity of the change.
@CodyGray pip has some weird things. Like the pip search CLI which has been disabled for like a year because the backend it uses is under constant DoS. There's a searchbar on the pypi webpage that works...
Such a fork of CPython would be interesting, but too much work for me to want to dive in.
When you say "source code", do you mean a = 3; print(A) printing 3? Or just the syntax, like sql?
(without claiming anything about sql non-syntax because I don't know sql)
cbg
07:58
@holdenweb Yes; unfortunately, that's the kind of thing you have to get right from the beginning. It's not something you can introduce as a breaking change. Too much breakage.
@AndrasDeak Hm, that's unfortunate. A good lesson in why we cannot have nice things, I suppose. Not that we needed any more lessons of that.
I don't know why they can't update the CLI to use the same endpoint as the webpage
@holdenweb Adding a pre-parse step where you run the code through a formatter that converts everything to lowercase is hardly enough to merit the name "fork". :-)
perhaps their way of mitigating DoS is to hamstring CLI search
@AndrasDeak You mean only the keywords? No, a and A would be the same names.
@holdenweb oof. Would that benefit users? Fortran does that and it creeps me out.
08:00
@CodyGray I'll be interested to see your code.
something tells me string literals might be tricky
oh and we could throw out the whole "class names use CapCase" thing
Some people expect programming languages to be case-insensitive. After all, the first use of the word "after" in this sentence has the same meaning as all other uses.
String literals aren't source code, they're data :P
@AndrasDeak You could/would still follow that convention, even if the parser was case-insensitive.
Correct.
@holdenweb yes, that's why just putting the source through str.lower like sausage would not work
08:02
Yes, you should always write for readability.
@holdenweb Ooh.. nitpick. No, it doesn't. The capitalization serves a semantic purpose: it indicates the word begins a new sentence.
@AndrasDeak That's true. If you needed to handle string literals, you would need to have a smarter parser. Or, create a requirement that string literals don't belong in source code files and require that strings always be defined as external resources. You know, for your own good. :-)
@holdenweb Do you have any guesstimates about the number of people expecting that? It would be really weird for me. And seeing all the questions on SO where no two variables are spelled the same, but they all refer to the same name... ugh
No it doesn't. that was indicated by the preceding period and space. or is this all one sentence?
@CodyGray python code tends to be full of string literals, on account of docstrings
@holdenweb It is a syntax error. :-)
There are cases where the beginning of a sentence is not necessarily indicated by a period or other sentence-ending punctuation mark. Consider a sentence beginning inside of a quotation mark.
08:05
@AndrasDeak But you "just" have to build an AST to eliminate the string literals. Not quite so simple as it firstt appears.
@holdenweb yup
@CodyGray Well yes, but since we're talking about breaking the rules anyhoo, why don't we just make English case-insensitive? ;-)
Ah well, to work. There are career structures to be designed.
that would physically pain Cody
It would cause a certain amount of unease in me.
So why do you want to do that to your source code? :'(
08:11
It might relieve some of my pain, actually?
It would mean no one could butcher the capitalization rules again, because there would be no capitalization rules.
Then again, with that logic taken to the extreme, we should just grunt, because then there'd be no spelling or grammar rules of any kind to enforce...
morning cbg
I see you folks have been busy
I've been keeping them entertained
no day is a bore when Cody is around
Amen to both
Now please don't mind me, this is very informative
@holdenweb Import hook + AST preprocessing should do, right? I imagine this actually could be doable in, say, a 100 line module. Give or take a few lines for cross-version AST compatibility.
08:26
@MisterMiyagi > @CodyGray I'll be interested to see your code.
@Hakaishin I... don't get this sentiment. Name handling in CPython is practically just pointers. C folks should have little problem understanding it. Seeing this sentiment repeated so often makes me wonder whether the learning material is just bad or where else the issue actually is.
@holdenweb It's tempting indeed. Is Py3.9 okay for a demonstrator?
Sure. It's just a proof of concept, right [gets popcorn]
Are you going to do it in a github repo?
and he was never heard from again
@AndrasDeak well, andras disagrees about "just".
@holdenweb Sure. What could possibly go wrong by publishing something like that? :P
08:33
sorry this is a reference to your ping to me @MisterMiyagi but I couldn't reference two msgs at the same time
@Hakaishin Indeed. Andras and me will have to settle that at our usual 10PM meeting on the rooms/6 parking lot.
I'll bring the hot chocolate
@holdenweb I'm gonna have to pull the lunch duty card for now. This message is an IOU-an-import-hook for, uhm, let's say tomorrow.
and he was never heard from again
I blame it on the pink dinosaurs. Kevin saw them too.
08:36
cbg
talk about "commit"
Finding a punny name was challenge 1.
@MisterMiyagi I tried it, but it doesn't seem to work :-p
09:07
It's just missing the magic sprinkles.
Practically done.
 
2 hours later…
10:40
i am wanting to check if a string `startswith` one among the string patterns predefined..
Preconditions:
1. the predefined string patterns are in the order of hundreds in quantity
2. the check operation is loaded into a very complex system, which calls the check function a few hundreds of times in under a second.
Question:
i feel like my implementation is kinda primal, so wanting a review
prelist = ["a","b","cc","dddd","fewhundredmore"]

def checklegality(word):

	for element in prelist:
		if word.startswith(element)
			return True
	return False
Just do return word.startswith(tuple(prelist))
If prelist is very long, using a regex pattern might actually be faster than startswith, but... probably not
@Aran-Fey okay noted,
I think regex is definitely worth testing. A sufficiently smart implementation of re.compile could produce a quite fast state machine
okay will check that too
If your strings are always ascii-only, I wonder if using bytes instead of strings would save you a couple cycles...
str.startswith is basically doing exactly what you're already doing, but it can do it X times faster, because C is just like that.
11:00
I wonder if something like github.com/qntm/greenery can construct a regex that matches a set of strings. I know it can do the opposite, but that's obviously easier.
If re.compile is smart enough to construct a trie that merges common prefixes of your prelist, then there are definitely scenarios where it will run faster.
I'd be surprised if '|'.join(prelist) would do anything smart in re
A trivial example: prelist contains ten million unique instances of "abcdef" + randstring(), and also "foobar". Given the input "foobarbaz" A loop-and-check algorithm will require ten million and one comparisons. A trie will require two.
11:15
I tried timing it on a string with a million characters... startswith((s1, s2)) took 14 seconds, and regex is still running...
Casefolded code execution: 30 LOC. Understanding the Import system: Please stand by, mental breakdown in progress.
Correction: Regex was still compiling the pattern
It looks like this is responsible for turning ab|ac|ad into a(b|c|d), but it only does it if all branches share the same prefix. Not suitable for our purposes.
Hmm? Sure it is, if there's no shared prefix then there's nothing to optimize...
Well, my hope is that ab|ac|ad|wx|wy|wz would get optimized into (a(b|c|d))|(w(x|y|z))
11:20
Oh, all of them have to share a prefix? Never mind then
I think so. But I didn't read the code too thoroughly, so maybe it cleverly recurses when I'm not looking
I'm decently sure such transformations are NP'ish, and everything but a simple heuristic would immediately burn away all the speedup you could possibly get.
If any regex expression can go between the pipes, then yeah there are probably a bunch of catastrophically bad cases. But if only sequences of literal characters can be between pipes...
i am loving this discussion, because usually a debate is like when trying to find out whoā€™s right & whoā€™s wrong, whereas a discussion like this serves to establish what is right and at what use cases.
Timing results:
str.startswith: 14 sec
re module: [still compiling]
regex module: [cancelled it after around 30 seconds]
super trivial self-made state machine: [still running]
(Measured using two strings that start with 1 million "a"s and then end in either a "1" or a "2")
11:29
I have an idea for an approach that turns a trie into a super fast C function, but my knowledge of ctypes is 1% of what it needs to be for me to test it
Now this is interesting... Somehow s2.startswith(s2) takes the same amount of time as s1.startswith(s2) or s2.startswith(s2). How on earth?
even for very large strings?
Both of these take around 14.5 seconds on my machine
:o i was able to open dpaste
this is a miracle
I see the Steering Council "strongly suggests" that the upcoming 3.10 changes to enum should be reverted, and PEP-ped for 3.11. Another blow for backwards compatibility!
11:37
If the strings being compared are the same "kind" (whatever that means), then the result can be calculated with a single memcmp call.
I'm guessing memcmp is stupidly fast even for arrays of a million elements
from timeit import timeit


prefix = 'a' * 1_000_000
s1 = prefix + '1'
s2 = prefix + '2'

print(timeit(lambda: s2.startswith(s2)))
print(timeit(lambda: s2.startswith(s1) or s2.startswith(s2)))
45.711478299999996
44.532112999999995
@MisterMiyagi [gets more popcorn]
i dont even.. how.
I wonder if memcmp(ptr1, ptr2, n) is O(1) when ptr1 == ptr2. It would be very inexpensive to do a quick referential equality check, but perhaps they don't bother because it would slow down the common case by a femtosecond.
But then s2.startswith(s2) should return instantly, right?
11:41
maybe its quick because our lengths are the same and the difference is at the end
        /* We do not need to compare 0 and len(substring)-1 because
           the if statement above ensured already that they are equal
           when we end up here. */
from timeit import timeit


prefix = 'a' * 1_000_00
s1 = prefix + '1' + prefix # i know its not prefix anymore, sue me!
s2 = prefix + '2' + prefix

print(timeit(lambda: s2.startswith(s2)))
print(timeit(lambda: s2.startswith(s1) or s2.startswith(s2)))
8.511486100000013
13.36007559999996
(increase a 0 on your machine as you see fit)
Ah, that makes sense. Although I can't find this if statement they're talking about
I had trouble parsing that too, but I think they mean the one on line 9738
PyUnicode_READ(kind_self, data_self, offset) == PyUnicode_READ(kind_sub, data_sub, 0) compares the 0th characters of the strings for instance
if (PyUnicode_READ(kind_self, data_self, offset) ==
    PyUnicode_READ(kind_sub, data_sub, 0) &&
    PyUnicode_READ(kind_self, data_self, offset + end_sub) ==
    PyUnicode_READ(kind_sub, data_sub, end_sub))
i cant mentally parse this chunk, looks like gibberish to me, but i assume its here
ah, kevin'd
so yeah, i suppose this is just a neat little optimization
11:46
Yeah
so yeah, we can also infer that the original operation is not O(1) when the strings are equal. the part that's optimized is the inequality
i imagine for it to be equal, it has no choice but to go through it even with memcmp, but now im just speculating
12:02
@holdenweb can you explain why it's a blow? Aren't the changes not released yet?
I'm missing the context
As in "another blow is struck in the fight to retain backwards compatibility." Ah, the ambiguities of human language ...
Ohhh OK, thanks
@Kevin Maybe in the C code the method does an identity check with self. That would be worth doing, as the cost is typically amortised across many cycles of string comparison and it allows an immediate True return.
Maybe. I googled around for memcmp implementations, but I couldn't find one that seemed reputable
Except for what you said about it actually taking a long time. Ignore me.
12:09
Plenty of "look, I reimplemented memcmp for my CS 102 class", not very many "look, here is how the Linux kernel implements memcmp on core i7 processors"
For the record, the CS 102 submission does not do an identity check
I'd expect kernel programmers to be more alert to the potential for optimising the comparison between a thing and itself. But that's just my foolish optimism.
I also expect that, but I also expect that sometimes their 300 IQ analysis results in "actually, it's not worth doing, for reasons Kevin cannot possibly comprehend"
it's all obvious if you're Dutch
"If you cross-reference the L1 cache against the speculative multithreader, you'll see that the Coriolis effect causes a destructive guru meditation error, and the kernel has to restore itself from tape backup"
And Steve closes the tape archives early on alternating Thursdays so he can get ready for his LARP night, so we can't do identity checks then
12:29
@Kevin Precisely. I'm a firm believer in respecting the black box interface of sufficiently reliable services (though I'll sometimes take them apart out of interest). I long ago lost the arrogance of believing my intuition would beat the efforts of people who'd actually done lots of hard work on a problem.
@AndrasDeak But naturalisation doesn't work.
If I have a bad day, I'll console myself by saying "at least I didn't have to take apart a black box interface of sufficiently reliable services"
voluntarily taking apart a black box is fine of course
13:02
@Kevin string kind should mean the encoding here ā€“ i.e. whether they are the 1 byte, 2 byte, ... subset of unicode.
Sensible
In that case, they can have the CPU literally compare the memory content. Can't get faster than that.
13:20
@Kevin Exactly. It's the compulsion I object to: "If you want me to work you'll have to fix me!"
@MisterMiyagi There is no string kind; there is only string.
paulgraham.com/avg.html Is lisp as amazing as this article makes it seem? Did you guys use it? How is it compared to Python?
@Hakaishin It depends on what "flavor" we're talking about here tbh. There as many flavor of Lisp as there are star in the sky (I'm probably exaggerating, but not too far off)
the syntax may look the same, but most people won't make a clear, detailed comparison of the token, syntax, grammar etc and just paint them all with the same brush
for example, the most documented Lisp flavor would be Common Lisp.
If you know it, you technically should be fine learning other Scheme/Lisp stuff, but that's not always the case...
The syntax is probably fine even with the parentheses being overused, but that's probably a question of preferences.
@NordineLotfi preferences?
I followed a Lisp tutorial or two but my attention drifted before I got to the good bits
@Hakaishin yeah, sorry for the typo :) but you get what I mean
13:29
(print "Hello World") lol, gotta love me some NOISE
meh, I'm out
@Kevin same. For me it's also because there so many question I have but most won't get answered right away...and when I learn something, I really want to "know" what's going on, even if I don't know the internal, at the very least, to know what X give Y as result, instead of "trying and failing"
I don't get why every other language loves their ({;
probably because of C set a kind of "trend" I think
and people maybe had enough of the "english" like grammar that other ones used (eg: Fortran)
The cleaner your language looks, the harder it is to write the parser for it
13:32
Obviously, also the cleaner the language looks :) Any language where hallo world is not print("hello world") Is not a language I am bother in learning
@Kevin But I thought the idea of progress is to push as much work down the stack not keep it at the current level :)
Every language other than Lisp should just suck it up and write a better parser. But Lisp has the justification that the user needs to be able to define new syntactical elements for the language at runtime, and the more parentheses they have in the base syntax, the less painful it will be for the user
I don't know; I feel like most language have a very simple syntax for "printing" text like "hello world", and then, it just give users/learner the impression it's actually as easy as that, but it isn't most of the time
@Kevin does that mean you can define your own keywords at runtime?
More like there is no such thing as a keyword
at all?
13:34
@Kevin at least we got auto pairing for parentheses these days...imagine back in the day when you had to remember if you put the right parentheses at the end or start before testing something you made
(function_name args) is unambiguously parseable in O(N) time with 0 additional tokens of lookahead. function_name(args)... Not so much
Not sure how exactly it works, but it's not like you can introduce any new syntax. Everything is essentially just a function call. So adding a "keyword" is equivalent to defining a new function.
@Kevin then how does python do it?
@Aran-Fey that's an interesting way to understand this :o
@Hakaishin Probably it compromises on "unambiguous". There may be expressions that could theoretically compile to multiple different valid syntax trees, and Python picks one basically arbitrarily. And there may be expressions that are syntactically valid, but the parser incorrectly rejects them as invalid
13:39
@holdenweb The unicode type has three different internal representations, depending on the largest character ordinal. PEP 393 lists the three kinds as 1 byte (Latin-1), 2 byte (UCS-2) and 4 byte (UCS-4).
Or perhaps it refuses to compromise on ambiguity. It can check for these failure states, and use context clues from the surrounding source code to make the correct decision. But then they're compromising on "0 additional tokens of lookahead"
@Kevin I never quite got the point. If you insist on simple syntax to make it easy to define new syntax... isn't the new syntax then not automatically restricted to be just as simple? Otherwise, the advantage is gone pretty quickly.
@Kevin This sounds more plausible and totally acceptable for the reduced noise
@MisterMiyagi I'm guessing the designer's preferences come into play at some point, and their own view of "simple" probably isn't what we would all call that.
By making a design rigid along one axis, you gain additional flexibility along another axis
13:45
yeah
If they can't take care of that other axis, or decide not to, then their original vision (eg: "simple") isn't that anymore.
but then again, it's probably not that simple. But still, they could at least explain more their design reason when that happen...
@Hakaishin Yeah. All other things being equal, I'd prefer python-without-noise over python-with-noise. But if I had to choose between "python without noise" and "python with noise, and also with a suite of powerful syntax-redefining tools"... Not so cut and dry
@Kevin Ever tried MacroPy?
Nope
Ah, I heard of it too but never tried it. Although I did try MicroPy
there are surprisingly a decent amount of different fork and flavor of Python, especially for embedded devices/project.
@Kevin You should. MacroKS would be pretty sweet!
13:51
@Kevin could you make an example?
I have been meaning to explore the question of "can you construct a Turing complete system using only string replacement?". MacroKS could be one possible outcome of that.
@Kevin you can already do that though. sed and ed technically are Turing complete :) same for other "string" replacement dependent langs (most of them are esoteric langs though)
@Kevin Intuitively yes, not because I know things about string replacement, but because turing complete is a surprisingly low bar
@Hakaishin 75% serious example: If lambdas had curly brackets, you'd be able to put multiple statements in them.
13:54
@Kevin aren't lambdas with multiple statements called functions?
Not if it doesn't have lambda at the front ;-)
Unfortunately, I am essentially the Blub programmer that Paul Graham describes in his article, so I can't give a truly satisfying example of how NoisyPython could be more powerful than Python. Maybe if I had stuck with those Lisp tutorials for longer. Alas.
I could say "NoisyPython could implement call/cc" but I don't know if that's actually true. It would merely be a diversionary tactic so I could escape unnoticed while everyone confusedly reads that Wikipedia article four times over
@Kevin I wish all people I talk to would immediately understand, accept and incorporate into their language my pet peeve I have with what ever we are talking about. Like NoiseyPython is a good example. I wish everybody would call meat, dead animals when talking to me about veganism :)
Hmm, it's like I'm improving my conversational power by creating custom extensions to the syntax of the English language :-D
14:03
re unicode representations.. im now curious.. why did we create utf-16 and utf-32 instead of using utf-8 always?
@Kevin the smokebomb was very effective, I'm off to doing work again :D
@ParitoshSingh UTF-8 is variable size, so you cannot index it.
ah! got it, ty
For example in rust, you use UTF-8 strings when you want to stream things, but UTF-8 character lists for indexing/slicing.
It was the most unpleasant thing about the language for me. Python really knows how to set standards.
is it a bad thing i have no idea what that means?
oh. like there's two datatypes, character arrays, and strings?
14:09
I'm amused that en.wikipedia.org/wiki/UTF-32#Analysis is just three solid paragraphs explaining why UTF-32's principal advantage isn't worth the effort
section last edited by user "fixedWidthFormatH8er"
hmm, wondering how to know if a file has a newline at the end, So I thought of reading the very last char/byte like this:
with open("test.txt", "rb+", encoding='utf-8') as f:
    f.seek(-2, 2)
    # -1 or -2, may change depending on whitespace characters at end of the file
    var = f.read(1) # read one byte for a number
    f.seek(-1,1)
    print("last character:", str(var, 'utf-8'))
would this work for doing this or?
trying it but not sure if there a better way (the advantage here is that the whole file isn't read but just a single char/byte I think)
"may change depending on whitespace characters at the end"? I thought you wanted to read the last byte in the file?
@Aran-Fey yeah. was just trying stuff out since I wasn't sure on how seek would work here since I never used it
@ParitoshSingh There's "UTF-8 strings", which are just a sequence of bytes and the iterator knows how to interpret the UTF-8 size indicators (e.g. if the first bit is 0, its a 1byte/"ASCII" character). That's very compact but it can practically only be used for iteration.
with open(path, 'rb') as file:
    file.seek(-1, os.SEEK_END)
    last_char = file.read(1)
14:20
There's also "List of UTF-8 characters", where the List (actually Vector) type automatically adds padding so that each element is the same size. A 1 byte character would just get padded with 3 more bytes, for example.
@Aran-Fey Thank you, didn't know about os.SEEK_END :o
@Kevin "It is extremely rare[citation needed] that code wishes to find the Nth code point without earlier examining the code points 0 to Nā€“1." Laurel.
14:38
Whenever I see [citation needed] I kneel and touch the ground and say "... A battle occurred here"
15:08
okay, I think I'm going somewhere with this: gist.github.com/secemp9/ffa7e8eb7704dadc690e7732ec05505e
finally support binary files :D
(although it's kinda hacky)
Neat
15:30
also, didn't know you could do a function within a function in python...not sure what's the use of doing that, especially if it's within the same Class
to me, Class are what you should probably use the most when structuring all your functions. So I just don't understand why you would need/want to use a function inside a function inside of a class instead of two separate function inside a class
Decorators are a lot harder to write if you can't use functions within functions
A function inside a function is just a FunctionFactory. ¯\_(惄)_/¯
15:48
Classes are quite versatile and you can do a lot of things with them, but I wouldn't say you should use them for those things.
I see Python as a multi-paradigm language, so it can handle OOP-heavy designs, and OOP-light ones.
@MisterMiyagi that's a nice way to see it
@Kevin yeah, same tbh. I mostly said that because most codebase I seen that employed that "trick" weren't using decorators AFAIK
they were literally just using a main Class + sometimes would use a function within a function inside that same class
which is why I was kinda baffled that this was a thing, since I didn't see the point of doing that
I don't employ nested functions too much but I'll play devil's advocate and say that it's usually a good idea to use the tightest possible scope for your variables. In other words, if you never use the variable outside a function, then you should define that variable in that function.
@Kevin that's...actually a good reason to do that now that you mention it
I never thought of doing this myself for this specific reason, but I guess I'll think about it next time I run into that myself
The flipside of "choose tight scopes" is "write functions that are useful in multiple contexts". So there's some pressure to move functions to highly visible scopes, in case some other part of the code wants to use it
yeah, I see what you mean. I guess it would be harder to understand/debug/read if you use too many nested functions, even if it's well commented.
15:59
btw what is your code to comment ratio in locs? I would say about 1/500 in c++ and 1/100 in python
01:00 - 16:0016:00 - 22:00

« first day (3911 days earlier)      last day (1259 days later) »