Zettelkasten Forum


Learning a new programming language using the ZK

edited April 2021 in Workflows

Hi all,

I'm keen to understand other peoples workflows using a ZK, when learning a new programming language (if anyones done this using their ZK)...
I'm embarking on a new learning experience (read: having to learn Python after our shit-hot Python developer who took over my old mediocre R code has left our company), and keen to see if the ZK is able to help me learn this new language in any way.
I can follow along with the code as I essentially built all the logic in R prior to him rebuilding it all in Python, but he's massively improved the code as he was WAY more familiar with Python than I ever was with R.

Any pointers would be much appreciated!

/sep

Comments

  • edited April 2021

    When I learned about list comprehensions in Python, I explained it to me in familiar terms, e.g. what it'd be like in Ruby or C, for example. This helps find an answer for the question "what was the Python thing for X in Ruby again...?"

    Example: value types, which I likened to Ruby's OpenStruct

    # 201905280926 Value types in Python 3
    #python #value-type
    
    Python value objects require initializer boilerplate, overloading the `__eq__`
    function for by-value equality, and optionally `__repr__` for String representation
    when `print`ed.[#20210407vt][]
    
    ```python
    class RegularCard
        def __init__(self, rank, suit):
            self.rank = rank
            self.suit = suit
    
        def __repr__(self):
            return (f'{self.__class__.__name__}'
                    f'(rank={self.rank!r}, suit={self.suit!r})')
    
        def __eq__(self, other):
            if other.__class__ is not self.__class__:
                return NotImplemented
            return (self.rank, self.suit) == (other.rank, other.suit)
    ```
    
    For simple structures, the Python equivalent of Ruby's `Struct` or `OpenStruct`
    can be used, named tuples:
    
    ```python
    from collections import namedtuple
    
    NamedTupleCard = namedtuple('NamedTupleCard', ['rank', 'suit'])
    queen_of_hearts = NamedTupleCard('Q', 'Hearts')
    queen_of_hearts.rank # => Q
    ```
    
    In Python 3.7, this can be shortened using the `@dataclass` decorator:
    
    ```python
    from dataclasses import dataclass
    
    @dataclass
    class DataClassCard:
        rank: str
        suit: str
    ```
    
    [#20210407vt]: <https://realpython.com/python-data-classes/>
    

    I also often script command-line things as automations, so I usually have at least 1 note per programming language with copy-pastable instructions on how to create a relative file path securely.

    I have 20 notes tagged "python", only, and 5--10 of them are about function decorators that I found very interesting. So getting side-tracked learning something new was a thing, and it was very fun to play around with that.

    My use case was to build a controller application for Raspberry Pi to playback music with just 1 button for my grandmother. (I was slower than her hearing decayed, so I never finished the project, since by now I think the audio output options would be useless.)

    Author at Zettelkasten.de • https://christiantietze.de/

Sign In or Register to comment.