News for hackers. Stuff that matters.
Re:Reworder – A tale of learning Python and launching an app... by Luyt on Tuesday October 26, 2010 @06:22PM (#1836384)
make sure you use tabs to format all of your Python code

I disagree. Idiomatic Python uses 4 spaces per indent.

Either solely use tabs or solely use spaces, they don’t work well together, at least in my experience

Mixing tabs and spaces is indeed very unwise. You can run Python with the -tt option to make sure you're consistent.

Read Style Guide for Python Code for more advice on this front

I agree ;-) The author probably refers to PEP8, http://www.python.org/dev/peps/pep-0008/

Re:Reworder – A tale of learning Python and launching an app... by bwooceli on Tuesday October 26, 2010 @09:17PM (#1836855)
Could not agree more!!!! If you're a vimmy, be sure to add this friendly helper into your .vimrc

:set tabstop=4

:set shiftwidth=4

:set expandtab

Re:Reworder – A tale of learning Python and launching an app... by mattdawson on Wednesday October 27, 2010 @12:25AM (#1837248)
Or, if you only want to use these settings for python files, create a ~/.vim/ftplugin/python.vim file. Mine looks like this:

  setlocal tabstop=4
  setlocal softtabstop=4
  setlocal shiftwidth=4
  setlocal textwidth=80
  setlocal smarttab
  setlocal expandtab
  setlocal smartindent
Re:Reworder – A tale of learning Python and launching an app... by whimsy on Wednesday October 27, 2010 @05:27AM (#1837884)
Today I learned...

Thanks.

It looks like ftplugin is a native vim extension - is that correct?

Re:Reworder – A tale of learning Python and launching an app... by mattdawson on Thursday October 28, 2010 @12:45PM (#1843627)
I'm a bit late in responding, but yes, it's a native vim extension. To make sure your plugins are loaded automatically, put

  filetype plugin on
in your .vimrc.
Re:Reworder – A tale of learning Python and launching an app... by shortlived on Tuesday October 26, 2010 @08:35PM (#1836769)
I was fixing a makefile the other day with a coworker and it ended up being an indentation issue. And then we asked out loud why anyone would repeat this hell again...

Now, I am not a python programmer, but I am interested to learn more about how the structure via indentation how worked out for the language.

Re:Reworder – A tale of learning Python and launching an app... by sahillavingia on Tuesday October 26, 2010 @06:47PM (#1836464)
Ah yes, I'll read more into it! thanks :)
Re:Reworder – A tale of learning Python and launching an app... by gurraman on Tuesday October 26, 2010 @07:44PM (#1836633)

  Traceback (most recent call last):
    File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 513, in __call__
      handler.post(*groups)
    File "/base/data/home/apps/reworder/1.345779356045891791/reworder.py", line 122, in post
      headers={'Content-Type': 'application/x-www-form-urlencoded'}).content)
    File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/utils/simplejson/__init__.py", line 232, in loads
      return cls(encoding=encoding, **kw).decode(s)
    File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/utils/simplejson/decoder.py", line 251, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/utils/simplejson/decoder.py", line 270, in raw_decode
      raise ValueError("No JSON object could be decoded")
  ValueError: No JSON object could be decoded
Entered text "this is a test." and hit submit.
Re:Reworder – A tale of learning Python and launching an app... by sahillavingia on Tuesday October 26, 2010 @08:08PM (#1836696)
Figured out the bug: hit the API request limit. Argh!
Re:Reworder – A tale of learning Python and launching an app... by colbyolson on Tuesday October 26, 2010 @06:59PM (#1836503)

    Traceback (most recent call last):
      File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 513, in __call__
        handler.post(*groups)
      File "/base/data/home/apps/reworder/1.345779356045891791/reworder.py", line 140, in post
        synonym = synonym_for_word(stripped_word, tag)
      File "/base/data/home/apps/reworder/1.345779356045891791/reworder.py", line 201, in synonym_for_word
        return result.get(word_type)['syn'][0]
    KeyError: 'syn'
Re:Reworder – A tale of learning Python and launching an app... by olalonde on Tuesday October 26, 2010 @07:46PM (#1836638)
Hence, Teach Yourself Programming in Ten Years[1]. All kidding aside, I'm pretty sure it's unrelated to the actual code :)

[1] http://norvig.com/21-days.html

Re:Reworder – A tale of learning Python and launching an app... by itsnotvalid on Wednesday October 27, 2010 @12:43AM (#1837287)
"I was already pretty dead set on learning a functional language (either Python or Ruby)"

Did I see something strange here?

Re:Reworder – A tale of learning Python and launching an app... by rimantas on Wednesday October 27, 2010 @05:26AM (#1837882)
He meant javscript. A common typo.
Re:Reworder – A tale of learning Python and launching an app... by Jach on Wednesday October 27, 2010 @05:34AM (#1837901)
Eh? How is Javascript any more functional than Python or Ruby?
Re:Reworder – A tale of learning Python and launching an app... by josephcooney on Tuesday October 26, 2010 @10:07PM (#1836961)
He said he wanted to learn a functional language, and then listed Python and Ruby. Weird.
Re:Reworder – A tale of learning Python and launching an app... by moconnor on Wednesday October 27, 2010 @04:27AM (#1837778)
It's an easy mistake to make - when you come from a Java or C# background one of the most striking things about Python and Ruby code is the use of first-class functions.

Not everybody knows that there's more to a functional language than first-class functions.

Re:Reworder – A tale of learning Python and launching an app... by sahillavingia on Wednesday October 27, 2010 @12:48AM (#1837293)
There's a joke here I don't get. Care to explain? :D
Re:Reworder – A tale of learning Python and launching an app... by Nate75Sanders on Wednesday October 27, 2010 @01:29AM (#1837383)
Python and Ruby aren't functional languages.

You can write code in them in a functional manner, but for anything more than toy programs you _likely_ wouldn't.

They're heavily Object-Oriented, but could probably safely be called multi-paradigm. Not just "functional", though.

Functional languages are Haskell, ML, others, where you express computation by composing functions (in the mathematical sense). You make lots of copies and you don't modify state directly like procedural and OO languages do where you modify state a lot.

Re:Reworder – A tale of learning Python and launching an app... by meric on Wednesday October 27, 2010 @03:53AM (#1837713)
I remember it took me a dozen times of carefully reading explanations like this before I finally got what "functional" meant... I'll try to provide an explanation my former self would have easily got.

  lambda x: x+1 
If you only program with lambda's like these, your program is functional.

  def dosomething(x):
      y = x + 3 # y is a global variable
      return x + 1
As soon as you have a function like this, your program is no longer 100% functional.

The dosomething function modified `state` when it changed a global variable. Another function that modifies state is "print()". Generally any function that returns nothing is almost certainly going to modify state outside of it. (Otherwise what is the function for?)

State is memory that is not `local` to the function itself.

  def dosomething(x):
      y = x + 3 # y is a local variable
      return x + 1
The dosomething function here is functional, because the only `state` it modified was local to the function.

There you have it.

Re:Reworder – A tale of learning Python and launching an app... by mixu on Wednesday October 27, 2010 @05:34AM (#1837902)
Even more simply - are you writing code for a von Neumann architecture (http://en.wikipedia.org/wiki/Von_Neumann_architecture ), or something more abstract?

To my understanding the issue is not whether "state" has side effects (e.g. your global vs. local example), but rather whether there is any concept of "state" (e.g. shuffling stuff from one memory slot to another).

My experience is from Prolog, where the statement "X is X + 1" results in an error, because once unified, the variable X cannot be modified - X is not a memory slot. Once you try to let go of the idea of a machine with memory slots, alternative-paradigm programming gets a little bit easier. Of course in practice state is often needed, so it often gets added through some mechanism.

Re:Reworder – A tale of learning Python and launching an app... by meric on Wednesday October 27, 2010 @06:13AM (#1837971)
That's a good explanation.

My explanation is catered to people accustomed to the von Neumann architecture, however. :)

Re:Reworder – A tale of learning Python and launching an app... by torme on Tuesday October 26, 2010 @06:35PM (#1836427)
Completely unrelated to your write up but theres a bug. In FF if I back up and resubmit it doesn't update to the new text. I still see my first submission.
Re:Reworder – A tale of learning Python and launching an app... by sahillavingia on Tuesday October 26, 2010 @06:50PM (#1836472)
Ah yes, I randomly generate a permalink on load of the page, so it uses the old permalink, hence why it loads the first submission. Any ideas on how to change this?
Re:Reworder – A tale of learning Python and launching an app... by torme on Tuesday October 26, 2010 @07:02PM (#1836514)
I guess just generate the permalink in the action and redirect to that instead of having it in the form itself.

Something like:

Form: /reworder/generate

Action: Generates text, creates permalink and then redirects user to that permalink.

In the web world this pattern is common, called redirect-after-post. I'm not sure if thats much help, I've only used python in the context of the Pylons framework (and have only a few days experience with it at that). If you need more guidance let me know and I'll try and clarify.

edit: Link to redirect after post: http://en.wikipedia.org/wiki/Post/Redirect/Get

edit2: I should also say this is a pretty sweet project, sorry if I just listed criticisms.

Re:Reworder – A tale of learning Python and launching an app... by sahillavingia on Tuesday October 26, 2010 @09:52PM (#1836928)
Of course not, I love criticisms. How else do I improve? I'll implement that ASAP.
Re:Reworder – A tale of learning Python and launching an app... by smoody on Tuesday October 26, 2010 @07:26PM (#1836585)
"App engine is fast and awesome, right now. However, if your site gets really popular, you may consider moving off of it."

Perhaps you can explain why you believe this to be true? I thought that the strength of App Engine is that you can stay on it no matter how popular your app gets.

Re:Reworder – A tale of learning Python and launching an app... by sahillavingia on Tuesday October 26, 2010 @08:25PM (#1836744)
App engine doesn't allow certain features, like subdomains for each user, and non-www. URLs. Some other things too, that I probably don't even know about yet.
Re:Reworder – A tale of learning Python and launching an app... by detst on Wednesday October 27, 2010 @12:11AM (#1837220)
While I agree that there are limitations with App Engine, I disagree with your two examples; not only are these possible, I think they have a nice solution on App Engine.

1. Wildcard subdomains and multi-tenancy seem to be a nice solution to "subdomains for each user".

2. Unless by "non-www. URLs" you mean naked domains, that is also possible; both explicitly defined and with wildcard subdomains.

Maybe I'm misinterpreting you though.

Re:Reworder – A tale of learning Python and launching an app... by jscore on Tuesday October 26, 2010 @06:41PM (#1836444)
Traceback (most recent call last): File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 513, in __call__ handler.post(*groups) File "/base/data/home/apps/reworder/1.345779356045891791/reworder.py", line 140, in post synonym = synonym_for_word(stripped_word, tag) File "/base/data/home/apps/reworder/1.345779356045891791/reworder.py", line 201, in synonym_for_word return result.get(word_type)['syn'][0] KeyError: 'syn'
Re:Reworder – A tale of learning Python and launching an app... by StanDarsh on Tuesday October 26, 2010 @08:22PM (#1836733)
Awesome story. Thank you very much for the Stanford links.
Re:Reworder – A tale of learning Python and launching an app... by jacquesm on Tuesday October 26, 2010 @06:38PM (#1836434)
Hey, weren't you supposed to be a designer :) That's pretty quick to go from 0 to launch in 5 days in an unknown language.

Congratulations!

Re:Reworder – A tale of learning Python and launching an app... by sahillavingia on Tuesday October 26, 2010 @06:38PM (#1836436)
Designer, developer, coder, sleep-deprived. I'm a dude of many properties! :)
Re:Reworder – A tale of learning Python and launching an app... by paulbaumgart on Tuesday October 26, 2010 @11:35PM (#1837136)
Any input containing a forward slash results in a ValueError.
Re:Reworder – A tale of learning Python and launching an app... by davidj on Wednesday October 27, 2010 @08:21AM (#1838210)
if anyone cares, rephrasing engines are used to create splogs for SEO
Re:Reworder – A tale of learning Python and launching an app... by dgreensp on Tuesday October 26, 2010 @07:42PM (#1836625)
Breaks on apostrophes.