Re:Bootstrap 2.3 Released
by randallsquared on Friday February 08, 2013 @10:42AM
(#5188348)
> Tab vs. spaces will not cause code to break
Well, mixing them can. Python, for example.
Re:Bootstrap 2.3 Released
by robomartin on Friday February 08, 2013 @12:37PM
(#5189028)
I literally just started going through Project Euler with Python now to get comfortable with the language.
I'll play with that and see. I can't think of any other language where this might matter.
Should I look for anything in particular or simply tabs vs space in indentation on any code?
# Problems from ProjectEuler.net
# http://projecteuler.net/problem=1
def problem_1():
return sum([n for n in range(1000) if (n%3 == 0) or (n%5 == 0)])
def problem_1a():
return sum(set(range(3,1000,3) + range(5,1000,5)))
# http://projecteuler.net/problem=2
def problem_2():
sequence = [1,2]
while sequence[-1] < 4000000:
sequence.append(sum(sequence[-2:]))
if sequence[-1] > 4000000:
sequence.pop()
return sum([n for n in sequence if (n%2 == 0)])
I did say I was just getting started!I'll try the above and other code I wrote with a mixture of tabs and spaced and see what happens. Interesting. If Python actually breaks because of that it's a shame. I really like the language. Is it a matter of IDE interpreter (type code and execute interactively) vs. command-line interpreter (same as previous) vs. module execution (i.e.: "python my_module.py" from the command prompt)?
Re:Bootstrap 2.3 Released
by randallsquared on Friday February 08, 2013 @02:17PM
(#5189577)
If I recall correctly, Python's indentation counts characters, so a single tab is not the equivalent of four or eight spaces, but only one. If you accidentally mix them, therefore, lining things up visually in your editor will result in indenting or outdenting where you did not intend.
Tab vs. spaces will not cause code to break, mistyping camel case in a case sensitive language does. Neither camel case nor case sensitivity makes programming easier, better, faster, less error-prone, clearer, more accurate, et. In other words, it serves no useful purpose other than feeding a fad.
Tab vs. spaces? Don't really care. There are good reasons for going ether way. As long as the tab key does the indentation I, personally, couldn't care less which way it goes. My code will not break if I enter a bunch of spaces instead of tabs.