由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 有人用Haskell吗
相关主题
Python 缩进的syntaxMAC 下面 python 编程用什么IDE?
python的一大缺点haskell在生产环境的生产力到底如何?
请问python的多重循环怎么实现?python或pydev怎么跳到一个section的头/尾
总觉得python 用缩进定义逻辑block 这种思想很诡异python大家用什么IDE?
问一下python初学者的问题花了一个小时学习了python
Python for Data Analysis请问运行python的一些技巧。
我来说说python的优点吧correct indentation in python ?
lisperpython indentation
相关话题的讨论汇总
话题: python话题: print话题: haskell话题: code话题: f2
进入Programming版参与讨论
1 (共1页)
k***r
发帖数: 4260
1
syntax很怪,也还没搞清楚functional programming是不是个big deal
b***e
发帖数: 1419
2
The syntax is pretty normal for functional languages. The problem is that it is
alignment sensitive, which means, it MATTERS how many space/tabs you put at
the front of the line, and THAT SUCKS. Any language that is alignment
sensitive should DIE, like Haskell and Python.
w***g
发帖数: 5958
3
Haskell曲高和寡,感觉发明这个语言不是为了解决实际问题。楼主还是别折腾了。我曾
经花不少时间研究haskell的monad到底是什么意思,最后还是没有练到可以使用的水平
。fu
nctional language限制太强,以至于一般语言中很容易实现的东西都需要引入非常深奥
的数学概念才能勉强解决。functioinal language前段时间又有点抬头是因为多核处理
器和集群计算的兴起对并行语言的需求。其实是否可并行化是由问题本身决定的。有些
问题本质上不可并行,用functional language即使极其艰难地实现了其实还是不能并行
的。
我同意python should DIE。haskell从来就没正经活过。

it is
at

【在 b***e 的大作中提到】
: The syntax is pretty normal for functional languages. The problem is that it is
: alignment sensitive, which means, it MATTERS how many space/tabs you put at
: the front of the line, and THAT SUCKS. Any language that is alignment
: sensitive should DIE, like Haskell and Python.

k***r
发帖数: 4260
4
@blaze, @wdong,
I actually like Python very much. After you get pass the first
period, the indentation makes thing easier and you type less.
Among the languages I have used for any actual projects, Python
has been the most productive language for me when I need to
quickly get something done.
Even so, Haskell looks very foreign to me. wdong's comment
gives me a good perspective of the language in terms of the
shift to functional programming but remarks like python should
die has somewhat discount
n******t
发帖数: 4406
5

it is
at
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Can not agree more on this point. Anyone who got this idea must have
some brain damages.

【在 b***e 的大作中提到】
: The syntax is pretty normal for functional languages. The problem is that it is
: alignment sensitive, which means, it MATTERS how many space/tabs you put at
: the front of the line, and THAT SUCKS. Any language that is alignment
: sensitive should DIE, like Haskell and Python.

c*****t
发帖数: 1879
6
At least that's better than spending 5 minutes just to count () again
and again for a line of code in lisp. That's a quantum leap in term
of readability for sure :P

it is
at

【在 b***e 的大作中提到】
: The syntax is pretty normal for functional languages. The problem is that it is
: alignment sensitive, which means, it MATTERS how many space/tabs you put at
: the front of the line, and THAT SUCKS. Any language that is alignment
: sensitive should DIE, like Haskell and Python.

b***e
发帖数: 1419
7
Unfair comments. There're well many other functional languages that have "
normal" syntax, like ML/Caml/Ocaml. Why does Haskell have to be the asshole? As for lisp, any paren-matching tool in modern editors will help, e.g., emacs/vim.

【在 c*****t 的大作中提到】
: At least that's better than spending 5 minutes just to count () again
: and again for a line of code in lisp. That's a quantum leap in term
: of readability for sure :P
:
: it is
: at

k***r
发帖数: 4260
8
i don't know much about these languages. haskell could be more
mature than the other languages because i've seen people who came from
ocaml to haskell...maybe there's some advantages to it.

asshole? As for lisp, any paren-matching tool in modern editors will help,
e.g., emacs/vim.

【在 b***e 的大作中提到】
: Unfair comments. There're well many other functional languages that have "
: normal" syntax, like ML/Caml/Ocaml. Why does Haskell have to be the asshole? As for lisp, any paren-matching tool in modern editors will help, e.g., emacs/vim.

b***e
发帖数: 1419
9

我曾
fu
深奥
并行
哈哈, 这个高!
不过话说回来, Haskell作为language本身我并不看好, 但是有它而来的一些design
patterns确是值得借鉴的. 比如说这个monad, 做domain specific language
interpretation正好是物尽其用.

【在 w***g 的大作中提到】
: Haskell曲高和寡,感觉发明这个语言不是为了解决实际问题。楼主还是别折腾了。我曾
: 经花不少时间研究haskell的monad到底是什么意思,最后还是没有练到可以使用的水平
: 。fu
: nctional language限制太强,以至于一般语言中很容易实现的东西都需要引入非常深奥
: 的数学概念才能勉强解决。functioinal language前段时间又有点抬头是因为多核处理
: 器和集群计算的兴起对并行语言的需求。其实是否可并行化是由问题本身决定的。有些
: 问题本质上不可并行,用functional language即使极其艰难地实现了其实还是不能并行
: 的。
: 我同意python should DIE。haskell从来就没正经活过。
:

n******t
发帖数: 4406
10
学Haskell我的感觉是,绝对比C,C++之类的东西简单。
欧洲很多大学计算机系一年级第一门语言就是haskell,
这里面还N多,非计算机专业的副修学生。
当然设计这么一个语言是另外一回事。

我曾
fu
深奥
并行

【在 w***g 的大作中提到】
: Haskell曲高和寡,感觉发明这个语言不是为了解决实际问题。楼主还是别折腾了。我曾
: 经花不少时间研究haskell的monad到底是什么意思,最后还是没有练到可以使用的水平
: 。fu
: nctional language限制太强,以至于一般语言中很容易实现的东西都需要引入非常深奥
: 的数学概念才能勉强解决。functioinal language前段时间又有点抬头是因为多核处理
: 器和集群计算的兴起对并行语言的需求。其实是否可并行化是由问题本身决定的。有些
: 问题本质上不可并行,用functional language即使极其艰难地实现了其实还是不能并行
: 的。
: 我同意python should DIE。haskell从来就没正经活过。
:

相关主题
Python for Data AnalysisMAC 下面 python 编程用什么IDE?
我来说说python的优点吧haskell在生产环境的生产力到底如何?
lisperpython或pydev怎么跳到一个section的头/尾
进入Programming版参与讨论
n******t
发帖数: 4406
11

asshole? As for lisp, any paren-matching tool in modern editors will help,
e.g., emacs/vim.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is actually quite horrible too.

【在 b***e 的大作中提到】
: Unfair comments. There're well many other functional languages that have "
: normal" syntax, like ML/Caml/Ocaml. Why does Haskell have to be the asshole? As for lisp, any paren-matching tool in modern editors will help, e.g., emacs/vim.

b***e
发帖数: 1419
12
What other languages have you tried? If you can do it with python, you must
be able to do it with perl as well. It all depends on which flavor you
like. As general purpose scripting, python has nothing over perl. Well,
perl has the leading symbol trouble, but hey, I would rather live with that
rather than counting spaces/tabs, which are FUCKING literally invisible.
Most of the time, it is not the problem of getting things done quickly, but
to get things done reasonably fast and in a controll

【在 k***r 的大作中提到】
: @blaze, @wdong,
: I actually like Python very much. After you get pass the first
: period, the indentation makes thing easier and you type less.
: Among the languages I have used for any actual projects, Python
: has been the most productive language for me when I need to
: quickly get something done.
: Even so, Haskell looks very foreign to me. wdong's comment
: gives me a good perspective of the language in terms of the
: shift to functional programming but remarks like python should
: die has somewhat discount

k***r
发帖数: 4260
13
the languages I have used for real projects so far: c, c++, pascal, java,
python, php. I also tried to learn perl (a couple of times.) I personally
think python is a lot better than perl because every time i tried to learn
perl , i disliked it and gave up. I think my experienced is shared by many
given the declining number of perl users and rising number of python users.
Python has very smart design that makes it much easier (than perl) to
understand, maintain and think of a solution to a specif

【在 b***e 的大作中提到】
: What other languages have you tried? If you can do it with python, you must
: be able to do it with perl as well. It all depends on which flavor you
: like. As general purpose scripting, python has nothing over perl. Well,
: perl has the leading symbol trouble, but hey, I would rather live with that
: rather than counting spaces/tabs, which are FUCKING literally invisible.
: Most of the time, it is not the problem of getting things done quickly, but
: to get things done reasonably fast and in a controll

w***g
发帖数: 5958
14
我不喜欢python的理由是python那批人打着反对premature optimization为理由编写劣
质代码,并且到处reimplement wheels。其中最典型的就是python解释器。同为解释型
或半解释型语言,python在速度上要比perl或者java慢一个数量级。我不知道除了不做
"premature optimization"以外还有别的任何理由能把一个解释器做的如此之慢。

【在 k***r 的大作中提到】
: the languages I have used for real projects so far: c, c++, pascal, java,
: python, php. I also tried to learn perl (a couple of times.) I personally
: think python is a lot better than perl because every time i tried to learn
: perl , i disliked it and gave up. I think my experienced is shared by many
: given the declining number of perl users and rising number of python users.
: Python has very smart design that makes it much easier (than perl) to
: understand, maintain and think of a solution to a specif

r****t
发帖数: 10904
15
java 怎么算解释的?。解释器慢又是怎么比较的,你要是用 perl 实现和 python
object 等价的 object, 再来和对应的 python code 比较速度,没理由 perl 能执行
的快。oo has a cost as its overhead, oo scripting language 里面 python 不算
是慢的。
能举几个例子说下 in python, which wheels are unnecessary re-implementations?

【在 w***g 的大作中提到】
: 我不喜欢python的理由是python那批人打着反对premature optimization为理由编写劣
: 质代码,并且到处reimplement wheels。其中最典型的就是python解释器。同为解释型
: 或半解释型语言,python在速度上要比perl或者java慢一个数量级。我不知道除了不做
: "premature optimization"以外还有别的任何理由能把一个解释器做的如此之慢。

t****t
发帖数: 6806
16
我老人家料到你会出来
别的不知道, 不过java应该算是个半解释的语言吧, 有些hotspot有编译而已

implementations?

【在 r****t 的大作中提到】
: java 怎么算解释的?。解释器慢又是怎么比较的,你要是用 perl 实现和 python
: object 等价的 object, 再来和对应的 python code 比较速度,没理由 perl 能执行
: 的快。oo has a cost as its overhead, oo scripting language 里面 python 不算
: 是慢的。
: 能举几个例子说下 in python, which wheels are unnecessary re-implementations?

s******n
发帖数: 876
17
if you want slow speed, use Ruby, hehe

implementations?
写劣
释型
不做

【在 r****t 的大作中提到】
: java 怎么算解释的?。解释器慢又是怎么比较的,你要是用 perl 实现和 python
: object 等价的 object, 再来和对应的 python code 比较速度,没理由 perl 能执行
: 的快。oo has a cost as its overhead, oo scripting language 里面 python 不算
: 是慢的。
: 能举几个例子说下 in python, which wheels are unnecessary re-implementations?

n******t
发帖数: 4406
18
现在我怀疑goodbug会跳出来了。hehe

【在 t****t 的大作中提到】
: 我老人家料到你会出来
: 别的不知道, 不过java应该算是个半解释的语言吧, 有些hotspot有编译而已
:
: implementations?

g*****g
发帖数: 34805
19
thrust对java的描述没有错。

【在 n******t 的大作中提到】
: 现在我怀疑goodbug会跳出来了。hehe
k***r
发帖数: 4260
20
I'm not sure about Perl. Is Perl really that much faster than Python?
I haven't used it myself but the benchmark data doesn't say so:
http://xodian.net/serendipity/index.php?/archives/27-Benchmark-PHP-vs.-Python-vs.-Perl-vs.-Ruby.html
Python is said to be slower than Java. I think Java benefits a lot
from its JIT compiler, in which case the code is indeed compiled.
Psyco makes portion of Python code a few times faster. But I think
performance is to some extent irrelevant to the discussions here.

【在 w***g 的大作中提到】
: 我不喜欢python的理由是python那批人打着反对premature optimization为理由编写劣
: 质代码,并且到处reimplement wheels。其中最典型的就是python解释器。同为解释型
: 或半解释型语言,python在速度上要比perl或者java慢一个数量级。我不知道除了不做
: "premature optimization"以外还有别的任何理由能把一个解释器做的如此之慢。

相关主题
python大家用什么IDE?correct indentation in python ?
花了一个小时学习了pythonpython indentation
请问运行python的一些技巧。python有快速loop over dict的方法吗?
进入Programming版参与讨论
d***q
发帖数: 1119
21
貌似ruby 1.9已经不慢了。
perl 6 的compiler似乎是用haskell写的。
r*******n
发帖数: 3020
22
I like Python, too.
I started using Python in company in 2005,
and never got into the trouble of spaces/tab problems,
actually, the indentation makes the programs look NEAT.
A another advantages are that it's so productive and
has a lot of libraries.
It's true which language you like depends on who you are,
but Python works very well for me,
by the way, I don't like perl, either, because of its symbols system.

【在 k***r 的大作中提到】
: the languages I have used for real projects so far: c, c++, pascal, java,
: python, php. I also tried to learn perl (a couple of times.) I personally
: think python is a lot better than perl because every time i tried to learn
: perl , i disliked it and gave up. I think my experienced is shared by many
: given the declining number of perl users and rising number of python users.
: Python has very smart design that makes it much easier (than perl) to
: understand, maintain and think of a solution to a specif

b***e
发帖数: 1419
23
貌似是interpreter prototype.

【在 d***q 的大作中提到】
: 貌似ruby 1.9已经不慢了。
: perl 6 的compiler似乎是用haskell写的。

p***o
发帖数: 44
24
当然是个big deal
学了Haskell之后你会发现你甚至对Java和其他语言的的理解更加深刻了

【在 k***r 的大作中提到】
: syntax很怪,也还没搞清楚functional programming是不是个big deal
p***o
发帖数: 44
25
Significant indentation really sucks, because you won't be able to
automatically reformat your code in your editor. It's not because the editor
is not powerful enough. It's just impossible! The syntax is aimed to make
the language clean looking, but it causes more trouble than this minor
benefit.
But Haskell is too great a language to ignore, despite of this "defect
". I'm really sad to have to put up with its syntax.

it is
at

【在 b***e 的大作中提到】
: The syntax is pretty normal for functional languages. The problem is that it is
: alignment sensitive, which means, it MATTERS how many space/tabs you put at
: the front of the line, and THAT SUCKS. Any language that is alignment
: sensitive should DIE, like Haskell and Python.

k***r
发帖数: 4260
26
I don't think it's a problem for Python, though.

editor

【在 p***o 的大作中提到】
: Significant indentation really sucks, because you won't be able to
: automatically reformat your code in your editor. It's not because the editor
: is not powerful enough. It's just impossible! The syntax is aimed to make
: the language clean looking, but it causes more trouble than this minor
: benefit.
: But Haskell is too great a language to ignore, despite of this "defect
: ". I'm really sad to have to put up with its syntax.
:
: it is
: at

b***e
发帖数: 1419
27
Oh, really? How would that be?
If you mean Java Generics (which is new and ugly BTW), then Haskell probably
helps a little bit. But for the major OO concept, I don't see any help
from Haskell. Haskell does not have any OO, which determines its doomed
destiny.

【在 p***o 的大作中提到】
: 当然是个big deal
: 学了Haskell之后你会发现你甚至对Java和其他语言的的理解更加深刻了

w***g
发帖数: 5958
28
perl is really much (an order of magnitude, I would say) faster than python
in string processing. The benchmark you posted is too simple to tell someth
ing practical.
(Two test programs were measured:
Hello - Prints "Hello World" to stdout.
Inc - Increments a variable, starting at 0.
Each program does one-million iterations, and is run ten consecutive times.)

【在 k***r 的大作中提到】
: I'm not sure about Perl. Is Perl really that much faster than Python?
: I haven't used it myself but the benchmark data doesn't say so:
: http://xodian.net/serendipity/index.php?/archives/27-Benchmark-PHP-vs.-Python-vs.-Perl-vs.-Ruby.html
: Python is said to be slower than Java. I think Java benefits a lot
: from its JIT compiler, in which case the code is indeed compiled.
: Psyco makes portion of Python code a few times faster. But I think
: performance is to some extent irrelevant to the discussions here.

n*w
发帖数: 3393
29
我上次把一个perl的简单的text file parser改成python,快了接近十倍。

python
someth
.)

【在 w***g 的大作中提到】
: perl is really much (an order of magnitude, I would say) faster than python
: in string processing. The benchmark you posted is too simple to tell someth
: ing practical.
: (Two test programs were measured:
: Hello - Prints "Hello World" to stdout.
: Inc - Increments a variable, starting at 0.
: Each program does one-million iterations, and is run ten consecutive times.)

l********g
发帖数: 134
30
maybe just because of pyc.

【在 n*w 的大作中提到】
: 我上次把一个perl的简单的text file parser改成python,快了接近十倍。
:
: python
: someth
: .)

相关主题
jun rao说kafka已经开始用Java代码重写部分code了python的一大缺点
python自动缩进出错 快疯了请问python的多重循环怎么实现?
Python 缩进的syntax总觉得python 用缩进定义逻辑block 这种思想很诡异
进入Programming版参与讨论
n******t
发帖数: 4406
31
There should be some "funny" part in your perl code.

【在 n*w 的大作中提到】
: 我上次把一个perl的简单的text file parser改成python,快了接近十倍。
:
: python
: someth
: .)

p***o
发帖数: 44
32
I'm certainly talking about major OO concept: polymorphism, inheritance etc.
Java Generics really sucks. In fact many things are wrong with Java, but it
did something better than Python.
Essentially Haskell has OO, but only if you understand what OO really means.
Have you tried CLOS? That gives you a better idea what is OO.
But who told you that OO(in its conventional meaning) is the best way to do
things? I think the normal OO languages you use nowadays are doomed,
because "everything is an obj

【在 b***e 的大作中提到】
: Oh, really? How would that be?
: If you mean Java Generics (which is new and ugly BTW), then Haskell probably
: helps a little bit. But for the major OO concept, I don't see any help
: from Haskell. Haskell does not have any OO, which determines its doomed
: destiny.

p***o
发帖数: 44
33
Can you automatically reindent a block of code after you move it to a
different level? Can you delete a block of code by just one key stroke?

【在 k***r 的大作中提到】
: I don't think it's a problem for Python, though.
:
: editor

k***r
发帖数: 4260
34
I believe this depends on the implementation of an IDE.
There is no reason you couldn't. And the rules are easy -
just add or remove a number of spaces/tabs at the beginning
of a line.
With indentation, it's not that there will be a fuzzy boundary
between code blocks. It's a clearly defined boundary
signified by indentation, instead of curly brackets.

【在 p***o 的大作中提到】
: Can you automatically reindent a block of code after you move it to a
: different level? Can you delete a block of code by just one key stroke?

g*****g
发帖数: 34805
35
The point is that you have to manually maintain indentation.
While when you use curly brackets, you can use a formatter
to format the code based on your preferred template (Eclipse
has this feature). Therefore, all the source code can have
the same style no matter how it is originally written.
Consider this python example, all 3 are equal.
>>> if 1 + 1 == 2:
... print "foo"
... print "bar"
... x = 42
>>> if 1 + 1 == 2:
... print "foo"; print "bar"; x = 42
>>> if 1 + 1 == 2: print

【在 k***r 的大作中提到】
: I believe this depends on the implementation of an IDE.
: There is no reason you couldn't. And the rules are easy -
: just add or remove a number of spaces/tabs at the beginning
: of a line.
: With indentation, it's not that there will be a fuzzy boundary
: between code blocks. It's a clearly defined boundary
: signified by indentation, instead of curly brackets.

k***r
发帖数: 4260
36
I don't see why it has to be "manual", and I don't see why
a formatter wouldn't work. It's questionable if a good python
formatter has been implemented but I don't see anything that
prevents that from happening.
Yes, you can do:
if 1 + 1 == 2: print 'foo'; print 'bar'
The language syntax parser is able to determine that it's
equivalent to:
if 1 + 1 == 2:
print 'foo'
print 'bar'
So if you choose a template, it should be able to format it that way.
Once the syntax is parsed, the AST in mem

【在 g*****g 的大作中提到】
: The point is that you have to manually maintain indentation.
: While when you use curly brackets, you can use a formatter
: to format the code based on your preferred template (Eclipse
: has this feature). Therefore, all the source code can have
: the same style no matter how it is originally written.
: Consider this python example, all 3 are equal.
: >>> if 1 + 1 == 2:
: ... print "foo"
: ... print "bar"
: ... x = 42

g*****g
发帖数: 34805
37
With an explicit block marker like bracket, you don't need
compilation information to format the code. Eclipse formatter,
for one, can format the code well even if tons of compilation
errors exist. That's very helpful when you are doing some
copy and paste. Sometimes I copy a piece of code from web, and
integrate with my partial class, the formatting
is aweful due to web nature, the open and close bracket may not
match at all, there are often typo and other mess inside. Yet a
quick format and yo

【在 k***r 的大作中提到】
: I don't see why it has to be "manual", and I don't see why
: a formatter wouldn't work. It's questionable if a good python
: formatter has been implemented but I don't see anything that
: prevents that from happening.
: Yes, you can do:
: if 1 + 1 == 2: print 'foo'; print 'bar'
: The language syntax parser is able to determine that it's
: equivalent to:
: if 1 + 1 == 2:
: print 'foo'

k***r
发帖数: 4260
38
When there are compilation errors, it's a matter of best effort,
no matter what language it is. I think the same is true for Python.
You can still figure out the boundaries (or the lack of it) of code
blocks. The only difference is what to look for, {} or spaces/tabs.
I think the algorithms work very similarly, if not exactly the same
way.
For all the Python IDEs I've tried, including eclipse with PyDev plugin,
all IDEs do indentation for you when you hit enter. PyDev's Python
support may not be

【在 g*****g 的大作中提到】
: With an explicit block marker like bracket, you don't need
: compilation information to format the code. Eclipse formatter,
: for one, can format the code well even if tons of compilation
: errors exist. That's very helpful when you are doing some
: copy and paste. Sometimes I copy a piece of code from web, and
: integrate with my partial class, the formatting
: is aweful due to web nature, the open and close bracket may not
: match at all, there are often typo and other mess inside. Yet a
: quick format and yo

g*****g
发帖数: 34805
39
The point is that indentation information will be lost or messed up
when you are integrating code from different sources, from
others, from a different indent level, or from web which may use
other ways to format text (CSS etc.). And certain labor is
inevitable. To compensate it, your IDE has to be much smarter than
the counterpart, whether it can be achieved is another question, but
Python is doing all this without real benefit, good enough for me to
consider a design flaw.

【在 k***r 的大作中提到】
: When there are compilation errors, it's a matter of best effort,
: no matter what language it is. I think the same is true for Python.
: You can still figure out the boundaries (or the lack of it) of code
: blocks. The only difference is what to look for, {} or spaces/tabs.
: I think the algorithms work very similarly, if not exactly the same
: way.
: For all the Python IDEs I've tried, including eclipse with PyDev plugin,
: all IDEs do indentation for you when you hit enter. PyDev's Python
: support may not be

k***r
发帖数: 4260
40
The code structure info will not be lost. It's probably a bit
more work to implement but it's doable. Let me give you an example.
Let's say you have:
def f1():
____print 'f1'
def f2():
____print 'f2'
And we want to inline f2() into f1(). You cut f2's code,
and go to f1, right after the ":", hit enter. The carret will be
indented automatically because it's inside a function. Before you
do Paste, the code looks like this:
def f1():
____<- this is where the carret is
____print f2
Then you hit "Past

【在 g*****g 的大作中提到】
: The point is that indentation information will be lost or messed up
: when you are integrating code from different sources, from
: others, from a different indent level, or from web which may use
: other ways to format text (CSS etc.). And certain labor is
: inevitable. To compensate it, your IDE has to be much smarter than
: the counterpart, whether it can be achieved is another question, but
: Python is doing all this without real benefit, good enough for me to
: consider a design flaw.

相关主题
总觉得python 用缩进定义逻辑block 这种思想很诡异我来说说python的优点吧
问一下python初学者的问题lisper
Python for Data AnalysisMAC 下面 python 编程用什么IDE?
进入Programming版参与讨论
k***r
发帖数: 4260
41
I just did a side by side comparison of java and python code.
I know it's subjective, but I find Python code is easier to read
and follow, in terms of coding style. Since you write more (maybe
10-20%, because of the savings on { and }) code lines in a page,
it's also easier to get a bigger picture of what the code is
trying to do.
The problem I have with Python is not indentations. It's dynamic
nature of types. Java compiler does catch a lot of potential
errors that Python compiler wouldn't.

【在 g*****g 的大作中提到】
: The point is that indentation information will be lost or messed up
: when you are integrating code from different sources, from
: others, from a different indent level, or from web which may use
: other ways to format text (CSS etc.). And certain labor is
: inevitable. To compensate it, your IDE has to be much smarter than
: the counterpart, whether it can be achieved is another question, but
: Python is doing all this without real benefit, good enough for me to
: consider a design flaw.

p***o
发帖数: 44
42
But
if 1 + 1 == 2:
print 'foo'
print 'bar'
is very different from
if 1 + 1 == 2:
print 'foo'
print 'bar'
How is it possible for any IDE to know what you think when you say "
autoindent" at the beginning of print 'bar'?

【在 k***r 的大作中提到】
: I don't see why it has to be "manual", and I don't see why
: a formatter wouldn't work. It's questionable if a good python
: formatter has been implemented but I don't see anything that
: prevents that from happening.
: Yes, you can do:
: if 1 + 1 == 2: print 'foo'; print 'bar'
: The language syntax parser is able to determine that it's
: equivalent to:
: if 1 + 1 == 2:
: print 'foo'

g*****g
发帖数: 34805
43
Let's say you have code
print 'f1'
print 'f2'
Now you go somewhere, copy/paste a piece of code in between, it becomes

print 'f1'
if 1+1 == 2 :
print 'f3'
print 'f2'
No matter how smart your IDE is, it must be confused when trying formatting
I really doubt you can just copy/paste without some manual indentation.
And it's certainly error-prone.

【在 k***r 的大作中提到】
: The code structure info will not be lost. It's probably a bit
: more work to implement but it's doable. Let me give you an example.
: Let's say you have:
: def f1():
: ____print 'f1'
: def f2():
: ____print 'f2'
: And we want to inline f2() into f1(). You cut f2's code,
: and go to f1, right after the ":", hit enter. The carret will be
: indented automatically because it's inside a function. Before you

k***r
发帖数: 4260
44
if you have
print 'f1'
print 'f2'
and you want to paste:
if 1+1==2:
____print 'f3'
it'll become:
print 'f1'
if 1+1==2:
____print 'f3'
print 'f2'
Note that it's not suppose to change the 'f2' line.

formatting

【在 g*****g 的大作中提到】
: Let's say you have code
: print 'f1'
: print 'f2'
: Now you go somewhere, copy/paste a piece of code in between, it becomes
:
: print 'f1'
: if 1+1 == 2 :
: print 'f3'
: print 'f2'
: No matter how smart your IDE is, it must be confused when trying formatting

g*****g
发帖数: 34805
45
You don't get it. Let's I already have
if 1+1==2:
print 'f1'
print 'f2'
And I want to insert itself in between f1 and f2
if 1+1==2:
print 'f1'
if 1+1==2:
print 'f1'
print 'f2'
print 'f2'
Compare to
if 1+1==2 {
print 'f1'
if 1+1==2 {
print 'f1'
print 'f2'
} print 'f2'
}
An auto-format will adjust the latter correctly, same thing can't
be said for python..

【在 k***r 的大作中提到】
: if you have
: print 'f1'
: print 'f2'
: and you want to paste:
: if 1+1==2:
: ____print 'f3'
: it'll become:
: print 'f1'
: if 1+1==2:
: ____print 'f3'

k***r
发帖数: 4260
46
You add or delete space/tab when necessarily, similar to what
you would do with { and }.

【在 p***o 的大作中提到】
: But
: if 1 + 1 == 2:
: print 'foo'
: print 'bar'
: is very different from
: if 1 + 1 == 2:
: print 'foo'
: print 'bar'
: How is it possible for any IDE to know what you think when you say "
: autoindent" at the beginning of print 'bar'?

g*****g
发帖数: 34805
47
I don't. In eclipse, I use Ctrl+Shift+F, and it's done automatically.
That's certainly easier and less error-prone.

【在 k***r 的大作中提到】
: You add or delete space/tab when necessarily, similar to what
: you would do with { and }.

k***r
发帖数: 4260
48
You want to insert this to itself after the f1 line:
if 1+1==2:
____print 'f1'
____print 'f2'
You hit enter after 'f1', the carret stops right below letter "p",
then you paste. It becomes:
if 1+1==2:
____print 'f1'
____if 1+1==2:
________print 'f1'
________print 'f2'
____print 'f2'
Isn't this what you want?

【在 g*****g 的大作中提到】
: You don't get it. Let's I already have
: if 1+1==2:
: print 'f1'
: print 'f2'
: And I want to insert itself in between f1 and f2
: if 1+1==2:
: print 'f1'
: if 1+1==2:
: print 'f1'
: print 'f2'

g*****g
发帖数: 34805
49
In ideal world, maybe. But don't forget you copy the code
from internet, from 3rd party resource, you may or may not
have copied a leading or ending line break. People may use
2 or 4 space, or tab, or a mix of them. You just don't have
control of that.
At the end of the day, I am often lost after copying a long
piece of code, and format gets me back in no time if it's
in Java. But extra care is always needed on python side.

【在 k***r 的大作中提到】
: You want to insert this to itself after the f1 line:
: if 1+1==2:
: ____print 'f1'
: ____print 'f2'
: You hit enter after 'f1', the carret stops right below letter "p",
: then you paste. It becomes:
: if 1+1==2:
: ____print 'f1'
: ____if 1+1==2:
: ________print 'f1'

k***r
发帖数: 4260
50
Only you know where you need the } to end a function, right?
Not your IDE. Similarly, " " will be added to every line
in a Python function. When you decide you are done with this
function, hit enter then backspace. You are done with this function.

【在 g*****g 的大作中提到】
: I don't. In eclipse, I use Ctrl+Shift+F, and it's done automatically.
: That's certainly easier and less error-prone.

相关主题
haskell在生产环境的生产力到底如何?花了一个小时学习了python
python或pydev怎么跳到一个section的头/尾请问运行python的一些技巧。
python大家用什么IDE?correct indentation in python ?
进入Programming版参与讨论
g*****g
发帖数: 34805
51
No, } is generated by IDE when I type {. I always type in between.
And no matter where I copy the code from, as long as
it has matching {}, it will be formatted correctly.

【在 k***r 的大作中提到】
: Only you know where you need the } to end a function, right?
: Not your IDE. Similarly, " " will be added to every line
: in a Python function. When you decide you are done with this
: function, hit enter then backspace. You are done with this function.

k***r
发帖数: 4260
52
- code copied from web pages where indentation is lost
code is screwed up. No question about that
- mixed spaces and tabs
This can be converted by IDE. You just need to tell your IDE
what's the equivalent of a tab. Python coding convertion
recommends 4 spaces and that's what people use most of the time.
The good thing is, if a different style is contained in one
module or function, you will be fine even if they are mixed.
So this is less likely to be a problem.
No doubt that Python is more sensi

【在 g*****g 的大作中提到】
: In ideal world, maybe. But don't forget you copy the code
: from internet, from 3rd party resource, you may or may not
: have copied a leading or ending line break. People may use
: 2 or 4 space, or tab, or a mix of them. You just don't have
: control of that.
: At the end of the day, I am often lost after copying a long
: piece of code, and format gets me back in no time if it's
: in Java. But extra care is always needed on python side.

k***r
发帖数: 4260
53
No problem. IDE can generate } for you. Then you'll still need
to decide when to stop typing before the } and hit a few down arrows
to leave the function. Similarly, you need to decide when to hit
the backspace to end a function in Python. I really don't seel
a bit deal of difference here.

【在 g*****g 的大作中提到】
: No, } is generated by IDE when I type {. I always type in between.
: And no matter where I copy the code from, as long as
: it has matching {}, it will be formatted correctly.

t****t
发帖数: 6806
54
真是说都说不明白啊.

【在 k***r 的大作中提到】
: No problem. IDE can generate } for you. Then you'll still need
: to decide when to stop typing before the } and hit a few down arrows
: to leave the function. Similarly, you need to decide when to hit
: the backspace to end a function in Python. I really don't seel
: a bit deal of difference here.

c*****t
发帖数: 1879
55
我怀疑他们为了灌水而故意的。。。

【在 t****t 的大作中提到】
: 真是说都说不明白啊.
t****t
发帖数: 6806
56

usually (under the usual editor rules) it becomes:
if 1+1==2:
____print 'f1'
____if 1+1==2:
____print 'f1'
____print 'f2'
____print 'f2'

【在 k***r 的大作中提到】
: You want to insert this to itself after the f1 line:
: if 1+1==2:
: ____print 'f1'
: ____print 'f2'
: You hit enter after 'f1', the carret stops right below letter "p",
: then you paste. It becomes:
: if 1+1==2:
: ____print 'f1'
: ____if 1+1==2:
: ________print 'f1'

k***r
发帖数: 4260
57
Yes. It's not implemented that way in many Python editors.
If you had followed the discussion, you would have known that
goodbug's argument is that the information would be lost. I tried
(and I think I did) to prove to him that the information is all
there. It's only a matter of implementation. I didn't mean PyDev
(or any other editors) does this at this point.

【在 t****t 的大作中提到】
:
: usually (under the usual editor rules) it becomes:
: if 1+1==2:
: ____print 'f1'
: ____if 1+1==2:
: ____print 'f1'
: ____print 'f2'
: ____print 'f2'

w****i
发帖数: 964
58
自动多空两格东西要在IDE里实现很容易吧,用C++/java写程序还不是要缩进,虽然语
法不要求,但实际中有人写不缩进的程序吗,而且还得在前后加{}
上次好象有人讲过,既然缩进已经是写程序的惯例,为什么不利用一下。
g*****g
发帖数: 34805
59
Current IDE can do that for you if it's Java or C++. One shortcut key
will do it all. There's a difference between you use indent and you
type indent.

【在 w****i 的大作中提到】
: 自动多空两格东西要在IDE里实现很容易吧,用C++/java写程序还不是要缩进,虽然语
: 法不要求,但实际中有人写不缩进的程序吗,而且还得在前后加{}
: 上次好象有人讲过,既然缩进已经是写程序的惯例,为什么不利用一下。

w****i
发帖数: 964
60
not in gedit

【在 t****t 的大作中提到】
:
: usually (under the usual editor rules) it becomes:
: if 1+1==2:
: ____print 'f1'
: ____if 1+1==2:
: ____print 'f1'
: ____print 'f2'
: ____print 'f2'

相关主题
python indentationpython自动缩进出错 快疯了
python有快速loop over dict的方法吗?Python 缩进的syntax
jun rao说kafka已经开始用Java代码重写部分code了python的一大缺点
进入Programming版参与讨论
w****i
发帖数: 964
61
I use one key to do that in my editor too. I don't have any paste
identation issue particularly with python.
Yes there's a difference between use indent and type indent. Just like
there's a difference between automatic management memory in Java and manual
memory management in C++. You can't say one thing is always better than the
other.

【在 g*****g 的大作中提到】
: Current IDE can do that for you if it's Java or C++. One shortcut key
: will do it all. There's a difference between you use indent and you
: type indent.

n*w
发帖数: 3393
62
不是我的perl,那人的程序有时是无端端的吧时间复杂度写高一个指数级。我也怀疑是
他的算法问题。但那个parser很简单,简单的一个循环,regex。
pyc可能是python快得原因。

【在 n******t 的大作中提到】
: There should be some "funny" part in your perl code.
b***e
发帖数: 1419
63
Ah? Haskell has OO, please teach me. I'm not a professional Haskell
programmer, but I think I am proficient enough, and I never knew Haskell
developed OO mechanisms. Is it recently?
BTW by Haskell, we either refer to Haskell98 standard, or GHC, not the 10
million other dialects, like Hugs, O'Haksell, O'Hug...

etc.
it
means.
do
are

【在 p***o 的大作中提到】
: I'm certainly talking about major OO concept: polymorphism, inheritance etc.
: Java Generics really sucks. In fact many things are wrong with Java, but it
: did something better than Python.
: Essentially Haskell has OO, but only if you understand what OO really means.
: Have you tried CLOS? That gives you a better idea what is OO.
: But who told you that OO(in its conventional meaning) is the best way to do
: things? I think the normal OO languages you use nowadays are doomed,
: because "everything is an obj

b***e
发帖数: 1419
64
That's exactly the point. Braces are truly needed, but braces are:
NON-CONTEXT-SENSITIVE
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! So this is a plug-and-play thing.
Spaces/tabs are context-sensitive, which means, how many spaces are there
depends on how many spaces there are already in the context. So this is a
fuked-up thing.

【在 k***r 的大作中提到】
: Only you know where you need the } to end a function, right?
: Not your IDE. Similarly, " " will be added to every line
: in a Python function. When you decide you are done with this
: function, hit enter then backspace. You are done with this function.

x******c
发帖数: 13
65
Why is copy/paste code such a big deal? you may save a couple of key stokes
with the curly brackets, that's it. That should save you no more than 0.1%
development time.
Eliminating brackets may also not bring you lots of benefits, but I do think
it
is certainly higher than a few extra key strokes.

【在 g*****g 的大作中提到】
: In ideal world, maybe. But don't forget you copy the code
: from internet, from 3rd party resource, you may or may not
: have copied a leading or ending line break. People may use
: 2 or 4 space, or tab, or a mix of them. You just don't have
: control of that.
: At the end of the day, I am often lost after copying a long
: piece of code, and format gets me back in no time if it's
: in Java. But extra care is always needed on python side.

1 (共1页)
进入Programming版参与讨论
相关主题
python indentation问一下python初学者的问题
python有快速loop over dict的方法吗?Python for Data Analysis
jun rao说kafka已经开始用Java代码重写部分code了我来说说python的优点吧
python自动缩进出错 快疯了lisper
Python 缩进的syntaxMAC 下面 python 编程用什么IDE?
python的一大缺点haskell在生产环境的生产力到底如何?
请问python的多重循环怎么实现?python或pydev怎么跳到一个section的头/尾
总觉得python 用缩进定义逻辑block 这种思想很诡异python大家用什么IDE?
相关话题的讨论汇总
话题: python话题: print话题: haskell话题: code话题: f2