Most recent comments
Jogging og blogging
Are, 9 måneder, 2 uker
Liveblogg nyttårsaften 2016
Are, 9 måneder, 1 uke
Reading in dark times
Are, 11 måneder, 1 uke
Moldejazz 2016
Camilla, 1 år, 2 måneder
Dørskilt
Karoline, 1 år, 3 måneder
Halifax
Tor, 1 år, 4 måneder
Sony Smartwatch 3 review
Tor, 1 år, 4 måneder
Numerikk, takk
Tor, 1 år, 4 måneder
Topp tur
Camilla, 1 år, 6 måneder
Tolkien reading day
Tor, 1 år, 7 måneder
50 book challenge
Camilla, 9 måneder, 3 uker
Five years ago
Tokyo
Tor
Controls
Register

Coding. Oh, my

Today I have learnt to create an elephant at the touch of a button. And to find Tor in a list. Not to mention the delight of turning a string into a list.

Confused? Me too.

I was especially discombobulated (I am taking refuge in friendly words) by Tor's assumption that I would know how f(x) worked (I associate it with differentiation and therefore with annoyance and pain, neither of which are conducive to happy learning).

Everything got much better once I managed to get him to admit that when he was talking about variables, he was really just talking about algebra (or at least algebra as it is defined in my brain; I always found it to be the friendliest branch of mathematics because it managed to avoid those pesky numbers, and I would ask you to not take this illusion away from me by explaining algebra beyond a high school level).

First thing's first: I set up my terminal to look cool. I instantly felt like a hardcore hacker.

We decided I should learn Python, because apparently Python is friendly and nice and will give me warm, cuddly feelings any moment now.

Tor then explained about functions and variables, and how variables can be anything from text strings (he seems obsessed with 'elephant' as a word -- I got much more excited when I realised text strings could include whole works of literature) to numbers (of all shapes and sizes -- I am less excited about them than about the text strings) and lists (which I rather like).

At first I was a little worried about keeping track of all of this, but things got a lot more fun once I realised that I could use actual words instead of single letters as variables: Words are much easier to direct when you call them word, rather than a or x.

Writing
for x in a:
    if x=='Tor':
        print x

is much more confusing and hard to keep track of than
for word in word_list:
    if word=='Tor':
        print word


I wrote
paragraph='I have always preferred books to computers, and my fear that the machine would die (possibly taking me with it) if I accidentally pushed the wrong sequence of buttons has entertained (and possibly frustrated?) Tor immensely. Much as I love technology that makes my life easier, I have had a (healthy) respect for the digital. You know where you stand with books. Unless you set fire to them or drop them in water, they will not accidentally get rid of your text; the worst they can do to you is give you a paper cut or fall on your head.'

which defined that text string (lifted from here) as the variable named paragraph. Then, I wrote
paragraph.split(' ')

which turned that paragraph into the following (slightly scary-looking) list:
['I', 'have', 'always', 'preferred', 'books', 'to', 'computers,', 'and', 'my', 'fear', 'that', 'the', 'machine', 'would', 'die', '(possibly', 'taking', 'me', 'with', 'it)', 'if', 'I', 'accidentally', 'pushed', 'the', 'wrong', 'sequence', 'of', 'buttons', 'has', 'entertained', '(and', 'possibly', 'frustrated?)', 'Tor', 'immensely.', 'Much', 'as', 'I', 'love', 'technology', 'that', 'makes', 'my', 'life', 'easier,', 'I', 'have', 'had', 'a', '(healthy)', 'respect', 'for', 'the', 'digital.', 'You', 'know', 'where', 'you', 'stand', 'with', 'books.', 'Unless', 'you', 'set', 'fire', 'to', 'them', 'or', 'drop', 'them', 'in', 'water,', 'they', 'will', 'not', 'accidentally', 'get', 'rid', 'of', 'your', 'text;', 'the', 'worst', 'they', 'can', 'do', 'to', 'you', 'is', 'give', 'you', 'a', 'paper', 'cut', 'or', 'fall', 'on', 'your', 'head.']

After which I saved this list as word_list by writing
word_list=paragraph.split(' ')

I could probably have done that without the intermediary step, but Tor was being pedagogical.

At which point,
for word in word_list:
    if word=='Tor':
        print word

became possible.

In other words: I can now search a text for words using only the power of my coding skills. You may worship me. (If anyone mentions that it is not a very good search because it can be thrown off by punctuation, you will not get any cake.)

And to make matters even more interesting: I can count each instance of the word by writing
i=0
for word in word_list:
    if word=='Tor':
        i=i+1

I get a number! Instead of Tor written over and over.

Of course, this all depends on my ability to define things correctly, but while slightly daunting it is oddly familiar from writing academic texts.

I wonder whether I will remember any of this tomorrow.
Are, Tor likes this

Comments

Tor,  06.04.13 20:02

It'll be interesting to see how this plays out, and it would be cool to write a book about teaching humanities people to program. If the rise of digital humanities is more than a temporary fashion (and it should be, I think) it might even sell nicely.
Camilla, Are likes this
Camilla,  08.04.13 09:33

I am rather worried that I will suddenly redefine a variable without meaning to (because I have forgotten how I have defined it, or that I have defined it), and somehow throw everything for a loop. Is there a way to get it to notify me when I try to redefine it? Or is that for sissies and I should toughen up and keep a clear mind?

Are,  08.04.13 21:22

Modern development environments, like Visual Studio or eclipse with appropriate plugins, can help you avoid some common mistakes - like having two different variables called something similar, like book and booklet or something like that, and writing a value into one while leaving the other one unassigned, and using the wrong value down the road ("warning: variable is never read").

You can probably infer what kind of mistakes a compiler can help you avoid and which it logically can't detect. There are also tools which analyze code looking for weirdness in your code, like having a function declared as a boolean true/false only ever returning true - that sounds wrong.

Learning to code without tools like this is generally a good idea, though. In my opinion. Tooling can only get you so far.

A better answer to your question is unit testing. Write some code to check that your code does what it should. Test driven development is a branch of software engineering dedicated to using tests every step of the way when developing code - write a test, write some code until the test works, do it again until your test verifies that your code does what it should. A very good habit to get into quicky.

Ahh. I'm rambling. Now back to... coding.

IDE

Tor,  09.04.13 20:49

After having tried Visual Studio for about a month, I have to agree that it has some nice features, though they don't seem to work very well with languages for grown ups, such as fortran. However, I'm still leaning towards the Unix is an IDE philosophy, and I have serious problems understanding why anyone would want to pay money for Windows in the first place.

Are,  09.04.13 20:58

Well, if you had to pay for it... you might go for something else. I've never paid for Windows though - gotten it either through my uni or my employer. Microsoft is constantly in a race with open source - has to offer enough value to keep organizations away from free alternatives.

I wouldn't mind using Linux - but I would need a little while to learn the OS properly and become as effective as I am on Windows.

"Language for grown ups" indeed - I guess pretty much the programming equivalent of a "Vi over 60" subscription ;)
Tor,  09.04.13 21:33

I was actually thinking of companies and universities. It's completely beyond me how large organisations keep showeling out millions for mediocre software. As I see it, the value of Windows doesn't have anything to do with Windows itself, but rather the cost of the transition away from it.

It seems to be a trend, though, that a lot of software for economy, collaboration, sharing documents and so on, is written to be used in a browser. I guess as soon as an average employee can do all or most of their work in Firefox, there is no reason to stick with Windows.

Regarding fortran, I think there is a reason it is still commonly used in computational science, and it's not only because of history and resistance to change. I'm learning C++ now, by the way, and today I actually had to look at an Excel Macro written in Visual Basic, so in a few months, I should have a more informed opinion on the merits of various languages.

Also "Vi over 60" sounds like a evening group at the local school, aiming to teach the elderly how to use an editor.
Are likes this

Ole Petter,  09.04.13 22:33

I'm actually pretty satisfied with Windows these days, I even bought Windows 8 a while back (and I don't regret it), and Windows (7) at work works pretty well. It does what it's supposed to do in a clean and stable way.

After using OSX for two years I am not really that impressed, I still (mildly) prefer Windows. Don't get me started on IOS though...

As for programming: Avoid too much automation or too many warnings (you'll end up ignoring them), never trust your code (especially if it runs on the first try): always test. Since you already know LaTeX, maybe an interesting project might be to use python to automatically make some LaTeX stuff? Also I guess regular expressions should be on the todo list? (and afterwards you could buy the relevant xkcd t-shirt).
Are likes this

Wow

Tor,  10.04.13 18:24

I have a hard time seeing how anyone can (even mildly) prefer Windows over OS X. Granted, OS X has some issues, but surely Windows has some pretty annoying ones as well. And if you live a large part of your life in the command line, OS X is miles ahead of Windows in my opinion. Of course, linux is even further ahead, and gaining ground since Apple stopped supporting GCC (though they now support clang, so if you don't care about fortran, you're fine. However, compiling scipy includes compiling a lot of fortran code, and scipy from macports no longer passes all the tests).

Are,  10.04.13 18:57

Tor, I won't repeat myself, but scroll down: http://arewold.wordpress.com/category/os-x/

Most important one for me - Windows has better keyboard support. OSX is way too much mouse driven.

Ole Petter,  10.04.13 20:05

Tor, have you used Windows lately? I can understand your revulsion to older versions of Windows, but (IMHO) 7 and 8 are quite ok. I guess the commandline-stuff is better in OSX (but what about Powershell in Windows?); I have Linux available through virtualbox and remote desktop, and that works for me.

BTW: What do you think the present (D&D) alignment of Apple is? I vote for "neutral evil".
Tor likes this

Tor,  10.04.13 22:23

Currently using Windows 7 at work. Last time I used Windows it was XP, so I completely skipped Vista. I've only used it for a month, and I try to escape to my virtual linux box as often as I can, but it's started annoying me already. I don't have a lot of good examples, though, except a general feeling of unfinishedness. For example, I tried changing the keyboard layout under input methods, which seems the sensible place for it. This turns out to be on a per window basis, which is a bit annoying. After a bit of googling, I find out that to actually change the keyboard layout globally, I have to go to regional settings. Which I guess makes at least some sense in general, though not in my case since dvorak isn't a region, but why not have it in input methods?

Actually, I think I'll start keeping a list.

I tried powershell, but it seemed like it wanted to be linux, even though it isn't. I'm using cygwin instead, but of course that's just another way to pretend you're using linux.

Regarding keyboard shortcuts, it may well be the case that they're better supported in Windows (though ctrl + return is definitely set to 'Send' in Outlook, and it does nothing), but again, you don't really need them if you work a lot in the terminal, and with Quicksilver you can do a lot of other stuff as well. Still, there are things you can't do easily with a keyboard shortcut in Mac OS X. Which is actually a bit weird, as Apple seem to pride themselves on their universal accessibility stuff.

And Apple is definitely neutral evil. Microsoft is more chaotic evil, if I remember my D&D correctly.

Are,  11.04.13 08:07

Ctrl+Enter is supposed to ask you whether you want to use it for sending the first time you use it. If you answer no, then it won't do much. Perhaps it's just turned off in your preferences? Should be google-able.
Tor,  11.04.13 09:20

I couldn't do find it. It didn't ask the first time I tried, and it's definitely turned on in the options. You're my hero if you can find out.

Also:

List of annoying things in Windows 7


1: The fact that it restarts itself to install updates with only 15 minutes warning, and that this happens regularly. The Mac Mini in my office at the university had an uptime of 140 days when I switched it off to take it home.

Are,  11.04.13 09:25

Did you try googling something like this? Google query which didn't look so good when I just pasted it here Looks like you might need to change something in the registry, which shouldn't pose much of a problem to a hardcore superuser such as yourself.

As for the updates thing, the "delay by 4 hours" option is your friend. Also, the problem is really that your corporate setup mandates very frequent updates resulting in the frequent reboots. I very rarely reboot my private Win7 machine.

BTW - my biggest issue with Win7 is the overuse of fancy visuals, bluish transparency and the like. I much prefer the cleaner Win8 visual language - on Win8, you of course get the 7 and 8 mixed together. Win8 will be very nice eventually - I do have it on my living room machine - but it's very unstable.
Tor,  11.04.13 20:53

Do you even read your own posts? You're actually defending Windows, which is a piece of software from a major corporation, for which enormous amounts of money is paid, which came out half a year ago, and which is "very unstable", but you still think it's going to be very nice eventually? Why not go for something which is very nice and very stable today, and also free?

Delay for 4 hours is all well and good, except if you're away from your computer when the 15 minute warning pops up. I watched, with a mix of horror and fascination, as it brutally killed my virtual box about a second after sending the shutdown signal. Also, note that I did install system updates during the 140 days of uptime on my Mac, it's just that you don't have to reboot it every time. And Windows 7 is two years older than OS X 10.8, and so should presumably be a more mature OS?

Thanks for the tip about the registry. I've already used regedit to remap my Caps lock key to Ctrl, which was actually sort of fun, so I'll look into it.
Camilla likes this

Ole Petter,  11.04.13 21:15

Windows 8 is pretty stable (i.e. as stable as OSX) in my 'puter. Try comparing Finder in OSX to Explorer in Windows and you can tell me which major corporation should be embarrassed... Though I guess OSX wins on uptime, I hadn't thought of it since I reboot every day :)
Are likes this

Are,  12.04.13 13:23

Apple is at least as much a monopoly as Microsoft, and a bit worse when it comes to closing off their ecosystems and devices. I'd also like to echo Ole Petter's comment on the Finder (what? I can't cut'n paste a file? what? "enter" defaults to "rename", not "open"?).

As for stability, I seem to recall you being less than positive on the latest versions of OS X. With complex software, it's always nice to wait for the first service pack if you can, the .1 release, and let someone else do the heavy testing. Could be the Win8 problems I've had are the fault of Asus as much as MS, though.

My Win7 machine doesn't automatically reboot itself, I have to say OK first - again, that's up to your IT dept.

I'd say it doesn't make a huge difference which OS you use. For me, keyboard shortcuts give Windows the edge, and as long as I build .NET apps, I doubt any IDE on Linux can compete with Visual Studio. But if I was doing a less MS-centric language, I could well run Ubuntu or something similar. I don't see any reason to, though, as long as Windows is free for me and the tools match my needs.

I guess you could make a philosophical argument in favour of supporting an open, free platform over a closed-source semi-monopolistic one - but in that case, you should get off your iPhone and run something Linux-based on it instead. (Maybe Sailfish?)

Thankfully, the exact platform we're using matters less and less - more apps will run on the web in the future, and switching away from proprietary tech in government etc will be easier (thus saving us tax money).
Tor,  14.04.13 22:57

Perhaps it's time to wrap up this discussion? I admit that Apple are evil and annoying, that Finder could have been better (though why do you need Finder when you have the terminal?) and that OS X 10.8 previously kernel panicked whenever I closed a MacVim window containing a sizeable LaTeX document (though only on one of my two Macs). However, I still find Windows to be a more annoying product, and my opinion at the moment is that Mac provides a reasonable mix of stability, smoothness and a unix environment. I've been leaning more and more towards linux, though, so this may change in the future.

I still find it surprising that you defend Windows. It may be free for you, but what about the cost to society? And whenever we discuss phones, you prefer Android over iOS for what I perceive to be idealistic reasons, so why aren't you a linux man?

Of course I understand that if you happen to be developing .NET, it makes a certain amount of sense to use Windows. (Though this didn't neccessarily have to be the case. I've heard that Microsoft developed a version control system for Visual Studio which was so bad they didn't even use it themselves.) The point I was trying to make at the beginning of the discussion was that people shouldn't be developing .NET apps in the first place.

In any case, this entire discussion is somewhat off topic, as the point of the article was that Camilla is learning to code. Good work, Camilla!
Camilla likes this

Are,  15.04.13 07:50

Felt I wrapped it up with my previous post ;)
Category
Technology
Tags
python
programming
Views
5020
Last edited by
Camilla, 04.06.13 10:26