Fix syntax in space-age mentoring notes on python track

I notice a bit of a weird syntax in an example in the mentoring notes for space-age. It looks like some auto-complete in an IDE went wrong :slight_smile: : Sign in to GitHub · GitHub

For example:

assert name: str.startswith("on_"), name: str

should read

assert name.startswith("on_"), name

Of course the same applies to the next line.

I’d also replace old-style new-style classes (inheriting from object), so that a quick copy-paste would not confuse users.

There’s an extra ) and a logic error in the same second example: round(self.years * PLANET_RATIOS[planet]), 2) → round(self.years / PLANET_RATIOS[planet], 2).

Personally, I’d also change the following:

  • I see no good reason, in the context of the exercise, to define years as a property
  • I’d rather move the computation from the __getattr__() method to a separate method, and return a partial() on that method. Arguably partial would add an extra concept to introduce so maybe using a lambda is still better, although if we already get into attribute resolution and descriptors and whatnot, partial() is benign.

So with all of the above applied, the second example would look something like:

class SpaceAge:

    def __init__(self, seconds):
        self.seconds = seconds

    def _age_on(self, planet: str) -> float:
        result: float = round(self.seconds / EARTH_SECONDS / PLANET_RATIOS[planet], 2)
        return result

    def __getattr__(self, name: str):
        assert name.startswith("on_"), name
        planet = name.removeprefix("on_")
        return partial(self._age_on, planet)

The last itemized list should not be a code block, either :slight_smile:

There are some other options for reducing the code duplication in this exercise, but I don’t think any of these is a valid improvement:

  • Using a setattr run in a top-level loop at import time poking in methods for each of the planets. Arguably faster since you don’t pay the price for lookups for each call, but it’s horrible.
  • Defining each on_* method with partialmethod. Not much of a saver in terms of DRY.

Given this is worth the time for review and so on, I’d be happy to create a PR. Please let me know if I should simply fix the syntax and logic, or implement one or more of the “extra” proposed changes.

Hey there @petrem!

I’d welcome a PR for the whole shebang. These notes haven’t (really) been looked at for a long long while (probably not since 2022 :scream: ) - so having you review and suggest changes is excellent.

Since these are mentor notes, they get PR’d to website-copy, and not the track. Please also note that we tend to NOT use typehints, since they’re optional and we don’t teach them.

If you are also feeling frisky, this exercise doesn’t have any published approaches. Since you are redoing the mentor notes, you are likely more than halfway to one or more approach write-ups, should you want to do them. Just let me know. :smile: I’d happily welcome some PRs on that front.

3 Likes

Thank you for the reply and info. I’ll have to read up on the approaches thing, but sure, in principle I’m game.

Yup, approaches are generally more helpful in my experience. All students completing an exercise have access to approaches. Students who request mentoring (a small sliver of the overall population) also need a mentor who uses the mentoring notes to benefit. Regular mentors may have their own notes for the exercise as well.

Here it is: Fix syntax and clean up mentoring notes for space-age in python track by petrem · Pull Request #2389 · exercism/website-copy · GitHub

2 Likes

When I was newer to mentoring or mentoring an exercise the first few times, I would read the mentoring notes. I haven’t looked at them in ages, though.

While the purpose and audience is slightly different, it might make sense at some point (or not?) to replace mentoring notes entirely with the other exercise Approaches/Articles docs.

1 Like

Yeah, Julia has a few mentoring notes in particular I recall that could easily be spun out as approaches. I’ll ping the maintainers after Thanksgiving and see if they’re interested. The original contributors should be in the Git history hopefully so they can get credited.

2 Likes

We’ll look into it. There has been some discussion about this sort of thing, but maybe we need to move it up the priorities (cc @depial).

The original authors are no longer active on Exercism, but we’ll take care of credit.

Issue 1049

3 Likes

@petrem – I got sidetracked by a nasty CSS grid problem on a project I’m working on, so your PR hasn’t been reviewed yet. My apologies! I will get to it as soon as I beat this issue I’m having into submission.

Thank you very much for opening a PR! :smile:

2 Likes

After looking into this in more detail, it turns out that we’re in better shape than we realized. Most of these already have Approaches on the Julia track. Of the 4 that don’t, one is just a near-empty stub file, and we’re thinking about how to edit the remaining 3 to make them more student-friendly.

That was off-topic for this thread, but to bring it back to Python: There are at least 4 different exercises that Bethany and I wrote approaches for in Python, now probably worth reworking for Julia. Things like matching-brackets and all-your-base have enough algorithmic complexity to transfer between languages, regardless of syntax details.

And even more on-topic: I was shocked to see how many typos survived into the final, merged Python approaches. That might be worth a cleanup PR, sometime when I’m more awake and @BethanyG is less stressed!

1 Like

I was just vaguely aware of approaches and articles until now.

I’d look into adding some contributions to approaches, and weeding out typos could be a good start for me.

My English, while not native, is relatively OK, but this would be a spell checker job anyway (see, I can rhyme!).

2 Likes

I continue to insist that typos are alive, and they breed and multiply in the dark when we’re not looking.

2 Likes

Reviewed, approved, and merged! :tada: Thank you for submitting this @petrem.

:thinking: Gotta go back and review my solution now. I think I did an attr creation in my __init__, so I am doing work every time an object is instantiated. oops. :wink: :laughing:

1 Like

Would welcome typo patrols from you and @colinleach - should either of you care to take that on! My spelling is terrible, and I am (purportedly) a native speaker. One wonders. :wink:

What I meant was NOT that someone with good English doesn’t do typos. I meant that I should be able to spot many such typos and make sense of the phrasing, and so on, so that it wouldn’t be inappropriate for me to take that on.

Book publishers have (or had) people just hunting for typos (ok, and grammar issues), so they are correcting after the most proficient language users out there… I wont be ashamad for my typoing sir!

Sorry @colinleach, while I agree typos can and do breed in the dark, someone has to have created the first two (per realm of existence), to start with. They aren’t lice, after all.

2 Likes

I … don’t know if that tracks. Abiogenesis feels like it applies to some of my writing. There are many things that I swear I spell-checked that end up with typos anyway. I’m so good at them that I often flummox the checker and it can’t come up with a suggestion! :laughing:

But perhaps they migrate to find partners, or are a contaminate from my fingertips… :wink:

I did once have a teacher ask in wonder if I was “trying” to prove a point with my spelling test scores - they just couldn’t figure out why someone with my level of comprehension could be so stupid with the words.

Ok, I will stop now. :laughing:

2 Likes

Hi @BethanyG ,

I finally finished a project and will have some free time.

For me it would be helpful to read through the approaches on the Python track and do a typos patrol, along with other minor checks and fixes, should there be anything that stands out.

Please let me know if that’s OK with you, and whether I should do separate a pull request per exercise or one PR to rule them all (or some other way).

If there’s any simple housekeeping that needs doing and makes sense to be done at the same time, please let me know.

@colinleach please let me know if you’d like to do some of them, or perhaps double-check after I’m done?

Hi @petrem!

I’d be delighted if you wanted to do an approaches audit. :smile:

The easiest for me would be 1 PR per exercise, especially if you’re going to review syntax and grammar as well as typos (doing just typos is just fine - so don’t feel obligated!). Easier to have a discussion in GH, and easier to “check off the list”, once we’ve reviewed :smile:

I think it can feel a little overwhelming at first. Each completed set of approaches is in the .approaches folder under each exercise. So, for example, the approaches for wordy are under https://github.com/exercism/python/tree/main/exercises/practice/wordy/.approaches

Each .approaches should have a config.json and a introduction.md (which outline all the available approaches for an exercise). Then there will be 2 or more subfolders that include the approach in detail, along with a code snippet. Be careful of the snippets: they are sharply limited in length, so aren’t necessarily complete nor “Python formatted” with extra whitespace (since that counts as a line). For more info on approaches, see the approaches section in the Building Exercism docs.

See the table below for which exercises have completed approaches and which are “in progress” (which have an unmerged PR). Hopefully, I didn’t miss any.


Exercises With Approaches
Completed? Exercise Name
:white_check_mark: Acronym
Affine Cipher
IN PROGRESS (PR 3652) All Your Base
Allergies
Alphametics
Anagram
Armstrong Numbers
:white_check_mark: Atbash Cipher
Bank Account
Binary Search Tree
Binary Search
:white_check_mark: Bob
Book Store
Bottle Song
Bowling
Change
:white_check_mark: Circular Buffer
Clock
:white_check_mark: Collatz Conjecture
Complex Numbers
Connect
Crypto Square
:white_check_mark: Darts
Diamond
Difference Of Squares
Diffie Hellman
IN PROGRESS (PR #3666) Dnd Character
Dominoes
Dot Dsl
IN PROGRESS (PR 3378) Etl
Flatten Array
Food Chain
Forth
IN PROGRESS (PR 3772) Gigasecond
Go Counting
Grade School
:white_check_mark: Grains
Grep
:white_check_mark: Hamming
Hangman
High Scores
House
Isbn Verifier
:white_check_mark: Isogram
Kindergarten Garden
Knapsack
Largest Series Product
:white_check_mark: Leap
Ledger
Linked List
List Ops
:white_check_mark: Luhn
Markdown
Matching Brackets
Matrix
Meetup
IN PROGRESS (PR 3935) Flower Field (Minesweeper)
:white_check_mark: Nth Prime
Ocr Numbers
Paasio
:white_check_mark: Palindrome Products
:white_check_mark: Pangram
Perfect Numbers
Phone Number
:white_check_mark: Pig Latin
Poker
Pov
Prime Factors
Protein Translation
Proverb
Pythagorean Triplet
Queen Attack
Rail Fence Cipher
:white_check_mark: Raindrops
Rational Numbers
React
Rectangles
Resistor Color Trio
Resistor Color Duo
Resistor Color
Rest Api
:white_check_mark: Reverse String
:white_check_mark::white_check_mark: Rna Transcription
:white_check_mark::white_check_mark: Robot Name
Robot Simulator
:white_check_mark: Roman Numerals
:white_check_mark: Rotational Cipher
Run Length Encoding
Saddle Points
Satellite
Say
Scale Generator
:white_check_mark: Scrabble Score
Secret Handshake
Series
Sgf Parsing
:white_check_mark: Sieve
Simple Cipher
Simple Linked List
Space Age
Spiral Matrix
:white_check_mark: Sublist
IN PROGRESS (PR 3375) Sum Of Multiples
Tournament
Transpose
Tree Building
Triangle
Twelve Days
Two Bucket
Two Fer
Variable Length Quantity
IN PROGRESS (PR 3371) Word Count
Word Search
:white_check_mark: Wordy
:white_check_mark: Yacht
Zebra Puzzle
Zipper
3 Likes

Given all the other things I have been totally failing to do recently, it would be dishonest to pretend that I can make much of a useful contribution to this, any time soon. Sorry!

Like @BethanyG, I would be delighted for you to get started on this. Good luck!

3 Likes

Thank you for the details.

Here’s a first attempt: robot-name approach: fix typos, minor rephasing/improvements by petrem · Pull Request #4051 · exercism/python · GitHub

Please let me know if this is along the lines you had in mind, if I went too far with the changes, etc.

I wouldn’t want to take up too much of your time, so don’t be too gentle :slight_smile:

2 Likes