« first day (4025 days earlier)      last day (909 days later) » 
09:00 - 13:0013:00 - 21:00

1:00 PM
@CodyGray The root problem is that types are mutable, so inferring types does not buy anything.
 
not to mention, because python is rather "open" in nature, things could still be patched
 
It doesn't know what the type of a is at the time it executes an expression involving a?
 
exactly, what miyagi said
 
yup
 
@CodyGray yep. even simple OPs in python go through the whole data model chain
 
1:01 PM
I bet one could make assumptions about c-defined standard library types. The question is whether the python core devs find that to be a useful effort considering impact on runtime.
 
ie. take the "object" on the left. ask if it has a mul. if it doesnt, ask this to the object on the right. etc etc
 
Having to determine that 0 is an int and a is an int and then figuring out applicable optimizations would probably lose you more than what you'd win. We're still talking python. a**4 is not your bottleneck.
In any case, I don't think there are runtime optimizations. Code is compiled to bytecode during compilaton, and then the bytecode is executed.
but I might be wrong about this
 
For the record, PyPy does type inference for built-in types since these are immutable. There are also some changes for CPython 3.11 (?) that allow for hot paths for built-in types. Those types are the minority, though.
 
I guess it's difficult to understand how this type information would not be known at the time that that particular line of code is being executed, which makes this trivial.
 
it's my (although limited) understanding that if a language is dynamic, and supports monkey patching, the best you can do is JIT
 
1:05 PM
Yeah, that's probably true
 
@ParitoshSingh Cody is talking about runtime
so that's within JIT
 
But yes, I mean JIT compilation, that's where the type information would be available.
 
@CodyGray it's known at exactly the time an expression is executed. Doesn't say anything about immediately before or after, though.
Because any expression can also change the type of anything. It's... Not Nice.
 
too many wobbly bits
 
Hmm
Awful.
 
1:07 PM
But you can do JIT with some limitations, as we said. There are libraries and interpreters that do this. But CPython doesn't do this on its own.
 
the power of being able to tinker with stuff comes at the price that the compiler cannot be sure what happens when
 
You can tinker with stuff in plenty of other languages and environments, though, so you can't act like that's a distinct Python strength.
 
I heard there's lots of tinkering potential in JS :P
 
On a more fundamental level, Python's types are first class. Such a type system is provably unsound.
 
@CodyGray I don't think any of us did?
 
1:09 PM
@CodyGray nope, not going to either. its a strength, but not unique to python. and honestly it's the kind of strength you dont actually need for 90% of the use cases
 
@MisterMiyagi where's my monocle...
 
@CodyGray The simple truth to that is that no one bothered to pour as much money at Python as on Javascript. :/
 
@roganjosh That's how I interpreted Paritosh's statement. Maybe I misunderstood.
 
@MisterMiyagi this ultimately is very true.
@CodyGray yeah, i didnt mean to claim this made python special or anything.
 
@MisterMiyagi Yeah, I guess that's the thing. I mean, a JS runtime can do this trivially.
 
1:10 PM
@AndrasDeak It's in your cdr pocket.
 
I'm sure Cody thinks Python is special
 
So it's not like I'm just approaching this from the perspective of a static AOT compiled language, as Andras is implying, although I freely admit that I think those are far superior in nearly every way.
 
a JS runtime is a monster of an optimizer. it is basically trying to guess and reguess based on the hot paths.
 
Yes, that's how JIT optimization generally works
 
and it's constantly trying to optimize and check, discarding optimizations if they break on the go.
 
1:11 PM
It must, that's literally the only advantage that JIT optimization has over AOT optimization.
 
Hey guys what's going on tod--
[I back slowly out of the room]
 
Hai Kevin :D
come join us, we have cookies, want one?
 
[I forward slowly into the room]
 
@MisterMiyagi Sorry, what exactly does this mean?
 
but yeah, re Cody, it still means that on the very first execution, you'd still generate the code as usual.
its only because theres a hot path that subsequent executions got optimized. which im sure you can do in python too if you want to. i half suspect if pypy does it or not.
 
1:14 PM
Maybe it's JS' haphazard origins, but it strikes me as the kind of language that can do some very cool things, which happen to fail spectacularly in 0.001% of cases because you tripped over the hole where they stuffed all their pigeons
 
tbh i dont know why JS manages to stay performant while validaying its machine code as it goes
 
"We solved the halting problem! For programs that don't try anything stupid"
 
Nah, even if the JIT optimization fails, you just fall back to naive execution. There's minimal risk.
 
@CodyGray the JIT python libraries compile once based on inputs, usually. Pypy recompiles I think.
 
yeah, you dont fail because of the optimization, just because js is... well.. js.
i hear you dont like semicolons. well, we do-n't, and couldn't make up our mind.
 
1:16 PM
Oh yeah, JS is awful for a zillion reasons
Anyway, just... wow. No wonder software is so bloated and performance is so bad even on ridiculously powerful hardware. :-\
 
ah.. now that's a fun topic of discussion
we really didnt get performance matching our hardware level increases, because we chose to fill it with abstractions, essentially. What's curious is how much of that was deliberate, and how much just accidental.
 
I don't agree with that... I work with abstractions all day long. But I use a system that makes those abstractions essentially free.
 
Any programmer not working with machine code has implicitly chosen abstraction over performance
 
This is not true. Because even a reasonably proficient machine code programmer cannot generate code that is anywhere near as efficient as a modern optimizing compiler.
 
@CodyGray let's put it this way: this was an issue recognized in hindsight. free abstractions were not always a priority, and so a lot of abstractions that exist arent like this
I've been listening to a guy (he does like ranting a lot, so beware) but it's still fun to listen to his perspective on it. (had to google the name, oops) Jonathan Blow
 
1:23 PM
Actually, I take it back. Machine code is an abstraction too. If you're not calculating the interaction of electromagnetic fields, then you're not a True Coder ;-)
 
haha, im sure you could pull that off Kevin, but that would mean no coding for me :P
 
Ideally you'd be calculating the vibrations of 16-dimensional superstrings that cause electromagnetism, but the theoretical guys are still working on that
 
But yeah, while Jonathan Blow takes an extreme stance on why modern programs aren't as good as they should be, i think there's some wisdom in his annoyance with the state of things. His core argument is that we could "get away" with more inefficient code as hardware became more powerful...and so we did.
 
Yeah, that's true
I agree with that. But I also put a lot of blame on programmer sloppiness.
 
How many programmers looked at their code at 4:00 PM on a Friday afternoon and thought, "maybe 1000 times slower than the theoretical optimum is good enough"
 
1:28 PM
Sure, though unfortunately it's not like sloppiness was intentional. deadlines, time pressures, inexperience. a lot of our modern infrastructure is built on a pile of rock and rubble, stuck together with duct tape.
 
I see it more as practicing good "hygiene". You develop and follow best practices to ensure that you aren't writing pathologically inefficient code for no reason. And because you're following those established practices all the time, you aren't reducing your productivity.
 
essentially, those practices were learnt "the hard way", because they simply didnt exist at some point
 
They did... they were forgotten, and then had to be reinvented.
 
Okay, sure. let's put it this way then: IF someone were to expect that one must be perfect about best practices before being allowed to code, we wouldn't have any new coders come up
best practices existing wont make them universal, ultimately each new person still has to start fresh, and there's just a lot to take in
 
I don't find that very convincing
At best, it increases the barrier to entry, but that's not entirely a bad thing. And, in reality, I am not sure it does, because once patterns and practices become established, they should just be learned along with everything else, like the syntax.
 
1:31 PM
Yeah, people are all about learning best practices
 
@CodyGray Python's classes are regular objects, as instances of metaclasses. That allows to create types that are a logical contradiction, and that allows anything to happen. So that int that the type system inferred for a variable might actually be a rabbit. That's not an issue with runtime types, since it is just a regular runtime error like all the others then.
 
@CodyGray and they are. but we learn by doing. and probably commit a fair share of crimes along the way
 
It's Giraud's Paradox or some such. I recommend to only look at Russell's Paradox and handwave the rest from there on.
 
@AndrasDeak I sure see a lot of questions about it!
 
Im sure everyone, even in this room, can look back at some of their old codes and cringe
But even as you cringe, it's important to recognize it was the result of someone inexperienced still trying their best
 
1:33 PM
I wrote Python programs for like five years before I learned the whole syntax. If it also took me that long to learn all the patterns and best practices, I probably wrote a lot of junk before the window of opportunity closed.
 
@ParitoshSingh Heck no, I just did what worked
 
@CodyGray In Python? In most cases their aim is completely off and they think that everything should be crammed into a 1-liner to be efficient
 
Ultimately, that was the real aim. it wasnt to write "the best" code. it was to write something that solved the problem
 
@ParitoshSingh And this is the issue. I termed it "laziness" above.
 
@CodyGray is it lazy though?
 
1:35 PM
Yes?
 
Sounds like rational cost effectiveness to me, if it's 4 PM on a Friday.
 
ok. i disagree, but probably wont be able to convince you otherwise then
 
Impatience
 
@CodyGray it's like putting the blame on the individual for not knowing what they dont know
thats my best effort to sum up the issue i see
 
Yeah, there are institutional issues, too
Obviously you can't just blame the individual
 
1:39 PM
@MisterMiyagi yeah... if you're use to something like C++ then the difference between __new__ and __init__ does make you think :)
 
I like to think that coding is still a young craft, compared to carpentry or glassblowing or advertising. I wonder how long after the invention of gunpowder it took them to discover the best ways to not blow up your laboratory.
 
Laboratories still blow up
 
Hey roganjosh. Is this code better to prevent SQL injection:
while True:
    try:
        inp = int(input("Please type the roll number of the student whose marks you would like to see: "))
    except ValueError:
        print("Please type a valid input.")
        continue
    else:
        break

if inp not in roll_no:
    print("There is no such roll number.")
elif inp in roll_no:
    name_of_inp = stu_df.loc[inp,"Student name"]

    print()
    print(name_of_inp)

    q1 = "SELECT * FROM %s;"%name_of_inp
    df0 = pd.read_sql(q1, con)
    print(df0)
 
Sometimes due to laziness and institutional issues, no doubt. </75% serious>
 
Or lack of regulation. In the Chem Eng business, it can be pretty awful for no good reason
@RandomPerson No because q1 = "SELECT * FROM %s;"%name_of_inp still exists. I don't know what relevant changes I'm supposed to review
I was very specific on the line of code that caused the issue, what the issue name was, and what the resolution name was
 
1:43 PM
This doesn't have anything to do with sql injection, but elif inp in roll_no: can be changed to just else:
 
@roganjosh %name_of_inp depends on inp
 
99.999999999% of the time, an elif condition should not have the exact logical complement of its preceding if condition
 
@RandomPerson ... I know
 
@Kevin hmm.. I feel keeping the possible consequences narrow is better as else is quite broad..
 
@RandomPerson if youre making an a string yourself (using sting formatting), instead of letting the sql library do it, you're not using a parameterized query.
 
1:46 PM
@Kevin ugh got kevin'd
 
From my point of view, else has fewer possible consequences than elif. A code block with an if and elif clause can have three possible execution paths: one where the if passes, one where the elif passes, and one where neither passes. A block with an if and else clause has two possible execution paths. That's 33% better :-)
 
@roganjosh Initially, this was how I took input:
inp = int(input("Please type the roll number of the student whose marks you would like to see: "))
I changed it to:
while True:
    try:
        inp = int(input("Please type the roll number of the student whose marks you would like to see: "))
    except ValueError:
        print("Please type a valid input.")
        continue
    else:
        break
 
Would it convince you any if I said that else: is the community accepted best practice?
 
None of which has anything to do with SQL best practices
 
though i suppose its worth noting that you probably cant parameterize table names, can you
 
1:47 PM
@RandomPerson It doesn't affect SQL Injection
 
@ParitoshSingh No, you can't, but you can whitelist
 
@ParitoshSingh Only field names as far as I know
 
@Kevin oh.. I didn't know that. why so?
 
Because your elif condition is exactly opposite of if...
 
The community chooses its practices in mysterious ways :-)
 
1:49 PM
@RandomPerson elif leaves room for another branch. if you really care to spell out the condition of an else block, do it in a comment. win win
 
@ParitoshSingh To be fair, I guess I may be setting unreasonable goals. My attention level is not at its highest for this problem as it's rumbling on
 
logically, if your if covers some* possibilities, and "everything else" is going in a second branch, thats' an else branch, not an elif
 
@Kevin oh... ok.
@ParitoshSingh ok..
@ParitoshSingh can you let me know how SQL can do it?
 
Use the params argument of pd.read_sql
And if you end up using something other than read_sql to talk to the DB, then whatever function you choose will probably also have a params argument. It's very widespread.
 
Ah I wonder, what placeholder to be used here
 
1:54 PM
Can you give me a link which has more information about params?
 
That documentation says "Check your database driver documentation". What database driver are you using?
 
@RandomPerson He did if you ready the link above...
 
ah. as i said earlier, this might be an unfortunate example, because i think table names had the limitation of being not being suitable for parameterization.
 
@ParitoshSingh I disagree that's a "win win". Now, someone has to maintain the comment, it could easily get out of sync with the code, etc. If anything, make it an assertion.
 
@Random do you have separate tables per student as that seems to be implied by the code...
 
1:56 PM
@Kevin I have no clue. what is a database driver? I am using MySQL
 
@CodyGray hm. in that case i'd probably rather have nothing compared to an assertion. the intent was to clarify what logics entered the else branch
 
It seems best to query your database and get list of all the tables and check if the input is within the table, then proceed.
 
@JonClements yup. one table for each student.
 
@ParitoshSingh Why no love for assertions? That both documents the expected condition and verifies it.
 
Oh, I missed the fact that you're parameterizing the table name. Yeah, you almost never need to do that.
If your school student population doubles and this means you have to add more tables to your DB, then you have a problem with your design
 
1:58 PM
 
Are you sure you dont want a table for each class instead..?
 
@Kevin lol.. I am doing this program for my project. BTW, what would be a better design?
 
Just have one table, Students, with a column name, a column roll_id, etc etc
 
@CodyGray i am... not sure. i think its because im happy to use an assert to verify stuff that needs verification, but in this case i never set out to need to verify this information anyways, the if else construct already did it for me
ie why assert when you're in the else branch of an if...when the if already ensured what the else branch would have
to me, thats like adding pointless code
 
@Kevin well.. storing marks of many students in different subjects for different exams in one table seems complex..
@Kevin So my code is fine?
 
2:00 PM
@RandomPerson Not really, you will have to use whitelisting
 
@ParitoshSingh Arguably, if you're using an assertion to verify stuff that needs verification, you're doing it wrong. :-) If it needs verification, that means it might fail, so you should be explicitly checking and handling it, not asserting it. Assertions are for things that logically must be true, which means this is a perfect case. As you said, the failure to execute the if branch guarantees that the else branch must match the logical negation.
 
@RandomPerson no. bobby tables will still absolutely ruin you
just, the vector of attack shifted to the name of the student..which..is really poetic
 
@RandomPerson Nope, as long as you're dynamically choosing table names in any way whatsoever, it's wrong :-)
@CoolCloud That doesn't address the core issue though
 
@RandomPerson Ok, so have one table for students, one table for subjects, and one table for exams. Three tables total, nice and clean
 
2:02 PM
@Kevin Which is...?
 
That the number of tables in your database should not routinely change
 
@Kevin I think you will get a better idea if I show you the data..
 
Oh that one. I was still caught up on Bobby tables having a feast
 
@CodyGray ah yep yep. okay, let me try that again.. i think if else is such a fundamental construct, that if im asserting that, im really putting no faith in the very basic building blocks of the language itself
 
MT1 stands for monthly test 1.
@Kevin so I should make it non-dynamic?
 
2:05 PM
Yeah.
 
@ParitoshSingh Yeah, that's true. Other than if you wanted it for documentation purposes (the same reason you were considering writing a comment). Otherwise, I agree, you almost certainly would never write it. (Although, as a programmer, it pays to be skeptical of everything. I often have assertions to guard against failures in some very basic building blocks. They have at least once failed. Guess how much easier the problem was to fix that way than the other way?)
 
yeah, when an assert fails, it really saves you hours of pain and suffering
 
@RandomPerson Or you could have 3 tables like Kevin said, linking each by student roll number or so
 
@ParitoshSingh what if one's a masochist? :p
 
@JonClements assert has you covered there too!
 
2:07 PM
Actually, the program which I am working on is student report card management. That's why I am using many tables.. gathering data of one student from different tables will be a hassle
 
after all, your first reaction on a failed assert is usually " okay, why the yam did you fail, i swear this should never happen"
 
I'm imagining a schema like:

Student
    int roll_id
    string name

Subject
    int subject_id
    string name

Exam
    int subject_id
    int roll_id
    int score
    int month
 
@JonClements Isn't that implied by "programmer"? :-p
 
@RandomPerson except it's not a hassle - having multiple tables is a hassle...
 
2:08 PM
@JonClements oh..
 
@Kevin Looks nice
 
I will try changing the data schema..
 
If you aren't too concerned about the database architecture, I don't think you need to use primary keys and foreign keys either.
 
Thanks for the advice people..
@CoolCloud hmm. ok.
 
@RandomPerson If you don't mind me asking, is it your final year project for IP ?
 
2:10 PM
@CoolCloud why would you want to drop these?
 
@CoolCloud kinda.. it's my term 1 project. I might be having a similar project for term 2. I see that you are from India (in your SO profile). So were you an IP student in the past?
 
@RandomPerson have a look at sqlshack.com/sql-multiple-joins-for-beginners-with-examples - it's got a 3 table design similar to what Kevin has suggested and shows you how to do a join... (it's focused on SQL Server - but the same principles apply to all RDMS...)
 
@JonClements thank you. I have to learn a lot about JOIN...
 
@roganjosh Meh I just assumed they don't have to link the tables with each other in this case
@RandomPerson yep
 
Then if you want to find the score of all second monthly exams of any student named Alice in any Maths class, you can do select exam.scores from Exams exam where student.name = 'Alice' and subject.name = 'Maths' and exam.month = 2 LEFT JOIN Students student on student.roll_id = exam.roll_id LEFT JOIN Subjects subject on subject.subject_id = exam.subject_id
 
2:13 PM
@CoolCloud Of course they do, and there's no good reason not to have them linked
 
@CoolCloud cool. So you learnt Java in school? or Python?
 
(Not guaranteed to be the most efficient or beautiful approach, because I refuse to engage my full sql powers on the weekend)
 
what does IP stand for?
 
Informatics Practices (it's a subject in high school in India)
 
@RandomPerson Python
 
2:14 PM
i see
 
@roganjosh Hmmm I see, my bad then
 
If you're thinking "wow all of these joins look like a pain in the butt", that's why ORMs were invented :-) Then you can do something like exams = ExamTable.select(lambda exam: exam.month == 2 and exam.student.name == "Alice" and exam.subject.name == "Math")
 
and then 2 years later "these ORMs were a pain in the butt, what did i get myself into" :P
 
@Kevin ok..
 
select student.name as student_name, subject.name as subject_name, exam.* from student join exam on roll_id join subject on subject_id where roll_id = <whatever your input was>.... (or something like that - spinning a few plates at the moment...)
 
2:17 PM
@CoolCloud So I don't think you are much older than me..
 
I think Jon and I are on approximately the same page :thumbs_up:
 
@RandomPerson If it matters, just finished school this year.
 
@Kevin /me wags tail
 
I'm embarassed to admit that I never really know when to use join vs left join. I've been depending on ORMs for too long :-I
 
Python was introduced just 2-3 years ago in CBSE. I hope you are a CBSE student..
@CoolCloud oh.. cool.
 
2:19 PM
@RandomPerson Yea they were previously teaching Java for some odd reason
 
12k rep in a year and half, that's amazing CoolCloud
@CoolCloud why is it odd? Java is still widely used right?
 
@Kevin What's the table that you don't want null values from? Left join onto that
You can, of course, have records that contain NULL, but it gives you a concept of what the primary table should be
 
@Kevin join is short for "inner" join... so joining two tables... you only get a result set of actual matches between both... if you left join... then you get all rows on the left hand table but with NULLs for the columns from the right where it didn't match...
 
@RandomPerson I don't know, have seen many programmers in discord disregard Java in the past.
 
Let's see, I'm selecting exam.score from Exams, and I don't want that to be NULL. And I don't care about exams taken by null students or taken in null subjects, so... left join all the things?
 
2:21 PM
@CoolCloud oh.. ok.
 
Well, I think Students is the thing you don't want to be NULL, since (presumably) every student will have a name
 
@RandomPerson ah well thanks, just got into python and tkinter at that time :p
 
@CoolCloud we can use it and bash on it at the same time :P after all, people complain about the things they use most
 
Yea people are weird :p
 
Not every student will have done an exam, but you'd expect that at least their name would be registered
 
2:23 PM
@ParitoshSingh You must think I use Python then :-p
 
Our newest student, [the sound of one second of comfortable silence], technically has no name, but we just use a string of length zero for him
 
@CodyGray haha.
 
@CoolCloud oh.. ok. I am glad to see a fellow Indian student in SE/SO.. it almost feels like I am the only student in the SE community I participate in.
 
Pretty sure there are a lot of Indian students here on SO!
 
why tkinter? is it part of the sullabus?
 
2:24 PM
@RandomPerson Yep pretty sure there are lots, just don't seem to be revealing at first.
 
@CodyGray cool.. I don't participate much in SO. I meant high school students specifically.
 
@RandomPerson Nop, just wanted to make GUI for yearly project
 
@roganjosh I was trying to decide how to handle students that missed an exam. My initial instinct is to just not have a row for that in the Exams table, although I could perhaps be persuaded to put one in with a score of null.
 
@CoolCloud oh.. ok.
@CoolCloud oh.. ok. I hope you got 20/20 for the IP internals..
 
@Kevin missed an exam? In which case you'd have fake grades or it nulled out... or you treat the exams as "exams taken" and just don't have it... depends....
 
2:26 PM
@Kevin It's only really a heuristic for deciding the base table. But I'd assume that the complete set I really wanted was the student names vs. (say) a disembodied exam result
 
@RandomPerson Meh I wouldn't stress over it much, IP is an easy subject compared to CS
 
@JonClements Exactly what I was thinking
 
@CoolCloud hmm.. I felt that CS was too much theoretical.. and IP students learnt SQL in 11th instead of 12th like CS students.. so IDK..
 
@roganjosh so you'd have the _id's in the exam table as actual proper foreign keys... so you can't have anything in that that without it properly in the other two tables...
 
Yup. I was trying to add intuition to the LEFT JOIN vs. JOIN thinking
 
2:30 PM
@RandomPerson IP is perfect if you are favoring for Data Science
 
ORMs add a lot of overhead too, so I think it's important to think about this purely in SQL terms
 
@CoolCloud oh.. ok.
 
I think, more formally, you'd LEFT JOIN on the table that contains the set that you want to be complete
In this case, it wouldn't make sense to have a score with no associated name (other than, perhaps, for calculating a mean), but it would make sense to have a name with no exam score because you have a complete roster of pupils, and not all of them would have taken the exam
 
@Kevin can the subject_id be VARCHAR as they start with 0. Example: i.stack.imgur.com/OowyV.png
 
If every subject has a unique id, sure
 
2:38 PM
yup. every subject has a unique id.
@Kevin so I have to go ahead with a composite primary key I guess for the Exam (subject_id, roll_id, month) table..
 
Is there a nicer way to call a parent setter than this?
class Child(Parent):
    @Parent.foo.setter
    def foo(self, foo):
        super(type(self), __class__).foo.fset(self, foo)
        print('foo was set to', foo)
 
Lazy solution: use an auto-generated blind key for Exams, and don't bother enforcing uniqueness on student-subject-month combinations. "Alice has two math scores for January? That's because one was a retake"
 
But then how do you know which score was for the retake?
 
@Kevin nah.. no re-tests are allowed.
 
@CodyGray Proposal: add a timestamp column.
Now, how to enforce uniqueness on student-subject-month-timestamp combinations...
 
2:50 PM
oh my god.. that will make things even more complex..
 
Then you get the issue of time-traveling student exam takers
 
😂😂
 
Ideally, adding an additional column to a table will only add complexity to the parts of your program that wanted the new information anyway
 
And would the timestamp be the time of taking the exam, of scoring it, or of inputting the score?
I hesitate to imagine the next proposal ;-)
 
Cody Gray, please, no... more column proposals = more complexity in code..
 
2:51 PM
It's the algebraic mean of all three times
The problem hasn't changed in complexity, just our understanding of it. That's a good thing :-)
Extra good if you're getting paid by the hour
 
Or even by the line
 
@Kevin If you're going that far - you might as well go the route of having an ExamSchedule table which joins to the types of Exams and then link the Results against the schedule... that way you've also got a diary table handy for other bits :p
 
If we keep going like this, this homework question is going to be a spin-out company with a commercial UI :P
 
as long as we get shares from it? :p
 
I mean, I've been at this for quite a while, so I think I'll take a miserly 51%. That's pretty reasonable, I think
 
3:03 PM
Especially when combined with that $1k/hr consulting fee
 
Exactly! I've done myself a disservice here because I'm just that kinda guy
 
C.M.O.T. roganjosh
 
3:31 PM
hey guys!
anyone knows how can I get a text under a word in regex?
 
Please give an example
 
like: A B
" c d"
how do I get d without getting c
 
I'm still not sure I understand the goal, but how about:
>>> s = " c d"
>>> s.split(" ")[-1]
'd'
 
no the c and d are gonna be changed I'm not sure what they are so that's why I'm using regex, only thing I know is A and B I just want to get the text under it
thanks tho
 
Kevin's code doesnt rely on the fact that it's c and d.
 
3:39 PM
Right :-)
>>> s = " x y"
>>> s.split(" ")[-1]
'y'
 
oh thanks gotta try it now
thanks it worked!
 
Nice :-)
 
3:58 PM
@roganjosh 😂
 
I hate writing libraries when async objects that are only designed as context managers are involved... code be like:
async def _create_connection(self):
    self._session_ctx = aiohttp.ClientSession()
    self._session = await self._session_ctx.__aenter__()
    self._response = await self._session.get(self.url)

async def _close_connection(self):
    self._response.close()
    await self._session_ctx.__aexit__(None, None, None)
 
Save some Nones for the rest of us
 
I only used one!
 
I count 3?
 
They're all the same one though :P
 
4:12 PM
Ah the singleton None, or Nongleton
 
4:39 PM
laurel, well played
 
5:00 PM
Hello fellas!
This is how I'm currently storing/managing my initialized objects. Is it the correct approach? I'm kinda new to using classes.
myObjects = {}

class MyClass():
	unique_index = 1

	def __init__(self):
		self.name = 'object ' + str(MyClass.unique_index)
		MyClass.unique_index += 1
		myObjects[self.name] = self

obj = MyClass()
 
That's fine, but the idea of having a global index of all class instances is questionable. It's something beginners do all the time, and pros almost never
 
awesome @Aran-Fey! I'm using unique_index exclusively for naming purposes: the algorithm outputs some of those instantiated objects as a result, and I'm just making sure I won't have duplicate names.
 
The question is not why you're using a unique index. The question is why you need to keep tabs on every instance of your class.
 
Yeah, I could've worded that better
 
it's clear if you know what you meant... :P
 
5:14 PM
@Aran-Fey I assume it's a good reason, but what is the reason you don't use them as context managers?
 
Abstractions. I have an abstract base class that requires a _create_connection and _close_connection method
 
Yeah as you know I'm a novice programmer, and just recently I had to refactor this gigantic of algorithm of mine to use classes because keeping tab of data was getting very messy and error prone. It's not SOLID at all, and I still have this gigantic class with 31 methods with a bunch of responsabilities. I've been reading some blogs about how to proceed in separating this class, but it's hard to separate the responsabilities: you have shared functions and data for some of them.
Even though it's nowhere near perfect, it's much better than before: from 3600 lines to 2800!, and data flow/debug is much easier now :D
I'd wish I had the experience/knowledge to do perfect abstractions, but it's just not my current reality, particularly for such a complex algorithms with a lot of different branches of execution and wide variety of input :P
 
> I'd wish I had the experience/knowledge to do perfect abstractions, but it's just not my current reality
That's everyone's reality all the time, until they die
 
5:31 PM
Yeah but not much novices choose to start their programming life with a such a difficult project like I did, I'd suppose.
 
If you get good enough you might end up removing all those classes from your code...
 
Oh, many beginners choose ridiculously difficult first projects. But you have the disadvantage that you actually have to finish yours :D
 
yeah I started thinking functions would suffice, but it got really messy eventually. I'm pretty sure a pro would use classes for this case.
@Aran-Fey true lol
it's also hard for me because of my mindset: I started this thinking I would need only to program a simple mvp. 16 months later and it's gigantic and I had to learn a ton of new things lmao
but I don't intend to become a pro in programming. I'm a business guy
 
sounds a bit late for that
 
people around me are calling me a programmer already :P
but god I hate having to get so deeply focused and for so long. it's really harsh on me
I can't just sit, fix a few issues, read the news, get back to it, etc... When I sit down to work, I have to be here for at least 6h, and 100% focused, or I will do great mistakes. I know this is not the reality for a lot of programmers, but for such a complex project, being done by only 1 person, it's the only way.
sometimes I'm just unable: I'll just don't work for 3 or 4 days, and after that I'll work 14 to 16 hours a day to catchup
do all of you go through that, btw, in some manner, or it's just me?
 
5:38 PM
There are probably as many ways as people. Some focus like that, some work on and off. Everybody makes mistakes, the real skills are debugging and foresight.
It helps if you learn to write tests, because then if you find a bug you can write a new test that will ensure it doesn't come back. And if you have working code you want to refactor, a detailed test suite can make that feasible without fear of subtly breaking everything.
 
It's easier if you separate the classes and functions to do one thing only, otherwise it gets too complex
 
Problem with this current project is that it's double-complex, because what I'm doing is implementing a scientific model developed by my partner, which is very complex, but it has also changed a lot through time: a lot changed, and a lot got added. So if I write unit tests and everything, like I'd like, the next week he could be asking me to change a single detail and so I'd have to do a lot of rework. I hope he's done with that now, ffs.
@SurpriseDog I have seen a lot of videos and blog posts about refactoring, but almost all of them were regarding code logic that's nowhere near the complexity of my model, most being web stuff or some simple POS system.
Also, I've seen a video by Arjan yesterday about SOLID principles and it REALLY sounds to me like he's making a greater mess after all that refactoring than before. The way I see it, these principles simply don't apply to projects like mine where the code is not public, and will never be, and also because it's experimental: you HAVE to make changes on your way. True innovation is always experimental.
 
@lupus I'm just learning myself. The most I've done is a 3k line project that so far 0 people on github seem interested in
I just try to make pylint happy with my code
 
@lupus I have to agree, Arjan's tutorials are in a weird spot where you kind of get the impression that he knows what he's doing, but at the same time he really has no idea what he's doing. I watched his video on the factory pattern recently, and it's a prime example of overengineering and using the wrong tool for the job
And yes, design patterns are overrated
 
5:55 PM
@Aran-Fey nice to know those are your impressions. do you think I should try other contents about SOLID regarding this project of mine, or you think I'm right in saying it doesn't sound very useful (not even considering if it's doable because of time constraints)
@SurpriseDog didn't even know about pylint gonna take a look at it. What is your project?
 
@lupus Don't bother
 
@lupus It's complicated.
 
this is the video I was talking about btw: youtube.com/watch?v=pTB30aXS77U&t=560s
@Aran-Fey nice :)
 
6:48 PM
recbg
 
 
1 hour later…
8:03 PM
You guys know that feeling when you wrote a new piece of code that you're excited to use, but you really really shouldn't because it's responsible for downloading/moving/copying data and it would be really really really bad if it doesn't work 100% correctly?
 
no :P
fire up a docker container to play with in
I have lost results due to hastily issued broken shell commands though... but that is kind of the opposite of "new piece of code that you're excited to use"
 
Yeah, that's more of a "new piece of gibberish that you wish you didn't have to touch" kinda thing
 
straight from the poop mill
 
8:26 PM
In other news, I still haven't gotten into the habit of making micro-commits. I have months worth of changes, and the only reason why I'm committing now is because I'm likely gonna break something. My commit messages refer to the future instead of the past, because "committing now before I break everything adding feature Y" is more descriptive than "I have no idea what changes I made over the last 8 months"
 
git diff :P
and if you can retroactively identify groups of changes you can use git add -p to commit parts of changes in files
 
Eehhh, that seems like a lot of work for what's likely going to end up being a broken commit. I'm not confident anything will work if it's isolated
 
that would mean that you have identified groups wrong :P
 
09:00 - 13:0013:00 - 21:00

« first day (4025 days earlier)      last day (909 days later) »