Justified: Visual Basic Over Python For an Intro To Programming
theodp writes ICT/Computing teacher Ben Gristwood justifies his choice of Visual Basic as a programming language (as a gateway to other languages), sharing an email he sent to a parent who suggested VB was not as 'useful' as Python. "I understand the popularity at the moment of the Python," Gristwood wrote, "however this language is also based on the C language. When it comes to more complex constructs Python cannot do them and I would be forced to rely on C (which is incredibly complex for a junior developer) VB acts as the transition between the two and introduces the concepts without the difficult conventions required. Students in Python are not required to do things such as declare variables, which is something that is required for GCSE and A-Level exams." Since AP Computer Science debuted in 1984, it has transitioned from Pascal to C++ to Java. For the new AP Computer Science Principles course, which will debut in 2016, the College Board is leaving the choice of programming language(s) up to the teachers. So, if it was your call, what would be your choice for the Best Programming Language for High School?
To understand why proprietary software in schools is a poor answer, please see this 15-minute TED talk.
Actually that example is not even valid Python code, you'll get an 'n not defined'. Furthermore you need to indent it properly. You probably want something like this:
def primes_upto(limit):
is_prime = [False] * 2 + [True] * (limit - 1)
for n in range(int(limit**0.5 + 1.5)):
if is_prime[n]:
for i in range(n*n, limit+1, n):
is_prime[i] = False
return [i for i, prime in enumerate(is_prime) if prime]
And VB6 you can actually do this on one line :)
Sub Eratost() : Dim sieve() As Boolean : Dim n As Integer, i As Integer, j As Integer: n = InputBox("limit:", n) : ReDim sieve(n) : For i = 1 To n : sieve(i) = True : Next i : For i = 2 To n : If sieve(i) Then : For j = i * 2 To n Step i : sieve(j) = False : Next j : End If : Next i : For i = 2 To n : If sieve(i) Then Debug.Print i : Next i : End Sub 'Eratost
If you want one-liner programs, we should really force people to use perl which is famous for that. Python is not friendly to 'one-liner' types of programs because it forces indentation.
But really, the parser is supposed to work with you, not against you, so why not write it on several lines to help readability? I fail to see how writing code on one line really proves its power.
For bragging rights, you could go full-genius mode [instead of full-retard] with APL (change 100 to whatever you want the vector of primes to be) :
(~vv.×v)/v1100
EDIT: Damn it, you can't even put APL code in Slashdot. Here is a link to explain the code