Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

One of my professors says "the syntax is the UI of a programming language", languages like Ruby have great readability and it's growing, but we see a lot of programmers productive with C\C++, so as programmers does it really matter that the syntax should be acceptable?

I would love to know your opinion on that.

Disclaimer: I'm not trying to start an argument. I thought this is a good topic of discussion.

Update: This turns out to be a good topic. I'm glad you are all participating in it.

share|improve this question
12  
Hmm, this seems to assume that the C/C++ syntax is bad? Certainly some elements of C++ templates are ugly, but as far as languages go (historically), C/C++ is still very, very readable. –  Macneil Dec 26 '10 at 18:29
2  
well i know many programmers who will disagree on that , mostly from the ruby community though , its more readable than lisp as far as i can tell :) –  Saif al Harthi Dec 26 '10 at 18:44
7  
Was it a theoretical course? Remember: professors are often some of the worst programmers. They have no idea what it is like out there in the wild. –  Job Dec 26 '10 at 19:51
1  
Matlab and Python are an interesting example because SciPy uses what appears to be THE SAME syntax as Matlab, but does so outside of the language. Both languages are high-level, and often scripts written in either one are VERY short. So, if you never write more than 150 lines per task, then syntax does not really matter. –  Job Dec 26 '10 at 19:57
7  
Good syntax cannot make a miserable language better. But miserable syntax can make a good language worse ;) –  Dario Dec 27 '10 at 12:29
show 10 more comments

17 Answers

up vote 52 down vote accepted

Yes it does. If you're in doubt, take APL, or J, or Brainfuck, or even plain and simple Lisp or Forth, and try to understand any not entirely trivial program on it. Then compare to e.g. Python.

Then compare the same Python (or Ruby, or even C#) to things like Cobol or VB6.

I'm not trying to say that hairy syntax is bad and natural-language-like syntax is good in all circumstances. But obvoiusly syntax does make a huge difference. All in all, everything you can write in the most beautiful programming language you can also write as a Turing machine program — but you usually don't want to, do you?

share|improve this answer
17  
Lisp is definitely understandable. –  cbrandolino Dec 26 '10 at 20:31
35  
+1 for including Lisp in the list of unreadable languages. –  asmeurer Dec 27 '10 at 3:16
35  
-1 for including Lisp in the list of unreadable languages. –  Paul Nathan Dec 27 '10 at 3:29
18  
Programming in general is unreadable to the uninitiated. As are music notation and architectural floorplans. (= X Y) is just as readable as X == Y, to someone who knows how to read. –  Paul Nathan Dec 27 '10 at 16:08
3  
I loved APL, and unless the code was intentionally written to obfuscate (very easy to do), it was quite easy to read. The power of the syntax was that you could program algorithms in 2 or 3 lines of APL code that would require dozens or hundreds of lines of C, Fortran, or COBOL. The conciseness and power of a language like APL is important to this discussion because trying to read through hundreds of code lines of another language can be just as frustrating as deciphering obscure elements of APL. –  oosterwal Jan 31 '11 at 23:17
show 19 more comments

In practice I think it does matter. Readability has already been discussed above. Another issue might be how many keystrokes are neded to express an idea/algotithm? Yet another issue is how easy it is for simple typos to be hard for the human eye to catch, and how much mischief they can cause.

I've also found it useful in some contexts to analyze, and/or to generate fragments of code via another computer program. The difficulty of parsing the language, and/or generating correct code then directly impacts how much effort is required to create/maintain such tools.

share|improve this answer
2  
But in theory there is no difference between theory and practice. –  Job Dec 27 '10 at 1:02
show 1 more comment

I believe your professor is referring to Syntactic sugar.

Syntactic sugar is a computer science term that refers to syntax within a programming language that is designed to make things easier to read or to express, while alternative ways of expressing them exist.

So what your professor is implying, is that whatever code/syntax written in one programming language, can be expressed in other languages just the same-- or even the same language.

Robert Martin, pulling from Structured Programming theorem, abstracted what programmers fundamentally do with programming languages at his keynote at RailsConf 2010: Robert Martin (youTube video, see after 14 minute mark, although I recommend the whole thing):

  • Sequence (assignment)
  • Selection (if statements)
  • Iteration (do-loops)

That is all programmers do, from one programming language to another, just in a different syntax or user interface (UI). This is what I'm guessing your professor was getting at, if he/she is speaking abstractly about programming languages.

So in essence, syntax doesn't matter. But if you want to be specific, then obviously certain languages and syntax are better suited for certain tasks than others, whereby you could argue that syntax matters.

share|improve this answer
1  
I would. But I claim syntax matters. ;) –  Lennart Regebro Dec 26 '10 at 20:39
2  
"...Robert Martin abstracted what programmers fundamentally do..." Robert Martin? Robert Martin?? You might actually want to consider this paper: C. Böhm, G. Jacopini, "Flow diagrams, Turing Machines and Languages with only Two Formation Rules", Comm. of the ACM, 9(5): 366-371,1966. which is usually credited as the source of the 'Structured Program Theorem'. en.wikipedia.org/wiki/Structured_program_theorem –  leed25d Dec 26 '10 at 21:46
show 3 more comments

Yes and no.

There are a couple different aspects to syntax.

  • readability
  • expressivity
  • parsability

Readability has already been mentioned.

Expressivity is an interesting case. I'm going to use function-passing as an example, because it's sort of an inflection point of semantic/syntactic pain.

Let's take C++ for example. I can create a first-order function after this fashion:

class funcClass
{
  int operator()(int);
}
funcClass fun;

void run_func(funcClass fun)
{
   fun();
}

This particular idiom is commonly used in Stepanov's Elements of Programming.

On the other hand, I can mimic it in Common Lisp with something like this:

(defun myfunc() )

(defun run_func(fun)
  (fun))

Or, in Perl -

   sub myfunc
   {
   }

   sub run_func
   {
      my $func = shift;
      $func->();          #syntax may be a little off.
   }

Or, in Python -

def myfunc():
    pass

def run_func(f):
    f()

These all have - essentially - the same semantic content, although the C++ example carries some type metadata. Which language expresses the idea of passing a higher-order function the best? Common Lisp barely makes a syntactical variation. C++ requires a class to be created just to 'carry' the function. Perl is pretty straightforward about making some level of differentiation. So is Python.

Which approach best suits the problem domain? Which approach best can express the thoughts in your head with the least 'impedance mismatch'?

Parsability is - in my mind- a big deal. In particular, I refer to the ability of the IDE to parse and chop the language without making errors. Reformatting is useful. Token-delimited languages tend to parse well - ruby/c/pascal, etc.

Consider though - major systems of all sorts have been created with every serious language to solve real-world issues. Although syntax is a barrier to express some things, it is a work-around-able barrier. Turing equivalence and all that.

share|improve this answer
add comment

Syntax does matter, and I can give you two supporting examples: Dylan, which is a Lisp with a more conventional syntax, and Liskell, which is Haskell with Lisp-like syntax. In each case, a variant of the language was proposed that had exactly the same semantics, but radically different syntax.

In the case of Dylan, it was thought that dropping s-expressions in favor of something more conventional would help attract a wider range of programmers. It turned out that syntax wasn't the only thing preventing programmers from using Lisp.

In the case of Liskell, it was thought that using s-expressions would allow for easier use of macros. It turned out that macros really aren't necessary in Haskell, so that experiment didn't work either.

Here's the thing: if syntax didn't matter to anybody, neither experiment would have been tried.

share|improve this answer
1  
Dylan was too little, too late over other languages. What it had in its favor couldn't make up for that. We can no more assume it's a failure of syntax than it was a failure in naming. –  Macneil Dec 26 '10 at 21:15
show 5 more comments

The answer might be in separating what "matters" into computer factors and human factors. There are a lot of human factors in syntax:

  • Readability
  • Succinctness
  • Maintainability
  • Pedagogy
  • Error prevention
  • Appropriateness for the purpose -- is it a REPL language, a script language or a large systems language?

As far as the computer is concerned, the only issue of syntax is whether or not there are ambiguities that need to be resolved, and how much time it takes to tokenize/parse the code upon compile/interpret -- and it's only in the case of the latter where the overhead of parsing is a significant issue.

That might be why you'll always get a "yes and no" answer to this question -- because there's two aspects to it.

share|improve this answer
add comment

Syntax definitely matters, although you tend to notice it more when it's unintuitive and encourages bugs. For example, the infamous "world's last bug" joke:

if (AlertCode = RED)
   {LaunchNukes();}
share|improve this answer
1  
+1: Interesting, I've never seen (or acknowledged) this infamous "world's last bug" joke. But I can see how, depending on the syntax of a language (or actually even semantics), the result of that pseudo-code could be anything. Given the semantic angle as well, this can really be chalked up to classic case of cultural miscommunication. –  Stephen Swensen Dec 26 '10 at 23:06
2  
@Malfist: And thus we see that bad syntax leads to even worse syntax to compensate. Yoda conditionals are ugly and hard to read because they're not the way people think of the associated concept. My point was more like "this is (one of many reasons) why you should avoid the C family whenever possible." –  Mason Wheeler Dec 27 '10 at 17:04
1  
Well, fortunately, that code has two bugs. Sure, it'll always enter the conditional, but in there, it's just getting a reference to the LaunchNukes procedure, and never invoking it. Crisis averted! –  munificent Dec 27 '10 at 19:23
1  
Depends on what RED is. If it's 0, then LaunchNukes() would never be called. –  dan04 Jan 7 '11 at 9:58
show 4 more comments

Without syntax, we would not have a common "template" from which to communicate, at a human level, the intent of a block of code. Syntax provides a common framework from which compilers can be standardized; methods can be shared; maintenance can be simplified.

share|improve this answer
show 1 more comment

I think what really matters is API access, and availability of low-level functionality (like memory control and locking) when needed. Most other languages come with these features included. Problem is, when you need additional functionality you often have to use a language like C to implement it. And it is cumbersome interfacing C with the language you are using.

For everything except web development (and math) I've found that C/C++ is still THE language of an operating system and an application. It's what is supported most of the time for true multi-threaded, preforming, cross-platform application development. And the syntax of C is okay. Just very simple and relatively verbose. Amazing Syntax doesn't really matter that much. Power and API availability does We all need to interface with other people's code (which is most of the time written in C or its derivitives).

share|improve this answer
show 2 more comments

I don't think it matters beyond personal preference. All things (performance, capabilities, etc) being equal then I can see why one would put greater weight on a language syntax but choosing to pass over the performance of languages like c/c++ or any other language better suited for the job simply because of syntax would seem like a bad idea all around.

share|improve this answer
5  
How about "time to market", "cost to benefit", etc.? –  Job Dec 26 '10 at 19:52
add comment

Yes, syntax matters, although really only for readability. Compare:

for i in range(10):
   print(i)

(Yeah that's Python) with

FOR(i<-RNG-<10){PRN<-i}

(Yeah, that's a language I just made up) Both would do exactly the same thing, in the same way, but the syntax is different, and Python is easier to read. So yes, syntax definitely matters. Even "syntactical sugar" matters.

 @property
 def year(self):
     return self._date.year

Is easier to read than

 def year(self):
     return self._date.year
 year = property(year)
share|improve this answer
add comment

Another thing to consider is that programming languages with nicer syntax are easier to parse, thus making the compiler easier to write, faster, and less prone to bugs.

share|improve this answer
2  
Umm ... 10000 SLOC of parse.y in Ruby disagree. There is a reason why every single one of the 7 current-or-soon production-ready Ruby implementation uses the same parser, and every single Ruby implementation that has ever tried to develop their own parser has failed. –  Jörg W Mittag Dec 27 '10 at 3:03
show 1 more comment

Yep, sure.

If you wanna initiate a big flame, ask the folks, where they put the opening bracet in C-like languages. I mean

void foo() {
  // blah
}

VS

void foo()
{
  // blah
}

or even VS

void foo() 
{ // blah
}

And this is just the same language! Also, ask them about spaces, where they place them (function name and bracet, operators etc.).

1000 answers are guaranteed!

share|improve this answer
show 1 more comment

Syntax does matter. However in this day and age I'd say it matters almost entirely because of readability and not really in terms of the amount of keystrokes needed. Why?

  • Unless you're really writing something that simple, if the number of keys you press is the limiting factor in writing a program then you're either really, really crap at typing or think much, much too quickly.
  • All decent IDEs these days have a large number of shortcuts that mean you don't need to actually type out all the characters you're using most of the time.

That said, if it's too verbose then it can get to the point where it affects readability. I'd prefer to see something like:

foreach(String in stringList)

To:

for every String that's in the list as referenced by the stringlist variable

...any day!

share|improve this answer
add comment

To put it simply: syntax as such doesn't matter. The semantics you can express through it matter.

share|improve this answer
5  
As an excercise, write a complex parser in C, and then a device driver in Haskell. Did syntax help you? Then do the other way around, strictly preserving the semantics of both programs.</irony> –  9000 Dec 26 '10 at 19:59
1  
@9000: I've seen a couple of device drivers in Haskell. I couldn't see anything particularly wrong with them. Care to elaborate? –  Jörg W Mittag Dec 27 '10 at 3:05
2  
@9000, given how hard it is to get device drivers right in C i am not sure you have chosen a good example. –  user1249 Dec 27 '10 at 10:55
1  
@9000: That was exactly my point. The concrete nature of a syntactic construct doesn't matter, it is what you express with it. A programming language with Haskell's exact syntax, but that uses a different evaluation strategy will make lots of Haskell perform awfully or even get stuck in infinite loops. When it comes to syntactic constructs (or broader: language features), it is not their concrete syntax that matters, but their semantics, i.e. what you can express with them. –  back2dos Dec 27 '10 at 11:51
show 1 more comment

Syntax definitely matters. It's terrifically valuable if the language syntax is flexible enough to allow you to create a convenient and readable Domain-Specific Language for your application. If you doubt this, just imagine doing algebra problems in prosaic Latin, as it was done before the 18th century, or imagine doing calculus without the now familiar Leibniz notation. Sure, a calculus text is unreadable to a novice, but with practice we can use calculus and the Leibniz notation to quickly solve a class of problems that required pages of mathematics with classical methods. Programming is just another bit of mathematics. A convenient notation, close to the problem domain, can make an enormous difference in productivity.

share|improve this answer
show 2 more comments

Syntax matters to those who are learning it, the lower the barrier to entry the more popular the language might be initially. But if the language is difficult or impossible to express your self richly and succinctly it will start to wither in popularity.

Very terse and opaque ( Perl ) is just as bad as overly verbose and wordy ( AppleScript ).

There needs to be a balance, lower barrier to entry, high productivity and easy maintenance.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.