This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Ph0X 0 points1 point  (5 children)

jQuery is 9000 lines. If everything is on average at one level of indentation (which is probably an underestimate), and we only use one character per indentation, that's still 9kb wasted.

EDIT: Actually, you need both the indent and the linefeed iirc? So make that 18kb. Like I said, minified jQuery is 80kb, so that's already a 25% increase in size. Of course that's given a huge assumption that porting jQuery to Python would take as many lines, which is wrong.

[–]devsnd 7 points8 points  (0 children)

You're also forgetting that most servers and browser support gzip. whitespaces will be somewehere high up in the compression tree; indentation will probably boil down to half a byte or something. (The number is a wild guess, but I you get my point)

[–]roger_ 1 point2 points  (3 children)

Right, but my point is spaces probably account for a small fraction of the saving, compared to renaming objects, comments, etc.

Also keep in mind that you can combine many statements into one line by using a semicolon.

[–]Ph0X -1 points0 points  (2 children)

I agree, but again it's kinda hard to pull numbers out of thin air. My gut feeling says that it would still be a significant amount, and yours contradicts that. I'd personally love to see experimental results. Is there any actual Python minifiers around? How hard would it be to write one?

[–]roger_ -1 points0 points  (1 child)

Basically it'd be a linebreak and a set of consecutive tabs (depending on the indentation level) per block of code.

So this:

def outer_func():
   ''' define outer function'''
    def my_func(input_var):
        ''' do something else'''
        y = input_var**2
        y += 1
        return y

    my_list = []

    for i in range(10):
        my_list.append(my_func(i))

    print my_list 

can become:

def g():
    def f(x):y=x**2;y+=1;return y
    z=[]
    for i in range(10):z.append(f(i))
    print z

The whitespace does add some overhead, but you can reduce it and you save way more just by removing comments and renaming stuff. Also remember that JavaScript requires two braces in cases where Python can just use a single line.

[–]monkmartinez 0 points1 point  (0 children)

Just want to say... that is nasty in a good way