Re:A Conversation with Language Creators: Guido, James, Ande...
by pmontra on Thursday April 04, 2019 @07:57AM
(#19571076)
I don't think it's a matter of keywords. I'm working with both Elixir and Python on different projects right now.
Pattern matching is very deeply ingrained into Elixir. Two examples to scratch the surface
This is pattern matching in function arguments
def process_file({:ok, {file_name, file_content}}) do
...
:ok
end
def process_file({:error, reason}) do
...
:error
end
def process_file(_), do: error
This is pattern matching in assignment
{:ok, content} = File.read(file_name)
Actually the = character is the pattern matching operator, which accidentally ends up assigning values in some cases: it can't assign to the :ok atom but it can assign to the content variable. If File.read returns {:error, "some error"}, the match will fail and the program will stop. Usually I get a notice from Sentry and a supervisor process will start it again, possibly running into the same problem or not. Sometimes errors are caused by external services that have occasional hiccups.
Some changes are so structural that turn languages into another one and I'm not sure it's worth it. We have so many languages to choose from.
Pattern matching is very deeply ingrained into Elixir. Two examples to scratch the surface
This is pattern matching in function arguments
This is pattern matching in assignment Actually the = character is the pattern matching operator, which accidentally ends up assigning values in some cases: it can't assign to the :ok atom but it can assign to the content variable. If File.read returns {:error, "some error"}, the match will fail and the program will stop. Usually I get a notice from Sentry and a supervisor process will start it again, possibly running into the same problem or not. Sometimes errors are caused by external services that have occasional hiccups.Some changes are so structural that turn languages into another one and I'm not sure it's worth it. We have so many languages to choose from.