Originally posted by skeevy420
View Post
It's great to learn the basics (with some small limitations) but the deeper you go into and the bigger your code base get's the more it shows it's big design problems.
Let me name a few bigger problems:
1. no blockscope
2. to much syntax (I go deeper into that)
3. incorrect if/else statement (that is not only true for python)
4. hard to get much speed out of it.
5. very focused on using much variables
6. to few constructs.
That are of course only some headlines that tackle down to other stuff. No blockscope should be obvious. that means that you have to care that if you have maybe 2 loops with a iterator that you make sure that it got reseted, which can lead to many mistakes that produce no error just by changing the order of blocks much side effects.
The biggest problem is, to much syntax, the major guy behind Python hated functional stuff, and therefor created a separate language for it with crazy special syntax.
Like such:
Code:
isApple = True if fruit == 'Apple' else False
Code:
(lambda x: x + 1)(2)
Code:
def add1 (x): return x + 1 ... add1(2)
You also need to learn the lots and lots of different syntaxes. But you also become problems using lambdas that go over several lines. Because python is basically build around the assumption that you only have short lines that don't go longer than 1 line except multiline-comments.
You need something like that:
Code:
fn = lambda x: 1 if x \ else 2
About the incorrect if statement it represents not the block logic.
So idealy you have somethnig like:
Code:
if X: then: foo () else: bar ()
Which is correctly done in lisp:
Code:
(if x (foo) (bar))
Because multiline Lambda don't exist you need to seperate your code parts into smaller peaces and have more interim results and safe them in variables, which forces you to think of 1000 variable names.
About the two few constructs you could say I complained about to much syntax and now I want more constructs but a different construct don't need to have a different syntax it just can have a different name. So they don't have a switch/case statement so you usually see code like that instead:
Code:
if x < 0: x = 0 print('Negative changed to zero') elif x == 0: print('Zero') elif x == 1: print('Single') else: print('More')
again in (e)Lisp you have the pcase macro:
Code:
(print (pcase x ((pred (lambda (i) (< i 0))) (setq x 0) "Negative Changed to zero") (0 "Zero") (1 "Single") (_ "More")))
which purely compared line and charakter based is not that much different, but it is less repetitive therefor easier to refactor or just to change.
4 times print and 4 times "x" vs 1 print and 2 times "x". More DRY code therefor better. And yes there are ways to do that with lisp comprehension in python but A that is very advanced and B also not much better / cleaner.
In this example the negative number check would not be possible with list comprehension as far as I know. So in this specific example it would not be a option but also because there is a x=0 statement list comprehension would need to use functions as return value and not values that would mean 4 defined functions for the 4 possible conditions, which again would mean lot's of repetitive code. 4-5 function heads...
that are some of the problems I have with python but for small shell scripting it's good enough I guess
Comment