the fact logging can tell you the function where it is being called from is a point in favour of breaking up functions into smaller ones. anyone have thoughts on long functions + commenting vs. short functions?
I have for instance this function that has three distinct parts that I don't think will ever be called separately
There is a mantra in XP that a comment is an apology for a missing refactoring. "Uncle" Bob Martin, for example, advocates very strongly for short functions (very short - shorter than you might think feasible, until you have some practice with it), and I have had great success with this technique.
A function is something that can be named, and a good name is executable documentation.
(well, an executable comment. most often these things are only part of a private API, at least initially)
@Peilonrayz people really expect too much of type annotations, IMO.
suppose a database table undergoes a set number of changes during a period of a year. is it common place to make a new table each time a change is made, and begin making new entries into this new table, instead of modifying the previously existing table?
@shintuku no, it's very much not common practice. You'll typically break tonnes of code. This is why people care about "database normalisation" to make the design extensible as possible from the start (knowing that things will change) and you can track changes to schema in much the same way as code with git using something like Alembic
@KarlKnechtel there are so many rebuttals against Clean Code... we had a similar debate about it in this room not long ago
@Arne It's probably worse than LPTHW. "Uncle Bob" Martin is a very prominent software engineer, associated with the Agile manifesto, and SOLID design principles. https://en.wikipedia.org/wiki/Robert_C._Martin Clean Code is pretty famous, even outside Java circles. But as that qntm critique points out, it's riddled with flaws & inconsistencies.
Yes, def now_do_the_next_step(self): self.foo = bar is just pointless indirection. The X in XP stands for extreme and unsurprisingly all sort of fundamentalist zeal is harmful, especially in Python.
Make your code readable.
@Aran-Fey does it help if you completely separate the data from the GUI with something like an MVC pattern, where there's a controller who's aware of both data and GUI?
Tbh I don't really understand that pattern, but I don't think so? As far as I can tell, I still have the same problem when it comes to implementing the View: How do I know that a Healer needs 1 input element and a Tank needs 2?
Basically the problem is that my code is generally designed for "static" access, like character = Healer(); character.mana = 5, but sometimes (like in the case of a GUI) you need "dynamic" access like for every playable class and for every stat in this class
My problem is that this is super specifically designed for the GUI and not at all how you'd usually expect it to be implemented. Usually you'd imagine something like character.mana = 5, right? If I hadn't known about the GUI in advance, I would've implemented it completely differently. That doesn't sit right with me. Am I doing something wrong here or do you really just have to know in advance?
character.stats['mana'] = 5 seems general enough
And doing that with an input-like-thing also makes sense. So I still don't get it I think.
Yeah, stats could be implemented as a mapping. I'm not sure how I'd make the classes iterable, though. Maybe something like class Class(Enum): HEALER = ['mana']?
Then I could do for cls in Class: for stat in cls.value: make_gui_element() in the GUI
I guess it doesn't really matter if it's abstract, as long as there's a shared parent class I can list all of the playable classes with BaseClass.__subclasses__()
A potential problem would be if there are "intermediate" classes, like if Priest and Paladin both inherit from Healer
Isn't there some kind of design/architecture/guideline that tells me how to translate my thoughts/goals (like "Healer is a playable class", or "Healer has the stat Mana", etc) into code so I don't have to plan all of this stuff in advance?
Or resort to metaprogramming with getattr/setattr/.__subclasses__()/...
@Peilonrayz I don't like the idea of a Mapping[CharacterClass, Tuple[Stat]] because it kind of "fragments" the code. Whenever I add a new CharacterClass, I have to remember to update this dict
I guess you could do something like class Healer(Class[Literal['mana']]), but then you have to list all of the stats in one place. It wouldn't let me express a concept of "Priest and Paladin are both Healers, so they both have mana)
This is why I always find it funny when beginners try to write a game
@shintuku FWIW, logging's smaller cousin warning ships with a parameter to say how many levels up the stack it should look for the function name. Having too localized information isn't helpful either.
@Aran-Fey Can you invert the relation? So instead of the UI mucking in the character data, the character data requests values from the UI.
Right, but I'd have to know in advance, otherwise I'd just write self.mana = 0 and then there wouldn't be an obvious/easy way to loop over the stats. So how can I avoid the need to plan ahead?
I think it would be fair to say that self.mana = 0 is just... wrong. I have expressed "Healer has mana", but I have failed to express that "characters have stats" and "mana is a stat". So really it should be something like self.stats.mana = 0 instead
That's what I'm looking for, simple rules for how I should translate my mental model/goals into code
I didn't realise the extent to which I could be patronised until getting an hour into this onboarding from HR. I'd rather be eating my own face right now :'(
At least I get to choose the colour of my post-it notes on the jamboard. They haven't yet completely crushed my independence. They chose my spirit animal as my icon, though
It's just stupid happy-clappy HR activities. We had an exercise where we had to divvy up our group into roles in making a pizza. Then a 10 minute discussion afterwards about "and what do you think would have happened if you tried to assign people to these roles without getting to know each other first?" and then to everyone's response "yeah... yeah, that's a really good point, isn't it? How could we know without asking first?"
I couldn't work it out on account of doing the absolute minimum to get beyond the current hell and move on to the next. All I know is that she apologised beforehand if I was unhappy with it
The closest I came to caring was that my team assigned me an inappropriate role. Sourcing the ingredients was entirely in my wheelhouse given a career in logistics, but apparently I was better at preparing the ingredients. Then I realised that means I would have to participate to disagree and my life might be better spent rambling about the whole thing here
I don't know whether I should feel bad that there are 17 other people in this intro that actually take it seriously. Maybe I'm the weirdo
Then again, their company mission is "be no. 2 in the market" as they don't think they can catch number 1. I actually did contracting for no. 1 and by the second week I was in the War Room with a Director threatening to sack everyone if the project didn't work. I wasn't discussing how to make pizza. So perhaps no. 2 is a valid goal
(Although I was a contractor there, so pleasantries are hardly extended)
Well, now that fun is over, I need to put together a presentation about packaging python projects for tomorrow. I'm thinking the old-style like I used here, the newer pyproject.toml approach and maybe touch on poetry. That should be enough scope for people that haven't packaged anything in the past or do I need more?
I think you'd find the critique that Arne posted an interesting read. Throughout the book, he consistently breaks his own rules and some of the code is borderline unintelligible. Perhaps your interpretation of his general thesis works well, but his own implementation is actually... lacking
I mean, I constantly feel like I did things wrong when I look at my old code; and many refactorings in Fowler's catalog are intentionally reversible because which way is better will be context dependent or even a matter of style
oh man! work's been crazy. I've lost track of time, so here's a brief, cumulative update: Grandparents were ill in January - I took them to India. Grandpa passed away in May. Since i returned from India (mid Feb), I've been dealing with their affairs here (while also keeping up at work). Huge stressors. Took small pockets of mental health time. Looking to move apartments now. crashing at a friend's place while I figure things out
Went to Ireland for a beat and played my harmonica with a busker dressed a leprechaun. Attrition on the team, so more work on my plate now. Projects ramping up, so even more work upcoming. Building a few new systems at work... so lots of planning, coordination, and sequestering/prioritization
Well that definitely sounds busy, I'm sorry for your loss. It's good that you have a friend's house to stay at to give you some time to take stock of your situation
I did some contracting which ended, so I got a few months to pretend that I don't have to work again. I finally managed to make it to Japan with my best friend, which ticked off a major bucket list item, now I'm landed back on Earth back in the joys of corporate work
No toys, no. I went a bit mad in Kyoto and bought a woodblock print from 1863, but it does look good framed. We also went to the Anime museum and got a portrait of myself, my friend and someone we befriended over there which is ace
@DimitrisPapageorgiou This is all part of the fun. Wait until you get to the end and want to attach a domain to your IP through the DNS. I've done it once and did it right the first time... but you have to wait 24 hours to find out if each iteration works and I have no idea if I went back to do it again whether I'd remember anything about it
Welp, I definitely don't know how I did it since apparently I never did. Great.
I expect that I knew more than enough before this session to do my job. I want the problem, the desired goal and then yam-off while I go fix that. Not someone coming up with every way of saying "that's great. Well done you" to every suggestion in a group exercise about making pizza
Fun fact; the only module in Uni that I nearly failed was "Professional Skills". I got 42%.
Though I did only attend half a lecture for the whole semester and I had the opportunity to leave that one. I also ditched their broken software for making P&ID diagrams and did it in Microsoft paint. Kinda deserved my score. But I had to leave before I boiled over
No worries. We (the room owners) have been a bit lax in enforcing the policy so I'm trying to find the easiest way to transition back to enforcing the rule
Can you be more clear on what you think is wrong with the output?
The result for gradient descent i.e. manual implementation result does not match with the result obtained by standard Scikit-Learn's LinearRegression library for coefficient.