JSLint and the "Expected to see a statement and instead saw a block." error - scope

I have picked up the habit of wrapping all of my case statements in curly brackets from programming in C because of this but JSLint is throwing a fit. It stops validating at that point.
My question is: Is this such a bad practice in JS? Do I not have to worry about the scope issue because JS has function scope (I understand how that would be the case, I just want a good reason not to be 'consistent' on this)?
(I know that different languages call for different practices, but i am trying to be as consisten as possible across languages to help protect my sanity.)

Good question.
The reason that JSLint complains about this is because it is actually contrary to the language specification for the switch/case statments:
http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf
https://developer.mozilla.org/en/JavaScript/Reference/Statements/switch
The JavaScript compier will tolerate it, however JSLint is about ensuring your code adheres to a stricter and more correct subset of JavaScript. ("The Good Bits" as Douglas Crockford puts it!)
Moreover, the extra bracing is extra characters that you will have to transmit with the website. If you don't need them, why transmit them?
Referring to your above link, the same problem does not present itself in JavaScript. So, the following will work:
var x = 0;
switch(x){
case 0:
var y = 1;
alert(y);
}
See it at this JSFiddle: http://jsfiddle.net/LKWwB/
Finally, regarding your sanity, I would relinquish the tenuous grip you have on it. I did years ago and am much happier for it :-)

Related

Creating a conventional syntax "compiler" for python

I love the versatility of python, but I absolutely hate the (non conventional) syntax (mainly the lack of {}, semicolons, and obvious variable declarations). I know that for many people the syntax is a part that they like, and I can understand that, but, I far prefer using brackets to define scoped rather than tabs; I like knowing a statement is over when I see a ; and it is second nature for me to write a conventional for (variable; condition; increment) {} rather than for i in range (*,*,*): etc. You get the point. So, my question is: is it a totally absurd idea to write a text parser (written in any language, probably Java) that converts a text file that has the custom syntax into a compile-able .py program? This would be mainly a learning experience, and for fun, it wouldn't be a serious solution for any large/complex programs.
I am also not sure how this will sit with the stack overflow guidelines for a typical question, seeing as how it is partly opinion based, so if you think it shouldn't be here, could you tell me where a good place to post it might be?
Thanks, Asher

Basic Code Layout Question

HI, I have a simple question, I've asked 3-4 different people and have had different answers from each of them.
Which code layout is better and used more?
does it really matter as long as it's consistent?
Which is seen as better practice in the world of working as a programmer?
Eg
A)
for(int i=0;i<8;i++)
{
for(int p=0;p<8;p++)
{
if(array[i][p]->Equals(String))
{
//Do Stuff
}
}
}
OR
B)
for(int i=0;i<8;i++){
for(int p=0;p<8;p++){
if(array[i][p]->Equals(String)){
//Do Stuff
}
}
}
Thanks,
Tim
Several published style guides exist -- for example, Google's is here, and it mandates, for functions:
ReturnType ClassName::FunctionName(Type par_name1, Type par_name2) {
DoSomething();
...
}
and for blocks:
if (condition) { // no spaces inside parentheses
... // 2 space indent.
} else { // The else goes on the same line as the closing brace.
...
}
with similar examples for other blocks.
So, look around a few such style guides, pick one that's from a somewhat prestigious source and that you like, and if anybody objects to your style just say "oh, I picked it up from X" (where X may be Google, geosoft, or whatever other source you like (many more are listed here).
In almost all cases in practice, there is a clear answer: Use the style that is currently in use in the codebase that you're working with. If you are starting a new project, use the style that is currently in use in the other projects maintained by the team that will be maintaining your code.
The codebases I've worked with have largely had their roots in GCC and other FSF software, which means that all of my projects have used the style with the "{" on a separate line. I could come up with justifications for why that's "better", but that's a matter of subjective style. Being consistent within a project and within a team is objectively better.
This is entirely subjective. Both are popular.
There's no right or wrong here. It's up to the preference of you, or your team/organization.
As far as the braces go, my current team has chosen option B, but I actually prefer option A.
Personally I would recommend a little more spacing especially after the "for" and "if", and a bit more indentation on option B, for readability. But, that's just my preference.
What, no middle ground? Just two examples, each designed to take a (relatively) extreme position?
Clearly, you've left out a whole bunch of intermediate examples with lots and lots of slightly different formatting rules.
You're not really putting any effort into it if you can't think of at least ten more variants. Two variants isn't enough focus on nuance.
You can -- if you want -- be lazy. A decent IDE will format for you. I use Eclipse and it formats for me and that's what I use without thinking about it at all.
You can also download and read open-source code and actually emulate styles you find there. That's a little less lazy approach, you do have to read other's people's code.
I am not sure its possible to come up with reasons why one is better than the other that arent completely subjective and only valid for a small set of projects.
I like the compressed style, it tends to make code more compact and since I like my functions to be compact and fit on screen it helps.
It drives other people nuts though, and they dont like not seeing a block start and end on its own line. I can see their point.
Usually its not a big deal as each developer uses their own settings and we let the source control system store it in an agnostic format (doesnt really matter which one).
Of course YMMV.
As some have already pointed out, you should use the style that is already in use by the code base or the team.
However, if you are in college or have never used a language that uses curly braces, I would suggest placing the curly braces on their own line. I have found that new developers can have problems identifying missing curly braces when they are placed on the same line as code. This probably isn't as big of a deal with modern IDEs.
When I was younger, I used to believe that all of these questions were matters of opinion, subjective, and best left to individual taste.
As I have aged, my vision has become increasingly astigmatic. Without surgery, astigmatism is correctable using either glasses or contacts -- but the correction is far from perfect.
Astigmatism makes reading harder, including reading code.
For a person with astigmatism, such as myself, identifiers_with_underscored_spacing are much easier to read than IdentifiersWithCamelCaseWordBreaks.
Similarly, for me, braces on lines by themselves are easier to read than braces sharing a line with code.
Therefore I recommend the second style you propose because it is more accessible.

Is there a language that encourages good coding practices?

While I love PHP I find its biggest weakness is that it allows and even almost encourages programmers to write bad code.
Is there a language that encourages good programming practices? Or, more specifically, a web-related language that encourages good practices.
I'm interested in languages who have either a stated goal of encouraging good programming or are designed in such a way as to encourage good programming.
I think Python have some ideas for good coding practices. At least programs are forced to look the same way.
But don't forget that Larry Wall said:
Real programmers can write assembly code in any language
You'd better think about creating a coding style convention.
This is way too subjective. If by "good programming practices," you mean consistent indentation, then sure, Python works for that. But indentation is something most programmers learn the first time they write a program. I think good programming goes well beyond that.
Over the years, the idea of what is good programming practice has changed. Python, other than the indentation thing, doesn't really excel in any one category. It's not the most object-oriented language around, nor does it (yet) offer full support for functional programming.
Here are some possible definitions of good programming practices, and a representative language for each:
- Pure object oriented design:
SmallTalk was the first real OO language, and in some ways still the purest. Literally everything is a class.
- Pragmatic object oriented design:
Java, for all it's detractors, was a huge step forward in terms of encouraging good programming practices. It is strongly typed, almost everything is a class, and it requires self-documenting class design, to a certain extent (by explicitly listing thrown exceptions, making functions private by default, etc.) Java enforces disciplines that are valuable for large development teams.
- Functional programming
Haskell is often praised as being the most purely functional language around. Assignment is verboten, and side effects are impossible unless your function explicitly asks for them.
- Robust concurrency
Erlang (another language that encourages the functional programming paradigm) is known for its robustness in a concurrent environment. Never having studied or used it, I can't personally vouch for this, but its track-record seems impressive.
- Iterative development
There are a ton of Lisp evangelists out there. They can't all be wrong, can they?
- Quick 'n' dirty
Sometimes you just need a script done quickly. Thank you, Perl. ;)
Well, it depends on what you consider a web language. Smalltalk definitely encourages best practices, and there's even a crazy web framework written in it (Seaside). It's very different and you can still do bad things. You're simply encouraged to do otherwise.
Eiffel's big thing is Design By Contract. It's a nifty organizational requirement that encourages testing and assertions everywhere.
Python is great, but it doesn't really encourage good practices. Well, if indentation is a best practice, then Python definitely enforces it.
Other languages don't really encourage you to do bad things like PHP does. You can also write great (and proper) code in PHP. People often forget that you can disable much of the nastiness in the interpreter (globals, slashes, etc.). You needn't jump ship just because PHP merely entices you to the dark side.
There is No Silver Bullet. Technology will not make a better programmer of you.
PASCAL is one of the programming languages that encourages good programming practices
Short answer? No. But the question uses English-language ideas that don't lend themselves to computer programming. What does "encourage" mean? What is "good programming practice"? Syntax highlighting and auto-indent? Surely any language can do that. Lint-style warnings? Not terribly hard. Style policing? Well, we'd had to admit C if that was the criteria.
Good programming practice arises naturally from good design. It's quite hard for clever coders to write bad code in any language if the design is clean and simple. Conversely bad practice follows from bad design. The tricky part is working out where a design stops being good and starts being bad. This is the #1 question in software design and sadly there is no silver bullet. Those lovely Design Patterns start looking awfully ugly once you have several of them implemented in your app.
This is pretty subjective, but I would have to say Python. Readability counts and there is only one way to do things make the language very easy to work with.
Frameworks can also reinforce good practices. Python's Django framework is based off the "MTV" pattern and lends itself to very friendly code.
I think really what you're looking for is not a programming language that encourages best practices, but an opinionated web development framework.
Ruby on Rails for instance is very opinionated, and "out of the box" gives you a strong indication of how the framework expects you to interact with it - it automatically creates a project structure, and even provides some initial unit tests. Testing is a very integral part of rails development, and you'll find a lot of resources to support BDD, TDD and other good "agile" development practices.
Other frameworks like Django (python) and Seaside (smalltalk) probably have their own conventions, although I'm not personally familiar with them.
I'm going to attract flames and suggest Perl.
'WTF?' you may say. Perl has a reputation as a write only language. It is, when in the hands of people who use it as merely a super-shell language. You can write crap in any language. Perl gives you massive freedom and flexibility. So, in Perl, logically, you have more freedom to write crappier crap.
The freedom and flexibility can also be used in the cause of readability and maintainability.
But how do you learn to produce good code and not crap? In the past the answer was "Experience, and community involvement." Over the last few years, some new tools and resources have arrived to help as well.
Experience
If you write a turd, and have to maintain that turd, you will learn from the experience.
Lovely. How do you avoid writing turds in the first place?
Community
Instead of enforcing arbitrary rules in the language, Perl has cultural norms that help improve code.
Post code on perlmonks without strict and warnings, and you will hear about why you should use them.
Great, so to do a decent job, I need to spend hours reading websites and newsgroups? Well, you're here now. But this is still a sub-optimal solution.
Tools: This is where we hit paydirt -
A few years ago, Perl Best Practices was published. It codified and collected the ideas of many leaders in the Perl community. It provides detailed discussion of the reasoning behind each of the 256 suggested practices. It offers practices, and a way of thinking about the practice of programming.
perltidy is a great reformatter for Perl that promotes code readability by automatically enforcing formatting style.
Perl::Critic and supporting modules provide a highly configurable system for analyzing Perl code. PC goes way beyond basic lint and even refers you to a specific page in Perl Best Practices for each issue it finds, allowing you to improve your code, five levels beyond the syntax check.
Unit testing is a pervasive part of Perl culture. Perl offers great unit testing tools as part of the 5.10 distribution. Additional testing tools are available from CPAN.
Moose is a new object system for Perl 5. It is inspired by the Perl 6 object system. Moose provides advanced object oriented capabilities like roles and traits. Roles and traits provide powerful new ways of handling code composition and reuse beyond what is possible with inheritance, interfaces and mix-ins. Inheritance models an "IS A" relationship. Roles and traits model "DOES". I can't emphasize enough how useful this is.
You can follow good practices in any language.
Yet you can carry out bad practices in any language as well.
As for writing "bad" code...you have to learn not to do that ;)
As for writing "well styled" code - grab a copy of Visual Studio, the ReSharper plugin, and StyleCop. Intellisense and autoformatting (Visual Studio) will help you lay things out nicely, the ReSharper plugin will restructure your code into a "preferred" structure, and StyleCop will help you follow a standard.
If I'm reading the question correctly, what you're looking for is a language where the "easy" thing to do and the "Best practices" thing to do are closely aligned.
If that's the case, what are the "best practices?" Gotta start with that :)
And as a slightly bizarre suggestion, might I suggest LISP or Scheme?
Haskell.
It makes you write pure code separately
It uses a tab syntax, forcing whitespace
The module system allows effortless organization of code
Why are you asking? The question seems to come up a lot after I deal with some nasty code hairball. I spend hours picking apart spaghetti logic that trails through about 6 subroutine levels. Finally track down the niggling error. And my first thought is why can't this be easier?
Code is written for the computer - not humans. It's optimized for the machine. Machines require exact instructions. At that level of detail, the complexity of any code base goes up fast. And that complexity is what typically drives this question.
Programming languages are not intended to control complexity. Programming tools can help you do that. How you write your code matters a lot more than in what language you write your code.
Take a look at literate programming. It controls complexity through organization. I personally like the visual structure provided by the Leo editor.
You might want to read the seaside book to get some ideas on how to DRY web apps.
The elimination of templates, consequent construction of DSLs for html and javascript frameworks (a.o. jQuery, Scriptaculous, Prototype, RaphaelJs) and even css (Phantasia, not in the base distribution), combination with an OODB for persistence (Gemstone) provides a lot of why is the current state of the art in php, java, ruby or c# so much worse?
I can't believe nobody has mentioned Objective-C / Cocoa. You are encouraged throughout to follow MVC patterns, and loose typing allows for some seriously decoupled OO designs.
Of course, this depends on what one thinks are "good practices". Different languages generally try to enforce/encourage their own opinions of what are "good coding practices".
Some examples of good practices that some languages try to encourage are:
Indenting code in logical levels:
If there's 1 practice that pretty much all programmers agree is good practice, it's that different blocks of code should be indented.
For example, consider the following Java code:
static boolean isPrime(final int x) {
if (x % 2 == 0 && x != 2) {
return false;
} else if (x > 1) {
final int MIDWAY = (x-1) / 2;
for (int i = MIDWAY; i > 1; i--) {
if (x % i == 0) {
return false;
}
}
return true;
}
return false;
}
It's considered best practice to indent the code within different scopes (e.g. function body, for block, if block). However, you don't HAVE to indent your code in a consistent manner (or even at all) in most languages. There's nothing stopping me from writing the whole thing without indentation, like this:
static boolean isPrime(final int x) {
if (x % 2 == 0 && x != 2) {
return false;
} else if (x > 1) {
final int MIDWAY = (x-1) / 2;
for (int i = MIDWAY; i > 1; i--) {
if (x % i == 0) {
return false;
}
}
return true;
}
return false;
}
You could even write the whole thing on 1 line if you wanted to! The code will still work, but it'll be a lot less readable.
However, languages that use offside-rule syntax (e.g. Python, Nim) FORCE you to indent your code in a consistent manner. So for example, the following Python code:
def is_prime(x):
if x % 2 == 0 and x != 2:
return False
elif x > 1:
MIDWAY = int((x-1) / 2)
for i in range(MIDWAY, 1, -1):
if x % i == 0:
return False
return True
return False
HAS to be indented. It won't run if it isn't. It can't. I can't write this code without indentation because blocks are determined BY indentation (and not {}, which is what most languages use).
Ok, Python does allow you to be a LITTLE flexible with your indentation. 1-liners can go on the same line, like this:
def is_prime(x):
if x % 2 == 0 and x != 2: return False # This is allowed.
elif x > 1:
MIDWAY = int((x-1) / 2)
for i in range(MIDWAY, 1, -1):
if x % i == 0: return False # So is this
return True
return False
But that's only for 1-liners. Blocks that contain multiple statements (e.g. the elif block) can't be done on 1 line.
Naming constants LIKE_THIS:
A common coding convention is to name constants CAPITALISED_WITH_UNDERSCORES. That's just so you (and other programmers) can distinguish, at a glance, a normal variable from a constant.
Now Ruby doesn't have user-defined constants (sob), but they have something like it: Ruby will give you a warning if you attempt to change a variable named LIKE_THIS. E.g.
my_var = 5 # creating a normal variable
my_var = 42 # this is ok
puts my_var
ANOTHER_VAR = 21 # creating a pseudo-constant
ANOTHER_VAR = 32 # interpreter will complain about this
puts ANOTHER_VAR # Will still work though
This output of this code is:
42
test.rb:5: warning: already initialized constant ANOTHER_VAR
test.rb:4: warning: previous definition of ANOTHER_VAR was here
32
In this way, Ruby encourages (but doesn't force) you to follow the best practice of naming your constants with UPPERCASE_WITH_UNDERSCORES.
Using constants over variables:
Typically, if you create a variable that you only assign to once (maybe it's just to hold an intermediate value, or you just don't need to re-assign to it), that variable should PROBABLY be a constant (e.g. the MIDWAY var in the above Java code; if I don't intend to re-assign to it, why not make that intent explicit to others by making it constant?).
In Rust, variables are immutable (i.e. constant) by default, unless you specify otherwise (which is the opposite of what Java and C++ does). Example Rust code:
let x = 42; // declaring an immutable variable
x = 10; // compiler will give an error; can't reassign to x.
let mut y = 42; // declaring a mutable (i.e. "normal") variable
y = 10; // allowed
In this sense, Rust encourages you to use constants by default, and to really think about when they should be variables (whereas in most other languages you use variables by default and rarely think about when they should be constants).
NOTE: TECHNICALLY immutable variables aren't the same thing as constants in Rust (Rust actually has constants, declared with the const keyword, but those are evaluated at compile-time). But since they act like constants in other languages, I'll call them constants for the purposes of this post.
Apart from those, most languages won't so much encourage you to actively use good practices as they will discourage (or just outright prevent) you from using "bad" practices.
For example, common wisdom says that using goto is bad practice, so most languages don't even have goto(the exceptions being C & C++)!
From here though, opinion tends to differ on what features are considered to be so bad (in terms of encouraging "bad practice") they're worth not having. For example, overuse of break and continue in loops is considered to be bad practice (for similar reasons to goto), so Scala doesn't even have break or continue (well, at least not built in to the language)! The designers of Go thought that exception-handling tended to be abused (i.e. tempted programmers to write convoluted code and treat too many ordinary errors as "exceptional"), so Go doesn't even have exception-handling! Many languages consider code abusing the ++ and -- operators to be tricky and obscure, so they just don't outright have those operators (Rust, Python, Swift 4, etc). Note that there's not as much consensus here of what's considered good and bad practice.
So there you go, a by-no-means-exhaustive list (might add to it in the future) of some languages that try to encourage good coding practices in 1 way or another (or at least what they consider to be good coding practices).
I'd throw C# out there. It encourages good techniques, readable code and provides tools for ensuring your comments are useful and targetted.
They also provide static analysis tools out of the box to make sure the code is good.
to be clear You can write bad code in any language
anyway C# is really good for following good coding practices
C# undoubtedly... good base and constantly improving.
Yes, Python. Many of its design goals are for the stated purpose of encouraging good coding practices. Read the Python tutorial, and the Zen of Python (type "import this" at a Python prompt).
Coding practices are external to a language. You can just about muck up source code in any language and what is a good practice is subjective.
For example, in C# at the function level you can declare any variable using var and the compiler will enforce type safety, however many people don't like var and think it lends itself to making the code harder to decipher. I personally love var especially when the type is mentioned on the right:
E.g.
var firstName = new string();
is better to me than ...
string firstName = new string();
... because why do I need to say string firstName when I know it's a string based on the right hand instantiation? Of course, once again this is subjective.
Standards and using code analysis tools coupled with code reviews can really make a difference though.
Here's a list of good analysis tools:
http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis
Assembler fits the bill of "a language where the bad things to do are either actively discourage or just outright difficult" - having your program segfault at runtime is rather discouraging, and writing badly structured web software in assembler would be outright difficult.
I think an aspect of a language / framework that isn't often talked about is the community around it.
I think Rails does a great job of encouraging better practices not only in the technology itself - which is very much focused on good practices eg. creation of unit tests when you generate scaffolding, but in the community which encourages best practices etc
Boo language for the same reasons as Python.
Maybe I'm a bit biased...?

What is the worst programming language you ever worked with? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 13 years ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
If you have an interesting story to
share, please post an answer, but
do not abuse this question for bashing
a language.
We are programmers, and our primary tool is the programming language we use.
While there is a lot of discussion about the best one, I'd like to hear your stories about
the worst programming languages you ever worked with and I'd like to know exactly what annoyed you.
I'd like to collect this stories partly to avoid common pitfalls while designing a language (especially a DSL) and partly to avoid quirky languages in the future in general.
This question is not subjective. If a language supports only single character identifiers (see my own answer) this is bad in a non-debatable way.
EDIT
Some people have raised concerns that this question attracts trolls.
Wading through all your answers made one thing clear.
The large majority of answers is appropriate, useful and well written.
UPDATE 2009-07-01 19:15 GMT
The language overview is now complete, covering 103 different languages from 102 answers.
I decided to be lax about what counts as a programming language and included
anything reasonable. Thank you David for your comments on this.
Here are all programming languages covered so far
(alphabetical order, linked with answer, new entries in bold):
ABAP,
all 20th century languages,
all drag and drop languages,
all proprietary languages,
APF,
APL
(1),
AS400,
Authorware,
Autohotkey,
BancaStar,
BASIC,
Bourne Shell,
Brainfuck,
C++,
Centura Team Developer,
Cobol
(1),
Cold Fusion,
Coldfusion,
CRM114,
Crystal Syntax,
CSS,
Dataflex 2.3,
DB/c DX,
dbase II,
DCL,
Delphi IDE,
Doors DXL,
DOS batch
(1),
Excel Macro language,
FileMaker,
FOCUS,
Forth,
FORTRAN,
FORTRAN 77,
HTML,
Illustra web blade,
Informix 4th Generation Language,
Informix Universal Server web blade,
INTERCAL,
Java,
JavaScript
(1),
JCL
(1),
karol,
LabTalk,
Labview,
Lingo,
LISP,
Logo,
LOLCODE,
LotusScript,
m4,
Magic II,
Makefiles,
MapBasic,
MaxScript,
Meditech Magic,
MEL,
mIRC Script,
MS Access,
MUMPS,
Oberon,
object extensions to C,
Objective-C,
OPS5,
Oz,
Perl
(1),
PHP,
PL/SQL,
PowerDynamo,
PROGRESS 4GL,
prova,
PS-FOCUS,
Python,
Regular Expressions,
RPG,
RPG II,
Scheme,
ScriptMaker,
sendmail.conf,
Smalltalk,
Smalltalk ,
SNOBOL,
SpeedScript,
Sybase PowerBuilder,
Symbian C++,
System RPL,
TCL,
TECO,
The Visual Software Environment,
Tiny praat,
TransCAD,
troff,
uBasic,
VB6
(1),
VBScript
(1),
VDF4,
Vimscript,
Visual Basic
(1),
Visual C++,
Visual Foxpro,
VSE,
Webspeed,
XSLT
The answers covering 80386 assembler, VB6 and VBScript have been removed.
PHP (In no particular order)
Inconsistent function names and argument orders
Because there are a zillion functions, each one of which seems to use a different naming convention and argument order. "Lets see... is it foo_bar or foobar or fooBar... and is it needle, haystack or haystack, needle?" The PHP string functions are a perfect example of this. Half of them use str_foo and the other half use strfoo.
Non-standard date format characters
Take j for example
In UNIX (which, by the way, is what everyone else uses as a guide for date string formats) %j returns the day of the year with leading zeros.
In PHP's date function j returns the day of the month without leading zeros.
Still No Support for Apache 2.0 MPM
It's not recommended.
Why isn't this supported? "When you make the underlying framework more complex by not having completely separate execution threads, completely separate memory segments and a strong sandbox for each request to play in, feet of clay are introduced into PHP's system." Link So... it's not supported 'cause it makes things harder? 'Cause only the things that are easy are worth doing right? (To be fair, as Emil H pointed out, this is generally attributed to bad 3rd-party libs not being thread-safe, whereas the core of PHP is.)
No native Unicode support
Native Unicode support is slated for PHP6
I'm sure glad that we haven't lived in a global environment where we might have need to speak to people in other languages for the past, oh 18 years. Oh wait. (To be fair, the fact that everything doesn't use Unicode in this day and age really annoys me. My point is I shouldn't have to do any extra work to make Unicode happen. This isn't only a PHP problem.)
I have other beefs with the language. These are just some.
Jeff Atwood has an old post about why PHP sucks. He also says it doesn't matter. I don't agree but there we are.
XSLT.
XSLT is baffling, to begin with. The metaphor is completely different from anything else I know.
The thing was designed by a committee so deep in angle brackets that it comes off as a bizarre frankenstein.
The weird incantations required to specify the output format.
The built-in, invisible rules.
The odd bolt-on stuff, like scripts.
The dependency on XPath.
The tools support has been pretty slim, until lately. Debugging XSLT in the early days was an exercise in navigating in complete darkness. The tools change that but, still XSLT tops my list.
XSLT is weird enough that most people just ignore it. If you must use it, you need an XSLT Shaman to give you the magic incantations to make things go.
DOS Batch files. Not sure if this qualifies as programming language at all.
It's not that you can't solve your problems, but if you are used to bash...
Just my two cents.
Not sure if its a true language, but I hate Makefiles.
Makefiles have meaningful differences between space and TAB, so even if two lines appear identical, they do not run the same.
Make also relies on a complex set of implicit rules for many languages, which are difficult to learn, but then are frequently overridden by the make file.
A Makefile system is typically spread over many, many files, across many directories.
With virtually no scoping or abstraction, a change to a make file several directories away can prevent my source from building. Yet the error message is invariably a compliation error, not a meaningful error about make, or the makefiles.
Any environment I've worked in that uses makefiles successfully has a full-time Make expert. And all this to shave a few minutes off compilation??
The worse language I've ever seen come from the tool praat, which is a good audio analysis tool. It does a pretty good job until you use the script language. sigh bad memories.
Tiny praat script tutorial for beginners
Function call
We've listed at least 3 different function calling syntax :
The regular one
string = selected("Strings")
Nothing special here, you assign to the variable string the result of the selected function. Not really scary... yet.
The "I'm invoking some GUI command with parameters"
Create Strings as file list... liste 'path$'/'type$'
As you can see, the function name start at "Create" and finish with the "...". The command "Create Strings as file list" is the text displayed on a button or a menu (I'm to scared to check) on praat. This command take 2 parameters liste and an expression. I'm going to look deeper in the expression 'path$'/'type$'
Hmm. Yep. No spaces. If spaces were introduced, it would be separate arguments. As you can imagine, parenthesis don't work. At this point of the description I would like to point out the suffix of the variable names. I won't develop it in this paragraph, I'm just teasing.
The "Oh, but I want to get the result of the GUI command in my variable"
noliftt = Get number of strings
Yes we can see a pattern here, long and weird function name, it must be a GUI calling. But there's no '...' so no parameters. I don't want to see what the parser looks like.
The incredible type system (AKA Haskell and OCaml, praat is coming to you)
Simple natives types
windowname$ = left$(line$,length(line$)-4)
So, what's going on there?
It's now time to look at the convention and types of expression, so here we got :
left$ :: (String, Int) -> String
lenght :: (String) -> Int
windowname$ :: String
line$ :: String
As you can see, variable name and function names are suffixed with their type or return type. If their suffix is a '$', then it return a string or is a string. If there is nothing it's a number. I can see the point of prefixing the type to a variable to ease implementation, but to suffix, no sorry, I can't
Array type
To show the array type, let me introduce a 'tiny' loop :
for i from 1 to 4
Select... time time
bandwidth'i'$ = Get bandwidth... i
forhertz'i'$ = Get formant... i
endfor
We got i which is a number and... (no it's not a function)
bandwidth'i'$
What it does is create string variables : bandwidth1$, bandwidth2$, bandwidth3$, bandwidth4$ and give them values. As you can expect, you can't create two dimensional array this way, you must do something like that :
band2D__'i'__'j'$
The special string invocation
outline$ = "'time'#F'i':'forhertznum'Hz,'bandnum'Hz, 'spec''newline$'"
outline$ >> 'outfile$'
Strings are weirdly (at least) handled in the language. the '' is used to call the value of a variable inside the global "" string. This is _weird_. It goes against all the convention built into many languages from bash to PHP passing by the powershell. And look, it even got redirection. Don't be fooled, it doesn't work like in your beloved shell. No you have to get the variable value with the ''
Da Wonderderderfulful execution model
I'm going to put the final touch to this wonderderderfulful presentation by talking to you about the execution model. So as in every procedural languages you got instruction executed from top to bottom, there is the variables and the praat GUI. That is you code everything on the praat gui, you invoke commands written on menu/buttons.
The main window of praat contain a list of items which can be :
files
list of files (created by a function with a wonderderfulful long long name)
Spectrogramm
Strings (don't ask)
So if you want to perform operation on a given file, you must select the file in the list programmatically and then push the different buttons to take some actions. If you wanted to pass parameters to a GUI action, you have to follow the GUI layout of the form for your arguments, for example "To Spectrogram... 0.005 5000 0.002 20 Gaussian
" is like that because it follows this layout:
Needless to say, my nightmares are filled with praat scripts dancing around me and shouting "DEBUG MEEEE!!".
More information at the praat site, under the well-named section "easy programmable scripting language"
Well since this question refuses to die and since the OP did prod me into answering...
I humbly proffer for your consideration Authorware (AW) as the worst language it is possible to create. (n.b. I'm going off recollection here, it's been ~6 years since I used AW, which of course means there's a number of awful things I can't even remember)
the horror, the horror http://img.brothersoft.com/screenshots/softimage/a/adobe_authorware-67096-1.jpeg
Let's start with the fact that it's a Macromedia product (-10 points), a proprietary language (-50 more) primarily intended for creating e-learning software and moreover software that could be created by non-programmers and programmers alike implemented as an iconic language AND a text language (-100).
Now if that last statement didn't scare you then you haven't had to fix WYSIWYG generated code before (hello Dreamweaver and Frontpage devs!), but the salient point is that AW had a library of about 12 or so elements which could be dragged into a flow. Like "Page" elements, Animations, IFELSE, and GOTO (-100). Of course removing objects from the flow created any number of broken connections and artifacts which the IDE had variable levels of success coping with. Naturally the built in wizards (-10) were a major source of these.
Fortunately you could always step into a code view, and eventually you'd have to because with a limited set of iconic elements some things just weren't possible otherwise. The language itself was based on TUTOR (-50) - a candidate for worst language itself if only it had the ambition and scope to reach the depths AW would strive for - about which wikipedia says:
...the TUTOR language was not easy to
learn. In fact, it was even suggested
that several years of experience with
the language would be required before
programmers could build programs worth
keeping.
An excellent foundation then, which was built upon in the years before the rise of the internet with exactly nothing. Absolutely no form of data structure beyond an array (-100), certainly no sugar (real men don't use switch statements?) (-10), and a large splash of syntactic vinegar ("--" was the comment indicator so no decrement operator for you!) (-10). Language reference documentation was provided in paper or zip file formats (-100), but at least you had the support of the developer run usegroup and could quickly establish the solution to your problem was to use the DLL or SWF importing features of AW to enable you to do the actual coding in a real language.
AW was driven by a flow (with necessary PAUSE commands) and therefore has all the attendant problems of a linear rather than event based system (-50), and despite the outright marketing lies of the documentation it was not object oriented (-50) either. All code reuse was achieved through GOTO. No scope, lots of globals (-50).
It's not the language's fault directly, but obviously no source control integration was possible, and certainly no TDD, documentation generation or any other add-on tool you might like.
Of course Macromedia met the challenge of the internet head on with a stubborn refusal to engage for years, eventually producing the buggy, hard to use, security nightmare which is Shockwave (-100) to essentially serialise desktop versions of the software through a required plugin (-10). AS HTML rose so did AW stagnate, still persisting with it's shockwave delivery even in the face of IEEE SCORM javascript standards.
Ultimately after years of begging and promises Macromedia announced a radical new version of AW in development to address these issues, and a few years later offshored the development and then cancelled the project. Although of course Macromedia are still selling it (EVIL BONUS -500).
If anything else needs to be said, this is the language which allows spaces in variable names (-10000).
If you ever want to experience true pain, try reading somebody else's uncommented hungarian notation in a language which isn't case sensitive and allows variable name spaces.
Total Annakata Arbitrary Score (AAS): -11300
Adjusted for personal experience: OutOfRangeException
(apologies for length, but it was cathartic)
Seriously: Perl.
It's just a pain in the ass to code with for beginners and even for semi-professionals which work with perl on a daily basis. I can constantly see my colleagues struggle with the language, building the worst scripts, like 2000 lines with no regard of any well accepted coding standard. It's the worst mess i've ever seen in programming.
Now, you can always say, that those people are bad in coding (despite the fact that some of them have used perl for a lot of years, now), but the language just encourages all that freaking shit that makes me scream when i have to read a script by some other guy.
MS Access Visual Basic for Applications (VBA) was also pretty bad. Access was bad altogether in that it forced you down a weak paradigm and was deceptively simple to get started, but a nightmare to finish.
No answer about Cobol yet? :O
Old-skool BASICs with line numbers would be my choice. When you had no space between line numbers to add new lines, you had to run a renumber utility, which caused you to lose any mental anchors you had to what was where.
As a result, you ended up squeezing in too many statements on a single line (separated by colons), or you did a goto or gosub somewhere else to do the work you couldn't cram in.
MUMPS
I worked in it for a couple years, but have done a complete brain dump since then. All I can really remember was no documentation (at my location) and cryptic commands.
It was horrible. Horrible! HORRIBLE!!!
There are just two kinds of languages: the ones everybody complains about and the ones nobody uses.
Bjarne Stroustrup
I haven't yet worked with many languages and deal mostly with scripting languages; out of these VBScript is the one I like least. Although it has some handy features, some things really piss me off:
Object assignments are made using the Set keyword:
Set foo = Nothing
Omitting Set is one of the most common causes of run-time errors.
No such thing as structured exception handling. Error checking is like this:
On Error Resume Next
' Do something
If Err.Number <> 0
' Handle error
Err.Clear
End If
' And so on
Enclosing the procedure call parameters in parentheses requires using the Call keyword:
Call Foo (a, b)
Its English-like syntax is way too verbose. (I'm a fan of curly braces.)
Logical operators are long-circuit. If you need to test a compound condition where the subsequent condition relies on the success of the previous one, you need to put conditions into separate If statements.
Lack of parameterized class constructors.
To wrap a statement into several lines, you have to use an underscore:
str = "Hello, " & _
"world!"
Lack of multiline comments.
Edit: found this article: The Flangy Guide to Hating VBScript. The author sums up his complaints as "VBS isn't Python" :)
Objective-C.
The annotations are confusing, using brackets to call methods still does not compute in my brain, and what is worse is that all of the library functions from C are called using the standard operators in C, -> and ., and it seems like the only company that is driving this language is Apple.
I admit I have only used the language when programming for the iPhone (and looking into programming for OS X), but it feels as if C++ were merely forked, adding in annotations and forcing the implementation and the header files to be separate would make much more sense.
PROGRESS 4GL (apparently now known as "OpenEdge Advanced Business Language").
PROGRESS is both a language and a database system. The whole language is designed to make it easy to write crappy green-screen data-entry screens. (So start by imagining how well this translates to Windows.) Anything fancier than that, whether pretty screens, program logic, or batch processing... not so much.
I last used version 7, back in the late '90s, so it's vaguely possible that some of this is out-of-date, but I wouldn't bet on it.
It was originally designed for text-mode data-entry screens, so on Windows, all screen coordinates are in "character" units, which are some weird number of pixels wide and a different number of pixels high. But of course they default to a proportional font, so the number of "character units" doesn't correspond to the actual number of characters that will fit in a given space.
No classes or objects.
No language support for arrays or dynamic memory allocation. If you want something resembling an array, you create a temporary in-memory database table, define its schema, and then get a cursor on it. (I saw a bit of code from a later version, where they actually built and shipped a primitive object-oriented system on top of these in-memory tables. Scary.)
ISAM database access is built in. (But not SQL. Who needs it?) If you want to increment the Counter field in the current record in the State table, you just say State.Counter = State.Counter + 1. Which isn't so bad, except...
When you use a table directly in code, then behind the scenes, they create something resembling an invisible, magic local variable to hold the current cursor position in that table. They guess at which containing block this cursor will be scoped to. If you're not careful, your cursor will vanish when you exit a block, and reset itself later, with no warning. Or you'll start working with a table and find that you're not starting at the first record, because you're reusing the cursor from some other block (or even your own, because your scope was expanded when you didn't expect it).
Transactions operate on these wild-guess scopes. Are we having fun yet?
Everything can be abbreviated. For some of the offensively long keywords, this might not seem so bad at first. But if you have a variable named Index, you can refer to it as Index or as Ind or even as I. (Typos can have very interesting results.) And if you want to access a database field, not only can you abbreviate the field name, but you don't even have to qualify it with the table name; they'll guess the table too. For truly frightening results, combine this with:
Unless otherwise specified, they assume everything is a database access. If you access a variable you haven't declared yet (or, more likely, if you mistype the variable name), there's no compiler error: instead, it goes looking for a database field with that name... or a field that abbreviates to that name.
The guessing is the worst. Between the abbreviations and the field-by-default, you could get some nasty stuff if you weren't careful. (Forgot to declare I as a local variable before using it as a loop variable? No problem, we'll just randomly pick a table, grab its current record, and completely trash an arbitrarily-chosen field whose name starts with I!)
Then add in the fact that an accidental field-by-default access could change the scope it guessed for your tables, thus breaking some completely unrelated piece of code. Fun, yes?
They also have a reporting system built into the language, but I have apparently repressed all memories of it.
When I got another job working with Netscape LiveWire (an ill-fated attempt at server-side JavaScript) and classic ASP (VBScript), I was in heaven.
The worst language? BancStar, hands down.
3,000 predefined variables, all numbered, all global. No variable declaration, no initialization. Half of them, scattered over the range, reserved for system use, but you can use them at your peril. A hundred or so are automatically filled in as a result of various operations, and no list of which ones those are. They all fit in 38k bytes, and there is no protection whatsoever for buffer overflow. The system will cheerfully let users put 20 bytes in a ten byte field if you declared the length of an input field incorrectly. The effects are unpredictable, to say the least.
This is a language that will let you declare a calculated gosub or goto; due to its limitations, this is frequently necessary. Conditionals can be declared forward or reverse. Picture an "If" statement that terminates 20 lines before it begins.
The return stack is very shallow, (20 Gosubs or so) and since a user's press of any function key kicks off a different subroutine, you can overrun the stack easily. The designers thoughtfully included a "Clear Gosubs" command to nuke the stack completely in order to fix that problem and to make sure you would never know exactly what the program would do next.
There is much more. Tens of thousands of lines of this Lovecraftian horror.
The .bat files scripting language on DOS/Windows. God only knows how un-powerful is this one, specially if you compare it to the Unix shell languages (that aren't so powerful either, but way better nonetheless).
Just try to concatenate two strings or make a for loop. Nah.
VSE, The Visual Software Environment.
This is a language that a prof of mine (Dr. Henry Ledgard) tried to sell us on back in undergrad/grad school. (I don't feel bad about giving his name because, as far as I can tell, he's still a big proponent and would welcome the chance to convince some folks it's the best thing since sliced bread). When describing it to people, my best analogy is that it's sort of a bastard child of FORTRAN and COBOL, with some extra bad thrown in. From the only really accessible folder I've found with this material (there's lots more in there that I'm not going to link specifically here):
VSE Overview (pdf)
Chapter 3: The VSE Language (pdf) (Not really an overview of the language at all)
Appendix: On Strings and Characters (pdf)
The Software Survivors (pdf) (Fevered ramblings attempting to justify this turd)
VSE is built around what they call "The Separation Principle". The idea is that Data and Behavior must be completely segregated. Imagine C's requirement that all variables/data must be declared at the beginning of the function, except now move that declaration into a separate file that other functions can use as well. When other functions use it, they're using the same data, not a local copy of data with the same layout.
Why do things this way? We learn that from The Software Survivors that Variable Scope Rules Are Hard. I'd include a quote but, like most fools, it takes these guys forever to say anything. Search that PDF for "Quagmire Of Scope" and you'll discover some true enlightenment.
They go on to claim that this somehow makes it more suitable for multi-proc environments because it more closely models the underlying hardware implementation. Riiiight.
Another choice theme that comes up frequently:
INCREMENT DAY COUNT BY 7 (or DAY COUNT = DAY COUNT + 7)
DECREMENT TOTAL LOSS BY GROUND_LOSS
ADD 100.3 TO TOTAL LOSS(LINK_POINTER)
SET AIRCRAFT STATE TO ON_THE_GROUND
PERCENT BUSY = (TOTAL BUSY CALLS * 100)/TOTAL CALLS
Although not earthshaking, the style
of arithmetic reflects ordinary usage,
i.e., anyone can read and understand
it - without knowing a programming
language. In fact, VisiSoft arithmetic
is virtually identical to FORTRAN,
including embedded complex arithmetic.
This puts programmers concerned with
their professional status and
corresponding job security ill at
ease.
Ummm, not that concerned at all, really. One of the key selling points that Bill Cave uses to try to sell VSE is the democratization of programming so that business people don't need to indenture themselves to programmers who use crazy, arcane tools for the sole purpose of job security. He leverages this irrational fear to sell his tool. (And it works-- the federal gov't is his biggest customer). I counted 17 uses of the phrase "job security" in the document. Examples:
... and fit only for those desiring artificial job security.
More false job security?
Is job security dependent upon ensuring the other guy can't figure out what was done?
Is job security dependent upon complex code...?
One of the strongest forces affecting the acceptance of new technology is the perception of one's job security.
He uses this paranoia to drive wedge between the managers holding the purse strings and the technical people who have the knowledge to recognize VSE for the turd that it is. This is how he squeezes it into companies-- "Your technical people are only saying it sucks because they're afraid it will make them obsolete!"
A few additional choice quotes from the overview documentation:
Another consequence of this approach
is that data is mapped into memory
on a "What You See Is What You Get"
basis, and maintained throughout.
This allows users to move a complete
structure as a string of characters
into a template that descrives each
individual field. Multiple templates
can be redefined for a given storage
area. Unlike C and other languages,
substructures can be moved without the problems of misalignment due to
word boundary alignment standards.
Now, I don't know about you, but I know that a WYSIWYG approach to memory layout is at the top of my priority list when it comes to language choice! Basically, they ignore alignment issues because only old languages that were designed in the '60's and '70's care about word alignment. Or something like that. The reasoning is bogus. It made so little sense to me that I proceeded to forget it almost immediately.
There are no user-defined types in VSE. This is a far-reaching
decision that greatly simplifies the
language. The gain from a practical
point of view is also great. VSE
allows the designer and programmer to
organize a program along the same
lines as a physical system being
modeled. VSE allows structures to be
built in an easy-to-read, logical
attribute hierarchy.
Awesome! User-defined types are lame. Why would I want something like an InputMessage object when I can have:
LINKS_IN_USE INTEGER
INPUT_MESSAGE
1 ORIGIN INTEGER
1 DESTINATION INTEGER
1 MESSAGE
2 MESSAGE_HEADER CHAR 10
2 MESSAGE_BODY CHAR 24
2 MESSAGE_TRAILER CHAR 10
1 ARRIVAL_TIME INTEGER
1 DURATION INTEGER
1 TYPE CHAR 5
OUTPUT_MESSAGE CHARACTER 50
You might look at that and think, "Oh, that's pretty nicely formatted, if a bit old-school." Old-school is right. Whitespace is significant-- very significant. And redundant! The 1's must be in column 3. The 1 indicates that it's at the first level of the hierarchy. The Symbol name must be in column 5. You hierarchies are limited to a depth of 9.
Well, ok, but is that so awful? Just wait:
It is well known that for reading
text, use of conventional upper/lower
case is more readable. VSE uses all
upper case (except for comments). Why?
The literature in psychology is based
on prose. Programs, simply, are not
prose. Programs are more like math,
accounting, tables. Program fonts
(usually Courier) are almost
universally fixed-pitch, and for good
reason – vertical alignment among
related lines of code. Programs in
upper case are nicely readable, and,
after a time, much better in our
opinion
Nothing like enforcing your opinion at the language level! That's right, you cannot use any lower case in VSE unless it's in a comment. Just keep your CAPSLOCK on, it's gonna be stuck there for a while.
VSE subprocedures are called processes. This code sample contains three processes:
PROCESS_MUSIC
EXECUTE INITIALIZE_THE_SCENE
EXECUTE PROCESS_PANEL_WIDGET
INITIALIZE_THE_SCENE
SET TEST_BUTTON PANEL_BUTTON_STATUS TO ON
MOVE ' ' TO TEST_INPUT PANEL_INPUT_TEXT
DISPLAY PANEL PANEL_MUSIC
PROCESS_PANEL_WIDGET
ACCEPT PANEL PANEL_MUSIC
*** CHECK FOR BUTTON CLICK
IF RTG_PANEL_WIDGET_NAME IS EQUAL TO 'TEST_BUTTON'
MOVE 'I LIKE THE BEATLES!' TO TEST_INPUT PANEL_INPUT_TEXT.
DISPLAY PANEL PANEL_MUSIC
All caps as expected. After all, that's easier to read. Note the whitespace. It's significant again. All process names must start in column 0. The initial level of instructions must start on column 4. Deeper levels must be indented exactly 3 spaces. This isn't a big deal, though, because you aren't allowed to do things like nest conditionals. You want a nested conditional? Well just make another process and call it. And note the delicious COBOL-esque syntax!
You want loops? Easy:
EXECUTE NEXT_CALL
EXECUTE NEXT_CALL 5 TIMES
EXECUTE NEXT_CALL TOTAL CALL TIMES
EXECUTE NEXT_CALL UNTIL NO LINES ARE AVAILABLE
EXECUTE NEXT_CALL UNTIL CALLS_ANSWERED ARE EQUAL TO CALLS_WAITING
EXECUTE READ_MESSAGE UNTIL LEAD_CHARACTER IS A DELIMITER
Ugh.
Here is the contribution to my own question:
Origin LabTalk
My all-time favourite in this regard is Origin LabTalk.
In LabTalk the maximum length of a string variable identifier is one character.
That is, there are only 26 string variables at all. Even worse, some of them are used by Origin itself, and it is not clear which ones.
From the manual:
LabTalk uses the % notation to define
a string variable. A legal string
variable name must be a % character
followed by a single alphabetic
character (a letter from A to Z).
String variable names are
caseinsensitive. Of all the 26 string
variables that exist, Origin itself
uses 14.
Doors DXL
For me the second worst in my opinion is Doors DXL.
Programming languages can be divided into two groups:
Those with manual memory management (e.g. delete, free) and those with a garbage collector.
Some languages offer both, but DXL is probably the only language in the world that
supports neither. OK, to be honest this is only true for strings, but hey, strings aren't exactly
the most rarely used data type in requirements engineering software.
The consequence is that memory used by a string can never be reclaimed and
DOORS DXL leaks like sieve.
There are countless other quirks in DXL, just to name a few:
DXL function syntax
DXL arrays
Cold Fusion
I guess it's good for designers but as a programmer I always felt like one hand was tied behind my back.
The worst two languages I've worked with were APL, which is relatively well known for languages of its age, and TECO, the language in which the original Emacs was written. Both are notable for their terse, inscrutable syntax.
APL is an array processing language; it's extremely powerful, but nearly impossible to read, since every character is an operator, and many don't appear on standard keyboards.
TECO had a similar look, and for a similar reason. Most characters are operators, and this special purpose language was devoted to editing text files. It was a little better, since it used the standard character set. And it did have the ability to define functions, which was what gave life to emacs--people wrote macros, and only invoked those after a while. But figuring out what a program did or writing a new one was quite a challenge.
LOLCODE:
HAI
CAN HAS STDIO?
VISIBLE "HAI WORLD!"
KTHXBYE
Seriously, the worst programming language ever is that of Makefiles. Totally incomprehensible, tabs have a syntactic meaning and not even a debugger to find out what's going on.
I'm not sure if you meant to include scripting languages, but I've seen TCL (which is also annoying), but... the mIRC scripting language annoys me to no end.
Because of some oversight in the parsing, it's whitespace significant when it's not supposed to be. Conditional statements will sometimes be executed when they're supposed to be skipped because of this. Opening a block statement cannot be done on a separate line, etc.
Other than that it's just full of messy, inconsistent syntax that was probably designed that way to make very basic stuff easy, but at the same time makes anything a little more complex barely readable.
I lost most of my mIRC scripts, or I could have probably found some good examples of what a horrible mess it forces you to create :(
Regular expressions
It's a write only language, and it's hard to verify if it works correctly for the right inputs.
Visual Foxpro
I can't belive nobody has said this one:
LotusScript
I thinks is far worst than php at least.
Is not about the language itself which follows a syntax similar to Visual Basic, is the fact that it seem to have a lot of functions for extremely unuseful things that you will never (or one in a million times) use, but lack support for things you will use everyday.
I don't remember any concrete example but they were like:
"Ok, I have an event to check whether the mouse pointer is in the upper corner of the form and I don't have an double click event for the Form!!?? WTF??"
Twice I've had to work in 'languages' where you drag-n-dropped modules onto the page and linked them together with lines to show data flow. (One claimed to be a RDBMs, and the other a general purpose data acquisition and number crunching language.)
Just thinking of it makes me what to throttle someone. Or puke. Or both.
Worse, neither exposed a text language that you could hack directly.
I find myself avoid having to use VBScript/Visual Basic 6 the most.
I use primarily C++, javascript, Java for most tasks and dabble in ruby, scala, erlang, python, assembler, perl when the need arises.
I, like most other reasonably minded polyglots/programmers, strongly feel that you have to use the right tool for the job - this requires you to understand your domain and to understand your tools.
My issue with VBscript and VB6 is when I use them to script windows or office applications (the right domain for them) - i find myself struggling with the language (they fall short of being the right tool).
VBScript's lack of easy to use native data structures (such as associative containers/maps) and other quirks (such as set for assignment to objects) is a needless and frustrating annoyance, especially for a scripting language. Contrast it with Javascript (which i now use to program wscript/cscript windows and do activex automation scripts) which is far more expressive. While there are certain things that work better with vbscript (such as passing arrays back and forth from COM objects is slightly easier, although it is easier to pass event handlers into COM components with jscript), I am still surprised by the amount of coders that still use vbscript to script windows - I bet if they wrote the same program in both languages they would find that jscript works with you much more than vbscript, because of jscript's native hash data types and closures.
Vb6/VBA, though a little better than vbscript in general, still has many similar issues where (for their domain) they require much more boiler plate to do simple tasks than what I would like and have seen in other scripting languages.
In 25+ years of computer programming, by far the worst thing I've ever experienced was a derivative of MUMPS called Meditech Magic. It's much more evil than PHP could ever hope to be.
It doesn't even use '=' for assignment! 100^b assigns a value of 100 to b and is read as "100 goes to b". Basically, this language invented its own syntax from top to bottom. So no matter how many programming languages you know, Magic will be a complete mystery to you.
Here is 100 bottles of beer on the wall written in this abomination of a language:
BEERv1.1,
100^b,T("")^#,DO{b'<1 NN(b,"bottle"_IF{b=1 " ";"s "}_"of beer on the wall")^#,
N(b,"bottle"_IF{b=1 " ";"s "}_"of beer!")^#,
N("You take one down, pass it around,")^#,b-1^b,
N(b,"bottle"_IF{b=1 " ";"s "}_"of beer on the wall!")^#},
END;
TCL. It only compiles code right before it executes, so it's possible that if your code never went down branch A while testing, and one day, in the field it goes down branch A, it could have a SYNTAX ERROR!

How do you write code that is easily read by other people who have had no hand in writing any part of it?

How do you write code that is easily read by other people and who have had no hand in writing any part of it?
The best way to ensure that others can read your code is to make sure that it is clear and concise. Namely,
Use self documenting names for variables, functions, and classes.
Comment complex algorithms so that the reader doesn't have to spend to long figuring out what it does.
Ensure that tabbing and line breaks are constant throughout the code.
Beyond that you start to get in to the areas that might be a bit subjective, most people should agree on these items.
You may want to take a look at Clean Code by Robert C. Martin. It offers up a lot of useful practices for ensuring your code is readable.
Additionally, if your code is supported by a number of unit tests that thoroughly test your code, it offers a way for your user to understand the code by looking at what the tests are doing. You will also find that if you follow the Test Driven Development process, and you write tests for each bit of functionality, your functions tend to be small, do one thing only and do it well, and tend to flow more like a story than simply a large complex web of "stuff".
Tests tend to stay up-to-date more than comments. I often ignore comments anymore due to simple fact that they become obsolete very quickly.
This question is subjective, and should be avoided on StackOverflow, as per the FAQ
What kind of questions should I not
ask here?
Avoid asking questions that are
subjective, argumentative, or require
extended discussion. This is a place
for questions that can be answered!
The short answer would be:
Avoid excessive commenting:
// add one to the count:
i++;
Use good variable and method names:
int x = i + j;
int runSum = prevSum += newValue;
Use coding shorthand where available:
if (x == y)
{
z = a;
}
else
{
z = b;
}
z = (x == y) ? a : b;
Keep code nice, clear and simple. Don't comment what you're doing when it's obvious (for instance I know what a foreach or if does, I don't normally need an explanation).
Code tricks (such as auto properties) that make simple things take up fewer lines are good too.
Buy & read Code Complete 2. There's loads of stuff in there about writing easy to read / maintain code.
I don't think it's a subjective question, but it's too broad! It's not just about commenting and giving good variables names. It deals with how humans comprehends code. So your system must be implemented in a way that the reader can easily construct a mental model of its design in two way:
Top-down: assuming the user knows the system domain, he tends to make assumptions on how it would be implemented, so he'll scan the system packages and classes looking for entities he can identify. Giving good names to your classes and properly modularizing it would help very much.
Bottom-up: once the user reaches a portion of code he'll start navigation from there, building chunks of knowledge. If your system has low cohesion and lots of implicit dependencies the user will be lost.
Kent Beck adopts three principles: Communication, Simplicity and Flexibility. Of course, sometimes you'll have to trade simplicity for flexibility, and vice-versa.
This could go on and on. The answer to this question fits in a large book. As #rmbarnes suggested, buy and read Code Complete 2. I also suggest Implementation Patterns by Kent Beck - its highly related to your question.
Document the code as to why it does what it does.
Make sure that all variables functions etc. are named consistently and descriptively
Use white space to group logical portions of code together, so it flows while reading.
Place the functions/methods etc. in a logical order.
(this one is my personal preference) Make sure that code can easily be read on the screen without having to scroll horizontally (some people say vertically too, but this doesn't seem to bother me).
Since everyone else said pretty much what I'm thinking when I read this question, I'll just share two books related to this subject that you might be interested in reading. These books use open source code examples to explain how to read and write high quality code. In addition to Code Complete, I think they are valuable resources when you want to write good code in any language.
Code Reading: The Open Source Perspective
Code Quality: The Open Source Perspective
My rules:
Give everything a meaningful name, and call it what it is. Avoid using "x" and "y" for variables.
Don't abbreviate ANYTHING. I don't care how long the variable name is, don't abbreviate, even with comments. Interpretation of abbreviations is subjective. Does Cmp mean computer? Computer? Company? Compliment? Make it a strong rule, no exceptions, and its easy to follow.
Don't put multiple statements on the same line. Each line performs a single action.
Avoid Hungarian Notation like the plague. Or is it ntHungarian?
Use brackets even for single-line (if, for) substructures. Indentation differences are too easy to lose.
A lot of good answers here, I would like to add something from the perspective of an engineer who likes the big picture. I frequently found that getting a high level overview, in terms of class diagram or a package level overview (diagram/comments etc), heck if nothing exists a 10 line header comments in a file to help me a lot. We can use Doxygen/Javadocs to generate them, or spend 10-15 minutes to just jot down something in comments section.
They dont have to be 100% accurate, and I doubt the overall structure of classes/packages will change without a complete rewrite.
I personally found this kind of big picture overview very helpful and am sure there are others who feel the same.
Probably the most important point is to keep your syntax consistent. I would also have a look at the design guidelines for the language you are writing in.
I am most likely in the minority, but I don't mind whitespace. I LOVE WHITESPACE. Since the compiler takes it out and HD space being so cheap I like to have white space in my code.
For example I like:
int total = 10;
int sum = 0;
for (int i = 0; i < total; i++)
{
sum += i;
}
// Next coding statement is a space below the bracket
return sum;
I do not like:
int total = 10;int sum = 0;
for (int i = 0; i < total; i++)
{
sum += i;
}
return sum;
What I also put in Brackets even though technically they are not needed. The best example is the if statement. I find it greatly helps readability.
if(true)
// some action
if(true)
{
// Some action
}
The best code to me, is one that as simple as possible. With the least comments as possible, and most importantly works.
From being a developer with several years under the belt, this used to be a real question for me. I couldn't even say how many hours I passed thinking about this and trying different things in my code. The above answers are very nice too. I just want to add a thing or two.
We each have different things that make our reading different than the others. Something that you find easy to read, might really be hard for somebody else to read.
Cleanliness of your code is a very important aspect. Soon as it gets too cramped just forget about it.
Most important: You are you own teacher. No matter what style you follow, you will want to change a thing or two based on your experience. As months pass and you have to go back to your old for fixes or documentation, you will have the "I can't believe I wrote code that reads like that" effect. Take notes of what was bugging you with the code readability and make sure not to write like that again.

Resources