Advertisement
Guest User

German guy who posted online

a guest
Nov 17th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.45 KB | None | 0 0
  1. --Read if you are a rookie struggling with Python
  2. --Read from top to bottom thoroughly
  3. --Have a good read!
  4.  
  5. Q: Opinions on python..And what about Lua.?
  6.  
  7. A:
  8. Lua is as a language easier than Python. It is easier to learn and it has less reserved tokens (21) to Python (33) (Lua only needs about 60% the keywords to do the same and more). To this comes a huge and complex and complicated library structure, alone the many different classes and types are handled completely different.
  9.  
  10. We have non-intuitive counting in Python, like
  11.  
  12. for i in range(1,11) do:
  13. to count from 1 to 10, we have this terrible “whitespaces are code” problem, I don’t know who had that terrible idea, that’s just screaming for havoc and I highly dislike this as a daft idea.
  14.  
  15. Not that this is theoretically a daft idea, they had their ideological fights already if TAB should be allowed and how many space it should be, while the library base is done by the one way or the other any you absolutely can’t transfer any code anywhere else.
  16.  
  17. Everything is total “verkopft” and the programming experience is just terrible. I mean, I was at Python, I did work with that professionally, I earned money with products I delivered, but since I switched to Lua that’s much better.
  18.  
  19. Products actually can be delivered as packages, the code runs like 30 times the speed without eating away all RAM and CPU on the target machine and throwing a lot of incompatibility errors when I just want to link some libraries together.
  20.  
  21. All this is not happening with Lua.
  22.  
  23. The solutions to algorithms come easier, I need actually less code to do the same stuff in Lua than in Python (Python is already good with that, but Lua is on an epic level).
  24.  
  25. There are at least for everything I needed already libraries there and what some of the older postings here say, that you can’t get collections running and all that, that there is no regex library, that’s all wrong.
  26.  
  27. You have everything and you have it better than in Python. Why better? It’s blazing fast.
  28.  
  29. Luajit is the fastest High Level Language that is around and with all my little unimportant benchmarks I only fall short of C itself. Why? Because many of the Lua libraries are actually implemented in C, some in Lua, but many are in C. C is highly portable and indeed the best portable language I know.
  30.  
  31. You have FFI and with that a direct interface into the system, which makes it easy to call anything, you even don’t need most of those glue- and binding-libraries that you need for work with Python.
  32.  
  33. local ffi = require("ffi")
  34. ffi.cdef[[int printf(const char *fmt, ...);]]
  35. ffi.C.printf("Hello %s!\n", "user")
  36. This is indeed as easy as it gets.
  37.  
  38. If there should be anything that Lua can’t do, there is the package Lunatic-Python which is a bridge between those two and you just can mug it from Python and go back after that to the better language.
  39.  
  40. To include Lua as an embedded language into C are just four lines of code, the memory need for the whole runtime environment is just about 120kb shared code in memory.
  41.  
  42. This thing is tiny, powerful, flexible.
  43.  
  44. And it’s not just a “Script Language”, this thing is a full grown complete universal programming language that is at least as powerful as Python, but I tell you, I can do things in Lua, that Python never will do.
  45.  
  46. Lua is in the best possible way the return of BASIC, the return to bring the power of programming back to the simple man on the street. To democratize code and with that power. To enable the modern literacy to everyone, from child to granddaddy.
  47.  
  48. I have just no idea why Python got so big. This is just no comparison and the language Python never should have happened. The question which of those two languages is the easier one is very, very easy to answer:
  49.  
  50. Lua
  51.  
  52. And not just that. Lua “only” has one abstract datatype, the table, which is actually a mix of array, dictionary and set, depending on how you are using it. Tables are the natural way the CPU wants data and which is the fastest structure the CPU can process. It is also very easy to learn and after you understood this one thing, you have understood Lua and how to handle it.
  53.  
  54. You can do everything with those Lua-Tables because they are genius. You don’t need to learn abstract concept as object orientated programming, you can just do what you want. But Lua allows you to implement your modules like that.
  55.  
  56. You have all possible ways to write programs, imperative, functional, object orientated, predicative. But Lua doesn’t forces you to do that. It allows you to do that.
  57.  
  58. Because like every tool some are good and needed sometimes, some are daft sometimes. To not be able to get rid of a concept because of dogma is a bad thing and limiting the application of that language to software problems.
  59.  
  60. Lua never limits you. You can tell Lua to limit you, but you have to tell. And mostly that’s not sensible to do anyway. Lua is very easy to cross borders to C and from C back to Lua. You have full access from C to everything that is happening in the Lua engine.
  61.  
  62. So you can practically transpile any Lua module to C, compile it there as a shareable system library and reuse it.
  63.  
  64. There is a dispute about the features of both languages and Lua has won this argument by far against Python:
  65.  
  66. Lua Versus Python
  67.  
  68. But anyways.
  69.  
  70. Unique word counter for a file in Python:
  71.  
  72. #!/usr/bin/env pypy
  73. import re
  74. import sys
  75. r = {}
  76. for line in sys.stdin:
  77. for w in re.findall('\w+', line.lower()):
  78. r[w] = r[w] + 1 if w in r else 1
  79. sum=0
  80. words=0
  81. for k, v in sorted(r.items(), key=lambda x:x[1]):
  82. print(k + ': ' + str(v))
  83. sum+=v
  84. words+=1
  85. print("Sum: "+str(sum)+" Words: "+str(words))
  86. In Lua, while in Lua we don’t need any external library, but we created the allword() function. This can surely done by libraries, there are collections and that, but I wanted to show it the pure way. It is quite easy and understandable, but a bit longer in this example. You might call some of the solutions in Python elegant, but I only find them unintuitive and a bit too terse. The lambda function is not of the power of the full functional Lua solution and I maybe should have taken one of the libraries. But, hey. No need for that in Lua, not really. Not yet. But I find the allwords() thing quite easy and if you ignore that part, the program is much better. I didn’t have to look up any of this.
  87.  
  88. It is 5 times faster than even PyPy, though. I was calling it with
  89.  
  90. ./wordcount.lua <shakespeare_midsommer.txt
  91.  
  92. #!/usr/bin/env luajit
  93. function allwords()
  94. local line=io.read()
  95. local pos=1
  96. return function()
  97. while line do
  98. local s,e=string.find(line, "%w+", pos)
  99. if s then
  100. pos=e+1
  101. return string.sub(line, s, e)
  102. else
  103. line=io.read()
  104. pos=1
  105. end
  106. end
  107. return nil
  108. end
  109. end
  110.  
  111. r={}
  112. for word in allwords() do
  113. word=word:lower()
  114. if not r[word] then
  115. r[word]=1
  116. else
  117. r[word]=r[word]+1
  118. end
  119. end
  120.  
  121. list={}
  122. for k,v in pairs(r) do list[#list+1]=k end
  123. table.sort(list, function(a,b) return r[a]<r[b] end)
  124. words=0 sum=0
  125. for k,v in ipairs(list) do
  126. words=words+1
  127. sum=sum+r[v]
  128. print(v,r[v])
  129. end
  130. print("Words", words, "Sum", sum)
  131. Maybe you should also go to Rosetta Code and look at several algorithms and how they are solved in Python and in Lua there. Most of the Lua solutions are easier to read and shorter in code.
  132.  
  133. For example the coins problem (naive) took 6.52 seconds under PyPy and 0.2 seconds under Luajit, while I enhanced the number by two grades of magnitude, to get a measurable value. That’s 32 times the speed for Lua…
  134.  
  135. But you can see the programs there and compare them. It’s much better than my example (but I liked to come up with one myself): the code is almost identical. Just Lua states it more intuitive, more easy to read, more understandable.
  136.  
  137. So: I guess Lua is the simpler language. They have some things in common, but if you don’t like whitespaces, characters that you can’t even see as active part of the code, if you prefer some real functions in a functional programming instead of just some lambda calculus, if you prefer to see loops counting to 10 instead to 11 if you want to count to 10 and if you prefer that algorithms are written in near English instead of r[w] + 1 if w in r else 1 then you will most likely prefer Lua.
  138.  
  139. Easy language, hard problems.
  140.  
  141. There is nothing wrong with keeping a language easy. I really scratch my head why so many of the language makers think different. You know, if something is looking easy, but doing hard stuff, people tend to shout: “That’s genius!”
  142.  
  143. And that’s how I see that, too. This is what we want, what we need.
  144.  
  145. HLL is here, the only sense of that stuff is to get shit done faster than with a compiling language, more flexible, without caring about the underlying difficulties. As long as we get away with that. HLL are there, to lower the threshold for people who want to program, to lower the educational level, to get them into this early and easy and make that experience fun, challenging and rewarding.
  146.  
  147. There is no other thing a human being can do that gets used more by humanity, that saves more lives, gets repeated over and over, code, that is living knowledge, that multiplying and automated knowledge. It is not without reason the motor that drives or throttles our economy and the more people we get into coding, the better the world we get.
  148.  
  149. Coding that is like art something that only a very small fraction of people ever will be doing. How many people do you know who are really good musicians, and who do that all their life and not stop, when they are out of the fornication pool? When they are thirty or so?
  150.  
  151. How many keep on going? A lot more than I know programmers, but it is on the same niveau. We can forget about that utopia about everybody will be an artist. Artists are fucking rare. And we can forget as well about being a world full of programmers. Programmers are even rarer. I do know more people who have written a fucking book than I know people who are coders and I am living in an environment that sieves out coders, that is coder-rich, because I am one myself.
  152.  
  153. Python is looking at the first glance like an easy language, but it is not. It is a highly terse hacking-language for skilled and seasoned programmers, who are well educated in higher, complex and hard to understand programming concepts and it doesn’t lead from it’s nature to well readable and maintainable code.
  154.  
  155. There are worse languages out there, like APL or Malbolge or Java. But there are easier ones, too.
  156.  
  157. Lua would be one of them. Not that you can’t do complex and complicated stuff in Lua, you can. Easily. And you can write hard to understand code, too, if you don’t take care. But for an easy mind with low education, for a child or just average Joe, I would recommend Lua ten times over Python.
  158.  
  159. He will be more successful, the language gives back more, it is revolutionary as at it’s time the concept of BASIC was. Power to the people. And I don’t mean that in some socialistic way, I mean that in a fair and democratic way. Democracy, that means that everybody gets the chance to be a programmer. Not that this is in everyone or that we will have a real army of them. We will never.
  160.  
  161. But every child learns to play the recorder at school or some other instrument. And brings out some noises, and some of that stuff is really enjoyable and well done. Everybody has the the brains in him to become a coder, but only very, very few have the heart and the will and accept the hard work and the dedication to learn to play the violin or something.
  162.  
  163. But everybody that is must get the chance to learn it and it has to be a rewarding first time. A time that gets out of that mass of humanity the very few that actually not only have the potential, but also the drive to do it, to learn it.
  164.  
  165. And if we do that, we should give them a language that they do not need to abandon after a year or two, but something that has it’s place, it’s real place in the infrastructure. I hate “school” language and consider them a waste.
  166.  
  167. A waste of programming potential, because how many people do I know who stopped being programmers after our professors destroyed the will in them to become one, by torturing them with abominations of languages that are highly ideological, have not a little bit of practically in them, and are forgotten after the course ends?
  168.  
  169. Many. And I don’t understand why teachers are proud of that. Haskell, just to blame one. Pascal, to blame an other. Lisp, which has just no right to survive any longer from my position. And many more languages that will erode the thin potential we have.
  170.  
  171. We have to be careful with the thin potential of programmers. They are special. We need them. We have to nurture them and keep them going. Everywhere there is a shortage of programmers. Everywhere on this world.
  172.  
  173. Why?
  174.  
  175. Really, tell me, why? Is it so hard to write a “Hello World”? Are we not teaching every child to learn programming at school? Why am I the only adult from my class of Gymnasium, the only one doing still two things in his life. First playing music. Second doing code. We were about hundred children in my class of ‘85. One coder and from all children that we were at elementary school, from the thirty we were at class, two of us went to the Gymnasium. And I grew up in a very special environment, we were the hackers of the world at that time.
  176.  
  177. Literally in my class were sitting the boys that were directly doing the NASA hack. And I was in among those people. Friends of them. I wasn’t in those machines Castor and Pollux, but I did similar stuff at that age. Things that were not forbidden at that time, that were not against the law.
  178.  
  179. I am one of 3000, maybe 10000, maybe 30000. But I am rare. I never felt being “elite” but that there is nobody around doing even remotely the stuff I do and to not knowing anyone who is. This gives me the impression that I am rare and with that all other coders. We need more of them. More than we need people writing books and sharing knowledge. To share knowledge in a machine readable way is a step up from writing a book. It is an intersection of intersection of intersection of intersection of talents. It is special. We need more or them, more that are willing to share their knowledge in this kind of way; free.
  180.  
  181. But I don’t know if any of the parallel classes brought up anything. I did know all the possible programmers in the next year under us and the next and the next and the next, because I had friends there or my younger brother. And from all of those people, I am the only one left in code. And each and everyone of the people at Gymnasium is 2 of 30.
  182.  
  183. And we have to do everything to get more out of them. Code, that is future.
  184.  
  185. This last part goes about over this question, but the question is important, I think. “Which language is easier?” I think it is better to ask, “Which language is more fun?”, because it will bring people to the keyboard.
  186.  
  187. Not ease alone, but fun and motivation. And here Lua is a clear winner.
  188.  
  189. Just do some games with it, if it is fun for you. Playing is the first drive we have. The second is sex. The third is nutrition, safety and so on. The first is playing. A language that is 30 times more powerful than Python, that is easier to write, will give more positive feedback and that comes embedded in games, but is a very professional tool, this is the stuff we need.
  190.  
  191. To get sieved out the few potential we have in humanity. Those very very rare talents, rarer than artists, sparser than geniuses. And only they can code and keep at it. At university they told us, that computer science and software engineering was just engineering. Nothing special.
  192.  
  193. Wrong! I instantly protested, because I could see this was wrong. This was as wrong as it gets. It is more than engineering, it is art, a good whole lot of art in it and it is the result of a dedication that goes way over madness, if you want to be good at this. Most seasoned programmers have some personality quirks that I know or some mental condition. And they are not that way, because computers made them that way. They are like Bobby Fischer, something inside drives them towards these machines like he was driven to that game. They are like the geniuses at Bletchley Park: a rare species.
  194.  
  195. Something very hard to find and to sort out, rarer than gold. Harder to yield than any other thing and more urgently needed than anything on this world:
  196.  
  197. coders
  198.  
  199. Everybody has the brains to become a coder as everybody has the fingers to learn to play the violin. But how many actually end up really doing it? From all those with fingers that I know. Let’s see. I am the only one. From all people. Stop. I teached my friend to play. Okay. That counts. He is, by the way one of the other coders I know. He learned to play violin with 45. From all that people I personally know. Is this coincidence? I say, no. This has something to do with each other.
  200.  
  201. I am driven. And we need to find those driven people. You can’t make them. You can sieve them like you can sieve out gold. And you find them by making it fun, making it easy to do. Get them into contact with code. Make that easy and fun and don’t scare them away.
  202.  
  203. So we need easy languages, languages that encourage and inject the spirit. And make them feel special. We really, really need them. Economically. For making a better world. It worked for me. My first contact with a programming language was BASIC.
  204.  
  205. It was a wonderful experience. And it caught me and got me out of the sand. And we need more of this positive sieving. Because we can’t make them. We can’t make coders.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement