Re:macOS deprecating scripting language runtimes, including ...
by em500 on Friday June 07, 2019 @07:10AM
(#20123365)
clear
echo "Hello there. I'm a computer. What's your name?"
read G
echo "Hello $G. You are welcome to computer land."
while true
do
echo ""
echo "What would you like to do today?"
echo "1) Say something random"
echo "2) Make a maze"
echo "3) Exit"
echo "Enter your selection"
read S
if [ "$S" = "1" ]; then
say $( head -n $((7*RANDOM)) /usr/share/dict/words | tail -n 1 )
elif [ "$S" = "2" ]; then
for i in {1..3000}; do
if (($RANDOM>16384)); then printf '/'; else printf '\'; fi
done
elif [ "$S" = "3" ]; then
echo "Bye."
exit
else
echo "Try again."
fi
done
This doesn't seem much different than the BASIC example to me. I think only the lack of GOTO in shell scripts makes this look slightly more complicated (requiring either putting all the statements in the if ... elif parts or defining functions).I honestly don't see how a Python or Ruby version would be much better than a shell version for this. Perhaps you can show by example?
Re:macOS deprecating scripting language runtimes, including ...
by TimTheTinker on Friday June 07, 2019 @02:04PM
(#20127155)
You do have a point - that's not too bad, but to my eyes it's still more arcane than Python and Ruby (spoken as someone who has written less than 30 shell scripts in my life).
I still contend that Ruby and Python are far more accessible than shell scripting, because they are very popular, especially Python, cross-platform, and less arcane.
Re:macOS deprecating scripting language runtimes, including ...
by em500 on Friday June 07, 2019 @03:53PM
(#20127987)
For my own curiosity I did the simplest Python version I could think of to see how it would compare:
import os
import random
import sys
os.system("clear")
print "Hello there. I'm a computer. What's your name?"
G = raw_input()
print "Hello " + G + ". You are welcome to computer land."
while True:
print ""
print "What would you like to do today?"
print "1) Say something random"
print "2) Make a maze"
print "3) Exit"
print "Enter your selection"
S = raw_input()
if S == "1":
F = open("/usr/share/dict/words").readlines()
W = random.choice(F)
os.system("say {}".format(W))
elif S == "2":
for i in range(1, 3000):
if random.random()>0.5:
sys.stdout.write("/")
else:
sys.stdout.write("\\")
elif S == "3":
print "Bye."
exit()
else:
print "Try again."
It looks like a tossup to me, all 3 versions have their own share of magic that will confuse the beginner. I say this as someone who reads and writes a lot more python than bash daily.
Re:macOS deprecating scripting language runtimes, including ...
by TimTheTinker on Thursday June 06, 2019 @11:26PM
(#20121399)
Another of my favorites -- this was fun in middle school (years 6-8) when I had a spare minute or two to sit down at a random computer (maybe in a computer lab).
10 SCREEN 9
20 CLS
30 COLOR 1, INT(RND*10)
40 SOUND 20+(RND*5000),.2
50 GOTO 30
The effect is rather striking, like someone must have really messed up the computer.My main gripe with Windows NT was that it would go back to the NT screen saver -- I couldn't get it to stay displaying my program, because there wasn't any true DOS mode.
Re:macOS deprecating scripting language runtimes, including ...
by em500 on Friday June 07, 2019 @07:17AM
(#20123396)
How would you do this on macOS with just the built-in Python or Ruby?
Re:macOS deprecating scripting language runtimes, including ...
by TimTheTinker on Friday June 07, 2019 @01:44PM
(#20126979)
I have no idea... I just wanted to share something fun I did around 25 years ago.
What about the iconic 4th grader "greetings and cool things" script? Here's something like what it looked like for me (on the IBM PC in my classroom):
That kind of stuff is perfect for Ruby and Python. I don't envision kids getting that far with shell scripts, awk, sqlite3, or elisp. They might with HTML and JavaScript, but that requires learning HTML as well as JS and is sandboxed in the web browser; it's also not as "Cool! Look what I can make the computer do!" as messing around in the terminal. (Note, Iām glad BASIC isn't as available anymore -- we're not getting kids into certain bad programming habits early-on, like use of GOTO. But BASIC would still be more approachable than shell scripting, awk, etc.)