TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Do I Really Need a Programming Language?

150 点作者 momo-reina超过 11 年前

20 条评论

tikhonj超过 11 年前
The real question here is &quot;do I need syntax?&quot;, or, more precisely, &quot;do I really need a [complex] grammar?&quot; Any given Lisp is still a programming language--it has <i>some</i> syntax and it has semantics. But it does have a <i>much</i> simpler grammar than any language (save Forth).<p>The grammars exist because programs are made to be read by people, not just computers. A more heterogeneous notation can make for more concise code that&#x27;s easier to scan and easier to read.<p>Of course, this is not to say that Lisp is unreadable. I actually rather like reading and writing (paredit is <i>awesome</i>) Lisp code. But, after quite a bit of Racket, I&#x27;ve found that I still heavily prefer having infix operators and a bit more syntax. At the same time, I also often want <i>less</i> noise--ie no parentheses. I want all this so that I can quickly scan and comfortably read my code. That&#x27;s why we need grammars.
评论 #6979596 未加载
评论 #6979054 未加载
评论 #6979672 未加载
评论 #6979730 未加载
评论 #6979210 未加载
评论 #6979473 未加载
评论 #6979667 未加载
评论 #6979668 未加载
nostrademons超过 11 年前
This is why everyone should study compilers and machine architecture in college.<p>Anyway, it&#x27;s interesting that he chose to label what he ended up with as &quot;Lisp&quot;. I would&#x27;ve stopped at assembly, eg. in LLVM IR:<p><pre><code> %result = icmp gt i8 %price, 100 br i1 %result, label %Discount1, label %Discount2 Discount1: ret i8 10 Discount2: ret i8 5 </code></pre> The key idea here is that <i>underneath everything you tell the computer to do is boolean logic and transistor circuits</i>. Yes, even Lisp S-exprs; it&#x27;s not really correct to say &quot;Lisp has no syntax&quot;, it has a very simple syntax that is trivially parseable. Even LLVM assembly is a translation layer, as is LLVM itself; underneath it on my computer is an i86 processor, and underneath it in my phone is an ARM-architecture Snapdragon.<p>Once you understand that, you realize that all of these languages and frameworks and libraries and databases are just tools, and they exist for <i>your</i> convenience. They&#x27;re there to let computers handle things that humans are really bad at. For example, memorizing memory layouts really sucks; let a computer map out your structs onto memory. Managing heap memory really sucks; let a garbage collector do it. Managing register allocation really sucks; let a compiler do it. Managing syntax kind of sucks; let a parser slap something more friendly on top of it, or don&#x27;t and use Lisp. Managing vtables kind of sucks; let C++ or Java hide it behind a class, or don&#x27;t and continue to use C.<p>Once you&#x27;ve gotten into this mindset, you&#x27;re free from the religious wars that surround technologies, because you realize it&#x27;s all just tools that compile down to machine code at the end. And you understand when a tool might be useful, and when you could just as easily implement it yourself, and when it once was useful but has since ceased to be.
评论 #6978867 未加载
评论 #6978841 未加载
评论 #6979646 未加载
评论 #6978869 未加载
评论 #6979399 未加载
barrkel超过 11 年前
Now show the same tree for a ruby block, a Java inner class, a C# lambda and how they&#x27;re all the same.<p>Except they&#x27;re not.<p>Only the simplest ASTs are directly translatable. Language semantics differ wildly when you get into higher level constructs. Not even Lisp is able to help you, as that just changes the problem from one of syntactic representation into one of library implementation.
评论 #6979468 未加载
评论 #6978959 未加载
评论 #6981308 未加载
Cort3z超过 11 年前
Of course you don&#x27;t care that much about which language to choose when you just want to do a simple if statement. However when you want to do more complex stuff, like answering a request on port 80 and compile a document that you send back over port 80, making sure to encrypt it properly so that no third party will get a hold of it, then it would be beneficial with some sort of programming language.<p>The question should really be, why does the IT department care if he uses C or Basic? And more over, why did he try to make it in C in the first place if he knows the IT department prefer Basic? This is a case of unprofessional behaviour by the author, not whether or not you need a language to express an if statement. At that point he could just as well have written this is x86. Who needs maintainability anyway?
xixixao超过 11 年前
&gt; Among other things, the C parser will look for curly braces, and the VB.NET parser will look for the eye soring Then keyword.<p>Here I would pick up the article and write this:<p>No matter which language I start with, the end result is always the same. So maybe I could simply write out what is important for me:<p><pre><code> if price &gt; 100 10 else 5 </code></pre> And then I realized I was coding in CoffeeScript.
byuu超过 11 年前
Sure, and when you write an expression more complex than a single ternary, you start to see why Lisp is so uncommon in real-world usage.<p>It has a wonderful technical elegance, but the humans that have to write code tend to not think in the same sense. After four or five brace levels it gets very challenging to keep track of everything.
评论 #6979118 未加载
wtracy超过 11 年前
Well, you could edit machine code directly, or do the next best thing and write in assembler:<p><pre><code> cmp eax, 100 jle LESSTHAN mv 10, edx ret LESSTHAN: mv 5, edx ret </code></pre> I doubt that&#x27;s what the author had in mind, though.
评论 #6978806 未加载
评论 #6979121 未加载
评论 #6978812 未加载
评论 #6979071 未加载
chattoraj超过 11 年前
pg wrote about this years ago.<p>&gt;If you understand how compilers work, what&#x27;s really going on is not so much that Lisp has a strange syntax as that Lisp has no syntax. You write programs in the parse trees that get generated within the compiler when other languages are parsed.<p>source: <a href="http://www.paulgraham.com/avg.html" rel="nofollow">http:&#x2F;&#x2F;www.paulgraham.com&#x2F;avg.html</a>
评论 #6978856 未加载
评论 #6980519 未加载
wildgift超过 11 年前
Here&#x27;s the code in either C or C#:<p>return ( (price &gt; 100) ? 10 : 5);<p>Computer languages are for people. It should really be more like this:<p><pre><code> # # Description of what this does. # PRICE-THRESHOLD = 100 LOWER-PRICE = 5 UPPER-PRICE = 10 IF PRICE &gt; PRICE-THRESHOLD RETURN UPPER-PRICE ELSE RETURN LOWER-PRICE </code></pre> Alternatively, use Excel:<p><pre><code> =IF( (price &gt; 100), 10, 5 ) </code></pre> Excel is cryptic, but a lot of finance people understand it.
评论 #6979368 未加载
评论 #6979446 未加载
mikro2nd超过 11 年前
To quote Guy Steele, &quot;All programming languages evolve until they become Lisp.&quot;<p>(iirc)
评论 #6979340 未加载
评论 #6979394 未加载
评论 #6979318 未加载
ww520超过 11 年前
For simple business rules and logic, I found it useful to just use a table or mini-spreadsheet to represent them. It has strict structure and it&#x27;s simple to understand and fill in. Business users love them.
ericHosick超过 11 年前
We&#x27;ve been working on a programming language that is based on composition. This basically leads to a hybrid data structure (not necessarily tree-structured).<p>Here is an example (write out 1 2 4 8 16 32 on different lines):<p><pre><code> Application ( using Library ( name &quot;Vision.Console&quot; ) action ForEach ( items 1 2 4 8 16 32 action WriteLine ( text CurrentItem () ) ) ) </code></pre> Parts are upper case and properties are lower case. Each Part is a class 1 contained within a given framework.
girvo超过 11 年前
I&#x27;m working on a toy programming language at the moment, and I was considering using a LISP dialect of some sort as the IR to be compiled down to. Is this a dumb idea? I had the same sort of epiphany that the OP had, but then I think LLVM IR is a better choice. The only reason I like the LISP-as-IR idea, is that if a programmer wants to get deep and optimise, the tooling can work with lisp instead, which allows for some neat tricks I have in mind.
评论 #6978885 未加载
collyw超过 11 年前
Someone influential (was it Joel) said that code gets read a lot more often than it gets written.<p>I am not used to Lisp or VB.net but I do find the first two examples a lot more readable.<p>(Seasoned Lispers, does reading Lisp get easier to read over time? As readable as an imperative language?)
评论 #6980051 未加载
carlob超过 11 年前
The overly eager optimizer in me was thinking:<p><pre><code> (price &gt; 100) * 5 + 5; </code></pre> yay! no branching!
评论 #6979113 未加载
评论 #6979235 未加载
评论 #6979137 未加载
评论 #6979039 未加载
sgt101超过 11 年前
No one thinking that a contractor might have to maintain it in 5 years time? No?<p>Ahhh <i>the fundamentals</i>!
评论 #6979236 未加载
dschiptsov超过 11 年前
Nice way to discover the <i>if</i> special form. Now its time for short-circuiting.)
dylandrop超过 11 年前
Alright, that&#x27;s one anecdote. But take a look at this one.<p>In Python:<p>a = 3 * 4 + 5<p>In Lisp:<p>(setf a (+ 5 (* 3 4)))<p>Now maybe it&#x27;s just me, but balancing all those parentheses and thinking in prefix notation gets a little hairy, especially if we introduce more math into a program (think graphics or ML).
评论 #6982549 未加载
thomasfedb超过 11 年前
If you expressing what you want the computer to do, and it understands you, you are - by definition - using a language.
forgottenpaswrd超过 11 年前
Oh man, so many people in the world need a better boss...<p>Without him, they will spend most of their lives on mindless debates sucking their creative energy like a vampire blood.