Pattern matching accepted for Python

Discussion in 'Programming General' started by Wsj, Feb 9, 2021.

Pattern matching accepted for Python
  1. Unread #1 - Feb 9, 2021 at 7:59 PM
  2. Wsj
    Joined:
    Aug 13, 2019
    Posts:
    9,011
    Referrals:
    10
    Sythe Gold:
    9,182

    Wsj Hero

    Pattern matching accepted for Python

    Original article found here: Pattern matching accepted for Python [LWN.net]

    A lot of early Python's appeal was in its simplicity. I miss that era. Soon Python is going to resemble C++'s bloated feature set where you're not supposed to use parts of the language because "that's the old way of doing things". This already the case with string formatting.

    Python is evolving into several different languages. "There should be one-- and preferably only one --obvious way to do it." I'm waiting for a PEP that deprecates PEP 20, "The Zen of Python". It's become more and more clear that the core developers don't follow it all anymore.

    What are your thoughts?

     
    ^ Batatas and PKDealer like this.
    Last edited: Feb 9, 2021
  3. Unread #2 - Feb 11, 2021 at 4:01 PM
  4. Batatas
    Joined:
    Jun 29, 2018
    Posts:
    52
    Referrals:
    0
    Sythe Gold:
    60

    Batatas Member

    Pattern matching accepted for Python

    Depends on your definition of simplicty. Do you mean simplicity as in minimalist or simplicity as of easy?

    Cause in Python stuff is simple, as in easy to do stuff and to read.
    While in GoLang, stuff is simple, as in minimalist or only one way to solve a problem.

    for example, in Python you can already iterate over Lists in multiple ways, but all of them are really easy to implement and understand:
    Code:
    for element in my_list:
        print(element)
    
    # can be done the same ways like
    
    for i in range(len(my_list)):
        print(my_list[i])
    
    # or
    [print(x) for x in my_list]
    
    # or
    
    i = 0
    while i < len(my_ist):
     print(lst[i])
     i = i+1
    
    
    As you can see, here you have a for loop with syntatic sugar, you just need use use the keyword "in"


    yet in GoLang you only have one way to iterate over lists (aka slices or any other iteratable), which is

    Code:
    //index or element can be ommited using _, so like, "for _, element :=...." would ommit the index
    for index, element := range(my_list) {
         fmt.Println(element)
    }
    
    notice that also, in GoLang there are no while loops, yet you can still do while loops with

    Code:
    
    for 1 < 2 {
    
      fmt.Println("I like potatoes")
    }
    
    



    But, here's the simplicity as in easy:

    in GoLang there's no map function (or any other method available for generics, cause there are no generics)

    Here's how you would map a list of int (my_list) to a new list (new_list) using a function (my_func()):

    So GoLang
    Code:
    var new_list []int
    for _, element := range(my_list) {
        new_value := my_func(element) //this could be inside the append function, but would be hard to read
       new_list = append(new_list, new_value)
    }
    

    Yet here's the same thing but in Python
    Code:
    new_list = [my_func(x) for x in my_list]
    
     
  5. Unread #3 - Feb 11, 2021 at 4:42 PM
  6. Batatas
    Joined:
    Jun 29, 2018
    Posts:
    52
    Referrals:
    0
    Sythe Gold:
    60

    Batatas Member

    Pattern matching accepted for Python

    This was already wrong from the beginning, you may have multiple ways of solving the same problem in python, but that doesn't mean that it gets harder to read, understand or implement.

    Every multiple way of doing stuff in python are really easy to read, understand and implement, so there's no issue on that.
    Adding pattern matching and other stuff from functional programming will just make the code more concise and easy.
     
    ^ Wsj likes this.
< Sythe Login | >

Users viewing this thread
1 guest


 
 
Adblock breaks this site