{
in: {
nano: {port: 'nanoKONTROL SLIDER/KNOB'},
wx: {port: 'UltraLite mk3 MIDI Port'},
},
out: {
live: {port: 'from MaxMSP 1', ccmap: [2, 1]},
vl: {port: 'UltraLite mk3 MIDI Port'},
},
}
And I'm getting that very readable data file "for free" - simply by writing the data as the language encourages me to.primes = [2, 3]
for i in xrange(primes[-1] + 2, 1000, 2):
is_prime = True
for prime in primes:
if not (i % prime):
is_prime = False
continue
if is_prime:
primes.append(i)
print primes
print len(primes)
[andrew@fstop ~]$ ruby test.rb 10000000
user system total real
Hello 2.820000 0.140000 2.960000 ( 2.960524)
HelloThere 2.940000 0.270000 3.210000 ( 3.315655)
HelloThereMyFriendss 3.360000 0.490000 3.850000 ( 4.010065)
[andrew@fstop ~]$ ruby test.rb 20000000
user system total real
Hello 5.630000 0.290000 5.920000 ( 5.995643)
HelloThere 5.880000 0.530000 6.410000 ( 6.621344)
HelloThereMyFriendss 6.370000 1.010000 7.380000 ( 7.638905)
The results? If so, it really looks like concatenating "HelloThereMyFriendss" 10 million times takes more time than concatenating "Hello" the same number of times.[f(expensive(x)), g(expensive(x)) for x in items]It doesn't take a genius to be able to see that you can immediately eliminate that duplicate call to expensive(x) and perhaps save half your CPU off the top - it does take a genius to see this in assembly language.
Students need to understand how to think clearly about computers and computer programs before anything else. They need to understand best programming practices: how to create readable, testable, maintainable code. -- lupus_yonderboyWhy do you think the order matters? Certainly it would be good if they knew how to write "readable, testable, maintainable" code at some point but there's no reason they should learn that first, since it would probably bore them to tears. Likewise, I don't think Assembly should be taught first. The first thing should be to learn a relatively easy language as quickly as possible, so they can get used to expressing themselves in code.
because nearly all the time these "orders of magnitude" performance differences are an illusion.Picking an off the shelf collection is an implementation detail. Most of the time you just change the type deceleration to change which one you pick (i.e. Map m = new TreeMap<type> vs. Map m = new Hashtable<type>)
Suppose you have an indexed table and want to find elements in it. A linear search is O(n) but a hashmap is O(1)! So the hashmap wins.... right?
Not so fast, cowboy. It costs an awful lot just to set up a hashtable, all these buckets and pointers in memory, and then doing all the arithmetic to locate your buckets isn't free either.
primes = [2, 3]
for i in xrange(primes[-1] + 2, 1000, 2):
if all(i % prime for prime in primes):
primes.append(i)Remember that there is a "computer" in "computer science". Know how long it takes your computer to execute an instruction, fetch a word from memory (with and without a cache miss), read consecutive words from disk, and seek to a new location on disk.
« Older In their heyday in the 1960s and '70s, "spagh... | The 3 million people of the Sa... Newer »
This thread has been archived and is closed to new comments
My personal guidelines for learning how to program:
1) Learn assembly language (preferably for a simple CPU)
2) Optimize for fun and learning, not program performance. That is to say, use a language that speaks to you. Something like Ruby, Processing or perhaps Haskell. Maybe Python, but I don't like it personally. You might.
3) Do something diretly in your domain of interest. Use a thing you already know - don't be learning the code AND the idea you're trying to express at the same time.
4) Build it wrong, but build it.
Finally, theoretical computer science is both fascinating and beautiful, and borders on philosophy.
posted by krilli at 9:05 AM on October 24 [7 favorites]