Favorite Programming Language Features? 312
johnnyb asks: "I'm curious what everyone's favorite programming language features are. I'm looking for both the general and the specific. I'm especially looking for features that few people know about or use, but are really useful for those who do know about them. What are your favorite programming language features?"
"A couple of examples to kick off the conversation:
- Continuations
Continuations are very interesting, because they can be used to implement a number of flow-control features such as exceptions, coroutines, cooperative multithreading, and are better at modelling web interactions. This is a more general feature, but most people use these in conjunction with either scheme or ML.
- Tuple-returning
It is a huuuuge time-saver when languages like Perl allow functions to return tuples. Instructions like '($a, $b, $c) = $sth->fetchrow_array()' is a wonderful thing.
- The flip-flop operator [Perl's '..' operator]
Another perlism that I just think is cool. Read more about it here.
Simple, OOP (Score:3, Insightful)
For me it's just easier.
(Especially with XCode displaying it as a little blue box, it makes the concept easier to grasp for beginners)
That's obvious (Score:2, Insightful)
*cough*C*cough*
Re:That's obvious (Score:2)
gcc is more fun (Score:2)
void *vp;
some_label:
vp = &
goto *(vp);
Oh yeah... fill a jump table with pointers and
you can do some pretty cool stuff.
Let's not forget __asm__ with automatic register
assignment, the ability to place a variable into
a specific section of the executable, the ability
to associate a variable with a specific register,
the __builtin_expect and __builtin_constant_p
builtins... gcc kicks ass.
Slashdot mangles stuff, WTF? (Score:2)
damn well expect Slashdot to accept full ASCII.
I'll try "Code" now. Grrr.
void *vp;
some_label:
vp = &&some_label;
goto *(vp);
Easy. T-Shirt (C): (Score:2, Funny)
Re:Easy. T-Shirt (C): (Score:2)
language with some syntactic sugar (for, while).
I miss a goto in ksh, though.
ON ERROR RESUME NEXT (Score:2, Funny)
Lists (Score:2)
Tcl and Postscript both offer lists and lists within lists, without having to do anything fancy. Perl does have this, to an extent, but only on static lists. Anything dynamic adds a few lines of code and confuses things pretty easily. Of course, all of this came from Lisp, but I learned car and cdr and that was more than enough for me.
In short, lists only work when recursion is right at the tip of your fingertips in your language. If XSLT-2.0 works on tree fragments, we will have lists there as well.
Re:Lists (Score:3, Informative)
What do you mean by 'static lists'? Do you mean they're immutable?
You can do
to add to a list in a list. The syntax is tough, but I think it does what you mean. @{} is like a cast-to-list. should be helpful.
Re:Lists (Score:2)
I would guess he means "lists that are hardcoded into the program", I forget the proper term for this.
He was saying that perl creates nested arrays nicely:
But when it comes to actually creating a structure like that dynamically using push or unshift, the code gets really ugly. And I think you proved his point ;)
Re:Lists (Score:2)
anonymous inner classes (Score:4, Insightful)
It's certainly not an unknown feature, but I couldn't live without it.
Re:anonymous inner classes (Score:2)
Re:anonymous inner classes (Score:3, Insightful)
Java's inner classes (anonymous or named) are not even first class! (Try coding an inner class that refers to a non-final attribute in its enclosing scope.)
They are better than nothing though ...
Re:anonymous inner classes (Score:4, Informative)
This isn't quite right. First off, they are first class [c2.com], and you can refer to a non-final attribute from a named or anonymous inner class. What you can't do is refer to a non-final local variable from an anonymous inner class.
The intended effect is similar to closures - variables referenced from the enclosing scope have the value when the closure was instantiated (see, e.g. Scheme) - except that unlike scheme, you can't modify the now-private copy. If you want a modifiable copy, you just make one, like so:
final finalFoo = foo; Object bar = new Object() { private myFoo = finalFoo; // myFoo now acts as 'foo' would if this was // *really* a closure.
}
I'd agree that the construct sucks. I'd rather be in a language with closures myself.
Many (Score:5, Interesting)
Next I love ruby's block system, especially for stuff like this. It comes in super handy for a ton of stuff. Especially when I'm doing XML.
Also, there is another thing that I first discovered in python Save me a temporary variable, w00t.
Lastly, its not really a language feature, but in any object oriented language I love being able to serialize the objects. It's so simple to use pickle or any other serialization library and just write objects out to file or network. I never have to design a binary file format ever again. It's even better when you use Ruby and you can marshall objects into XML or YAML with a single method. Then you've got a human readable and editable file format that you can magically transform into objects again later. Super useful.
Re:Many (Score:3, Informative)
y ^= x
x ^= y
bitwise, no overflow worries...
Re:Many (Score:5, Insightful)
To that I answer by quoting Dijkstra: "if we wish to count lines of code, we should not regard them as 'lines produced' but as 'lines spent': the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger." (EWD1036 [utexas.edu], page 11)
And so for example even your 10-line, 40-token launcher is too long; its information content can be expressed succintly as "new Webserver(80)" or even "Webserver 80" in any properly designed language.
When electronic calculators came out, accountants did not say "the calculators do all the arithmetic for you, and you are not a real accountant" (or did they?) Similarly for spreadsheet. The reality is, each time they are relieved of a chore, they find a more worthwhile thing to spend their time on, such as analysing various what-if scenerios, which had been intractible until the advent of spreadsheets --- a fine programming language in its own right. I now quote Asimov on the general idea: "The Machines are only a tool after all, which can help humanity progress faster by taking some of the burdens of calculations and interpretations off its back. The task of the human brain remains what it has always been; that of discovering new data to be analyzed, and of devising new concepts to be tested.
Dreamed-of feature (Score:5, Interesting)
In a little more detail, suppose I write a C program. It will have lots of functions and conditionals with their "blocks" surrounded by braces.
But what if I prefer my "blocks" to be started and ended by brackets instead of braces. Better yet, what if I am tired of typing these and would like indentation to control this. Or whatever -- start end commands, if you like. The point is that these are minor sytactic idiosyncracies, and we all have preferences. Why not store the code in an underlying format (XML would be okay, were it not for the bulk of it)? As long as there is a one-to-one correspondence between all possible representations, you could view it however you want.
And so on for all syntactic features. Prefer "if-fi" construction to "if () {}"? Or "if
At this point, I feel like I am repeating myself, but let me continue for a little bit. It would let each user have his/her personal favorite representation. We already let them control the colors of their syntax highlighting, lets take it a step further.
Hell, if you want to use a graphical viewer for those C programs, akin to LabView, go for it! Or (in my opinion) a much better graphical programming environment with a graph structure. The point is: you write it how you want and save it. It appears to another coder how he/she wants it to appear, but the content is exactly the same.
In short: why isn't this done? It seems like a spectacular step in unifying programming languages a bit, and letting each user tailor his preferences while maintaining compatibility. As long as there was simple one-to-one correspondence, the translation from physical representation to underlying code and back would be quick and fairly easy to handle. Are there any modern projects which attempt this? Or *any* which attempt it with some success?
On a somewhat related note, is it possible to put a "hook" to a comment in the code, and with the proper viewer have that comment displayed along with the code (say when you click the "hook", move your mouse over it, or drag the "hook" to a "comment box")? If this last paragraph doesn't make sense, please ignore it.
Re:Dreamed-of feature (Score:2)
The whole idea is to make things as uniform and regular as possible because then there is less for everyone else to learn when they look at the code. This suggestion adds a whole layer of confusion, and only buys a modicum of user preference in return. That is a poor tradeoff.
Re:Dreamed-of feature (Score:2, Interesting)
No. In some sense, this is precisely the problem I try to avoid. The bizarre preferences were chosen because that programmer/company/standards bureau liked them and/or found them useful (hopefully). By storing the content of the program, and not their silly display preferences, it would load and present to me
Re:Dreamed-of feature (Score:2)
By storing the content of the program, and not their silly display preferences, it would load and present to me however I had it set up to display it, not according to their preferences.
One of the obvious benefits is the end of the holy wars over brace and indentation style [catb.org]. Think code should be tabbed out 2 spaces instead of 4? Constantly resisting the urge to reformat everyone else's Java code to 1TBS? Want to program in C using Python-style meaningful whitespace? Not a problem. Just clicky-c
Re:Dreamed-of feature (Score:2)
One of the obvious benefits is the end of the holy wars over brace and indentation style.
Good project managers don't allow coding style holy wars to break out. They mandate a house coding style, and (if necessary) use code reviews to enforce it.
Re:Dreamed-of feature (Score:2)
Re:Dreamed-of feature (Score:2, Insightful)
I don't believe that you understand the concept becuase it seems that your argument doesn't apply.
The whole point would be that you wouldn't see the idiosyncrasies of the way that he likes his code laid out, he would in essence give you compiled code and your development e
You can simulate it in perl (Score:3, Interesting)
Re:You can simulate it in perl (Score:2)
Not sure where you're going with that, but if you can get the "language" into a perl data structure you should be good to go.
What about automatically "expanding" perl's special variables?
I think you want use English; [cpan.org].
.NET CLR (Score:2)
Re:Dreamed-of feature (Score:5, Insightful)
Sure, you can develop in your own special IDE that gives you your unique syntax. But don't you ever look at code together with other programmers who might have different preferences? Don't you ever view code published in magazines and on web sites that can't pretty-print to your specification? Training yourself to strongly prefer some kind of private language is not a very good idea.
Re:Dreamed-of feature (Score:3, Insightful)
Multiple representations can be very powerful - editing html code in parallel with the rendered version makes a lot of sense. But even in this case there is not a one to one mapping - it's not just syntax but semantics that vary (i.e. the re
You must be very smart. (Score:2)
And it would be harder for me to learn from other programmers programs and integrate their code.
Ultrageniuses and Uber Programmers are free to write their whole entire universe of code, but I bet crappy programmers like me will still stick to using what tons of people are using, and reusing other people's work (e.g. CPAN) and learning from _their_mi
Re:Dreamed-of feature (Score:2)
This has given more confidence now that obviously intelligent people are also thinking it.
The only real problem I can see with it is that if you didn't have an IDE available (you needed to hack a piece of code in notepad or something) you probably wouldn't understand the code, or at least, wouldn't be used to it.
With the size of code these days, though, it'
Re:Dreamed-of feature (Score:3, Interesting)
We use graphical interfaces for a lot of things, we should use them for programming.
SCREW the text editor based programming.
What is this bracket crap to seperate codes?
You want to seperate code? draw a circle around it. Variables that are in the circle can be accesed by code in the circle. Want to reference a variable outside the circle? Draw a line from it into the circle. And guess what - you can tell from the color of the variable name that it is not from that same object.
Textual vs. graphical representations (Score:5, Insightful)
I think this is one of those rites of passage all experienced programmers probably go through. At some stage, your experience of different languages gets to the point where you understand that the underlying concepts transcend the syntax of any specific language. A natural next step, particularly if you've seen the sort of parsing graphs used by compilers, is to assume that throwing out the "awkward" text syntax in favour of some whizzy graphical scheme will make things much easier. Some people have even done PhDs on this subject.
Unfortunately, when you try it in practice, you find it's not nearly as clear-cut as you thought. Like all that nasty, unnecessary punctuation found in many programming languages, it turns out that using a concise, precise text format is often far easier both to read and write than any graphical alternative. What can be done in one line of regex in Perl takes a whole screen of graphical representation via flow charts and state machines.
I wish you luck in your exploration of graphical alternatives, but I'm afraid the odds are pretty heavily that after a while, you'll come full circle, and understand that all that nasty "bracket crap" is there for a reason, and has survived for decades because that reason is sound.
Perl (Score:2, Flamebait)
-psy
OOh, I love! (Score:2)
Wow, I coded a JMP there, somehow its now a JNE. Hmmmmmmmm... How'd I figure that out? Deadlist on a compiled executible. Never NEVER told me it'd do that. Just did it. Almost as bad as MASM...
Sucks having to compensate for compiler errors!
Stupid Lexical Scoping Tricks (Score:3, Interesting)
Overloaded Functions are sweet.
I am also quite fond of operator overloading.
Favourites (Score:4, Insightful)
And C++
dream here.... (Score:2)
regexp functions -> functions that do what the regexp do. eg result = regexp.removeSpace(word);
Easy to understand syntax.. instead of && use AND, instead of OR use OR, etc. kinda BASICish syntax.
Garbage collection that works, unlike java where sometimes it losses things, because of programmer error. IE: if I can do it the garbage collector should clean up after me, if it can't then it should not let me do it.
Definatly object oriented, Java / C
Re:dream here.... (Score:2)
result = add(23, div(52,7));
a little more typing but not that much.
I've looked at some pretty ugly C and I've even seen some really obfuscated(sp) shell code and perl.
regexp can be a real pain in some cases when people do things that more advanced.
Also it would be good to see the result have two parts to it. result.int (gives integer value) and then result.dec (gives decimal value), then result just gives both. No double, or longs or shorts or etc, etc.
C is good for many things, but some
C pointers and arrays (Score:4, Interesting)
main() {
int x;
int y[2];
x=1;
y[1]=10;
printf("%d\n", y[x]);
printf("%d\n", x[y]);
}
What will happen?
Re:C pointers and arrays (Score:4, Informative)
Personally, I think it's a completely crappy thing. You should get an error telling you: "Attempting to use a constant like a pointer".
So it should print out "10\n10\n";
If that's an ANSI C complier: you should get a warning about no return in main, an illegal declaration of main, and an unknown function printf. You might get away with main, because I believe all functions implicitly return an int.
Kirby
Re:C pointers and arrays (Score:4, Interesting)
The x could also be a double.
double x; won't change a thing
One another interesting thing:
the x[y] line compiled into assembly(using gcc non-optimized) will use less lines of code than y[x]
Optimized they use the same.
Learning this stuff actually gave me a much better understanding of pointers and arrays and their relationship in c.
Re:C pointers and arrays (Score:2)
This works because an int * is the same size as an int. If you used char's, I'm sure it wouldn't work.
Correct me if i'm wrong.
Re:C pointers and arrays (Score:2)
Re:C pointers and arrays (Score:2)
char x;
char y[2];
x = 1;
y[1] = 99;
In this case I don't think that y[x] is the same as x[y]
Don't confuse people (Score:5, Funny)
Self-execution (Score:5, Informative)
For example, clipper can do this via blocks:
cVar
Python has the same thing via "exec":
>>> b
NameError: name 'b' is not defined
>>> exec "b=2"
>>> b
2
This means you can build up strings of code at runtime and execute them, or store field-specific database logic in another database table, and fetch it when needed.
C# is not quite so convenient - you have to build up a complete class and compile it, but it can all be done in memory at runtime so it's just a little more work. Clipper and python can both affect the current scope directly (which can be both bad or good, I suppose).
I believe ruby has blocks similar to clipper (probably better), but I don't use it, so I'm not sure. I also don't use perl, so I have no idea if it supports this...
Re:Self-execution (Score:2)
Re:Self-execution (Score:2, Informative)
Say you have a database with multiple tables that all require user data entry. You can write code for each and every data entry screen (apparently the "visual basic" school of thought), or you can write a generic data-entry screen and include pieces of code for specific field validation in the database itself - so in effect, based on structural tables, the program builds the correct code for each screen. This also saves having to di
Very useful (Score:2)
Very useful when you need to do things that the system was never designed to do.
Whole industries and many thousands of jobs depend on such useful ideas.
Re:Self-execution (Score:2, Interesting)
Several: (Score:3, Interesting)
Pattern matching (some ML:)
fun has_a [] = false
| has_a 'a'::_ = true
| has_a _::xs = has_a xs;
Simple elegent functions requireing much less if_then_else's.
Automatic garbage collection and bounds checking: enables me to write the code to do the job, not the memory management.
Polymorphic typing: I can write general functions:
fun contains x [] = false
| contains x x::_ = true
| contains x _::xs = contains xs;
That will work with any type for which equality is defined.
These are the reasons I hate C for general programming. The most important thing is efficient algorithms, without them no amount of low level optimization will help. With good algorithms, functional languages are now normally at least as fast... (and much much easier to debug and even verifiable).
From non-functional languages, the object model is wonderful when used properly.
Smalltalk & co's complete environment is a nice feature.
I also have a soft spot for BBC BASIC with its speed, interactivity and simplicity. These are combined to allow windowed applications including at least one web browser and anyone can start programming simple programs (which is missing from most modern computers)
Then there's the specialist languages. They have all sorts of nifty features (Mathematica is a good example) but I wouldn't expect them in an everyday language.
Two words: string handling (Score:5, Interesting)
Re:Two words: string handling (Score:2)
Strings are one of the most important aspects of programming; the number of complete, useful programs that have been written that didn't process or use a string in some way is close to zero.
A good programming language uses and processes strings in a speedy, efficient manner, and has a robust, easy to program means of doing so.
Re:Two words: string handling (Score:3, Insightful)
This is certainly true to a point. There are three basic kinds of data used throughout the programming world: text, numbers and logic (true/false). Pretty much any mainstream general-purpose language provides basic arithmetic and logical operators, and then an extensive library of more advanced mathematics functions. With strings, you often get basic operators, but beyond those there's a world of difference between providing a couple of upper-/lower-case conversions and having things like regular expression
This "ask Slashdot" is a concurrent "cross-post" (Score:5, Informative)
Hey, johnnyb, where else have you posted this question? When you get answers, will you analyze them and post your conclusions? It could be interesting.
Re:This "ask Slashdot" is a concurrent "cross-post (Score:5, Interesting)
My last book [cafeshops.com] took me 3 years to find the spare time to finish, so I don't suspect I'll have this done anytime soon.
I was originally going to just analyze scheme's features, but then I realized that many languages have features that need to be recognized, too. my original outline was going to be:
* Memory Management
* Symbolic programming - an intro to Scheme
* Functional Programming & Functional Programming Patterns
* Closures and higher-order functions
* Advanced Flow Control w/ Continuations
* Compile-Time programming 1: Macros
* Compile-Time programming 2: Partial Evaluation
* Compile-Time programming 3: C++ templates
* Lazy evaluation
* Lazy data structures
However, if I decide to open it up to other languages, I have no idea how I'm going to organize it or even how I will decide what to include.
Anyway, it was originally posted just to Advogato, but then I remembered that the only threads on Advogato that get any real response are flame-wars, which is sad because Advogato could be a real cool place. Then I thought "you know, this would make a good 'Ask Slashdot' as well. However, I don't expect the quality of responses on Ask Slashdot to be as good, although I expect there to be a LOT more of them.
Python's indentation syntax (Score:4, Insightful)
But after the adjustment, I've truly grown to love its spartan clarity and simplicity. I can hardly stand to look at the redundant brace-littered syntax of Java, C or Perl now.
Mike
VB could use a little of that (Score:2, Insightful)
emacs solves that problem (Score:3, Informative)
Mike
Generic programming (Score:5, Insightful)
1) I must be incrementable.
2) I must be dereferenceable.
3) You must get from begin to end in a finite number of steps.
4) The type you get when dereferencing I (I's value type) must be comparable to V.
Because of this, you can use the same find function to search through arrays, lists, vectors, maps, sets, strings, streams, and more, even though none of them inherit from each other or implement a common interface in the OOP sense.
Additionally, there's no complicated syntax for the user of the library: The great thing about abstraction is that it avoids duplication. Avoiding duplication lets you test/debug/prove correct once for greater reliability. Once you wrap your head around this simple example, you'll be surprised how deep the rabbit hole goes.
Multiple [& Possibly Overlapping] Instances? (Score:2)
A nice example is a generic "find" function
Remember the Swedish rock group ABBA? How many instances of the substring ABBA occur in the following string [and what should your generic "find" function have as a return value]?
Extra Credit: Tell me what a generic "replace" function should do when told to replace "ABBA" with "The Bee Gees".
PS: I learned just the other night that ABBA soloist Anni-Frid Lyngstad was the product of Nazi Aryan eugenics experiment [dubbed "the Lebensborn"].
I excremen
Re:Generic programming (Score:2, Interesting)
Re:Generic programming (Score:2)
This plays itself out in many ways. For starters, with generics you can do specialization (like for your sort example, you might want to handle things differently depending on whether your void* points into an array vs. a linked list vs. a b-tree). You also have no problem doing thi
Simplicity, macros, conditions, multiple dispatch (Score:2, Interesting)
Lisp has almost no syntax, so it's extremely regular (barring exceptions like LOOP). Because it's so regular, it's easy to build macros that do powerful things.
Macros can completely transform the source, at compile time, but with the full power of the language. Having that ability, together with simplicity, means that it's easy to build a complete mini-language for one's manager or web designer to use on the site, and easy for them to learn it, since you can explain the syntax in 5 mi
my favorite (Score:3, Insightful)
Python's ok. Tcl is closer to the ideal syntax, but oy what a feature poor language. Lisp's really nice. Forth would be about perfect, but it makes you work at such a low level most of the time (fact is, most people just don't build it up that much) that your code looks noisier than perl, more like APL even.
Of course I like modern features, like automatic memory management, structured exceptions, first class functions, pattern matching, currying, asynchronous execution, concurrency, and so on. But I just can't express concepts well in a language that makes me clad every expression in so much syntactic scaffolding.
Re:my favorite (Score:2)
Ocaml is much more "real world" (you can even have variables (*gasp*)!) , but ocaml is full of syntax warts, unhelpful compiler feedback, a module system that's *supposed* to be the bees knees but looks suspiciously instead like plain old namespaces of static methods, and w
Re:my favorite (Score:2)
Perl's taint mode (Score:5, Interesting)
Ranum is citing this as an example of a way that existing tools -- such as GCC -- could be enhanced in such a way that programmers using currently popular languages (C/C++) would have a better security safety net without having to be retrained in practices (like checking for buffer overflows) that while obvious are still under-utilized in most software. The whole article is interesting reading, but this remark about Perl's taint mode seems like one of the best concrete examples of a modern protective language feature.
True 64-bit Environment w/ Strong Primitive Typing (Score:2, Interesting)
This is what I want:
For the first criteria, if, at any point, you are forced to make contact with a 32-bit environment, then the platform fails the test.
For instance, if the platform requires you to use either Java or SQL, then it fails.
SQL fails because it is essentially an ASCII-based language that has almost no sense of primitive data types whatsoeve
Lameness Filter - Java Correction (Score:3, Informative)
The java code should have read as follows [I didn't notice that the shift operator had been caught by the
Re:True 64-bit Environment w/ Strong Primitive Typ (Score:2)
#include <stdint.h>
int main() {
int64_t theLong = 1;
theLong = 32;
theLong += 1;
double *theDoubleArray = new double[theLong];
delete[] theDoubleArray;
return 0;
}
The ABI guys are still trying to figure out how to map all the double sizes. Right now, sizeof(long double) on my x86 machine gives me 12 bytes 96 bit. There is also talk of making a "long long double" of 16 bytes. Sooner or later
Re:True 64-bit Environment w/ Strong Primitive Typ (Score:2)
Huh. How odd. C/C++ can do this just fine...
Does "C++" have a tape backup package? [As in Seagate-Veritas Backup Exec? Or CA-Cheyenne ARCserve?]
Does "C++" have seamless background mirroring to a failsafe mirror server? [Preferably in a peer-to-peer relationship, but Master-Slave will do in a pinch.]
Does "C++" distribute loads across multiple redundant servers?
Does "C++" have a querying capability? [I.e. can C++ "query" itself the way a relation database can "query" itself?]
Does "C++" have data tr
But why do I have to re-invent the wheel??? (Score:2)
If I'm going to get a database, I want one that focuses on being a database... not something that is a "backup-enabled mirroring RAID-based load sharing encrypted connection AD-integrated solution". That's not a product, that's 10 pounds of overblown marketing drivel stuffed into a 5-pound bag.
But that's why Oracle [or DB2, or Informix, or SQL Server, or whatever] costs, oh, $50,000, and a C++ compiler costs, oh, $500.
You can be a cheapskate, buy your own C++ compiler, and write all that stuff from scr
unification as in prolog (Score:2, Interesting)
Example: [foo(A,x)|B] = [foo([p,q],x),C,d,e].
which implies that A = [p,q], B = [C,d,e], and C remains unconstrained.
lambdas! (Score:2)
you can stuff functions into session variables - how's that for obtuse!
easy (Score:2)
Re:easy (Score:2)
automatic arrays = hashes = 'objects' (Score:2)
my main problem with that is (besides perl's ugly syntax) that arrays and hashes are different things. that alone makes me use PHP more often than perl.
but in PHP I have choose all the time between the array/hash thing and the 'object' thing. I'm sure that internally the objects are managed with hashes, but the sy
reflection (Score:3, Interesting)
I generally like to use struts in web applications and find I often have to tranfer values from an action form to a java bean and vice versa. Using the org.apache.commons.beanutils package it is incredibly easy to do this, and beanutils uses reflection to do this with.
My second choice would be good regexp support. IMO, Perl is the best at this and I also like the Java regexp package in 1.4 as well.
ksh (Score:2)
Everything I learnt from it, and all these useful
features like
if [[ $foo != @(From\ )* ]]; then
set -A arrayname -- $(head -1 file)
let i=0
while (( i "
let i+=1
done
and more stuff like that.
If you want to update your system to have this
kind of powerful shell too, read
http://wiki.mirbsd.de/MirbsdKsh
and, for prompt lovers who don't like the
simplistic '$ ' PS1,
https://mirbsd.bsdadvocacy.org:8890/cvs.cgi / src/et c/profile
gl hf
Re:ksh (Score:2)
Should have been
while (( i < ${#arrayname[*]} )); do
print "$i = <${arrayname[i]}>"
let i+=1
I've just seen GNU bash has "shopt -s extglob",
but not the (supposedly more portable than
echo) print builtin... gah.
Also, check out coroutines in the ksh book
or manpage, they're REALLY powerful.
Minimalism. (Score:2)
Only slightly ;-)
#1 Garbage collection (Score:3, Interesting)
#2 No pointers, no buffer overruns, no memory corruption. Related to the first point. Memory corruption is just so hard track down. You can keep your pointers, I've already got an OS, I don't need to write my own.
After spending years programing asm and C on a platform with no memory protection (Amiga), and then later C++, I think I've paid my dues here.
#3 Stack traces. Not a language feature per se, but it takes a lot of the drudge work out of debugging.
#4 Python's 'for' loop for iterating over the contents of a list or array:
for thing in myarray:
mutate(thing)
It is easy to remember, easy to type, much easier to read, and you use it _all_ the time. Compared to the same code in C, C++ or Java, it is a godsend.
#5 Dictionaries, a.k.a. associative arrays. It just makes a lot of problems much much simplier and faster to solve. Sure, most other languages have dictionaries available as a class, but when they are seamlessly built into the language you use them as easily as any other primitive datatype.
--
Simon
Don't bash C++ (Score:5, Informative)
> management. Not very sexy, but by far the single
> biggest productivity boosting feature of any
> language. I hate housework. It is just a waste of time.
Garbage collection does not free you from memory management. It simply converts one kind of problem into another: namely it eliminates accesses of unallocated memory, but it creates memory leaks instead. The thing is, it is not always easy to figure out when you no longer need a block of memory. That's with garbage collection it is supposed to be good practice to "free" your pointers anyway, by assigning NULL to them. Why they can't just use STL containers instead, I don't know.
> #2 No pointers, no buffer overruns, no memory
> corruption. Related to the first point. Memory
> corruption is just so hard track down. You can
> keep your pointers
You won't have any memory corruption if you don't use arbitrary indexes to access your arrays. For example, when iterating over a container, you run your iterator from ctr.begin() to ctr.end(); no corruption possible. The other cause of memory corruption is using unverified data to directly access your arrays. That happens when you ask the user for a number and then use it to index; this is wrong in so many ways, I can't even begin to list them all. Verify your data, and you will not have any data corruption.
> #3 Stack traces. Not a language feature per se,
> but it takes a lot of the drudge work out of
> debugging.
#include
backtrace_symbols()
> #4 Python's 'for' loop for iterating over the
> contents of a list or array:
>
> for thing in myarray:
> mutate(thing)
#define foreach(t,i,c) for(t i = c.begin(); i #5 Dictionaries, a.k.a. associative arrays. It
> just makes a lot of problems much much simplier
> and faster to solve.
map m;
> Sure, most other languages
> have dictionaries available as a class, but when
> they are seamlessly built into the language you
> use them as easily as any other primitive '
> datatype.
You can use map as easily as any other primitive data type of the same category: as an array.
m["january"] = 31;
cout "january has " m["january"] " days" endl;
how about hardly any features? (Score:2)
In a similar vein, I've been pondering the feasibility of a no-GP-register CPU. Low addresses (say, the first 31 words) are stored on-chip, the rest in slower memory. Data is accessed via two memory-address registers (a la the M reg in the old 8080, which turned into (HL) in the Z80) t
TCL's slave interpreter (Score:2)
In particular, I find it useful when allowing an application written in TCL to be scripted. The TCL application can remain robust and reliable, even when the user code isn't.
A neat trick that I love doing with perl (Score:2)
It's an easy way of developing a command-driven interface (which is useful if you're developing a web-app or even for limited-functionality command shells).
So for example, the user's command is stored in the variable $cmd. We then have hash %cmds which stores all the possible commands like this:
Pascal and With operator. (Score:3, Interesting)
like if the structure had members x and y and structure was named coords you could do something like this
var own_x;
with coords
begin
x=own_x
y=123.13
end
A few favorites (Score:3, Interesting)
Unrestricted integer size (e.g., Lisp bignums)
Have persistent objects between program invocations. It's so tedious and buggy to have to write to a file when a program ends and then read it again when you start it up again.
Re:Speed and RAM (Score:4, Insightful)
Re:Speed and RAM (Score:2, Insightful)
Yeah, Perl can be obtuse. Personally, I find that less-experienced programmers write clearer Perl code. Basically, there are many idioms and shortcuts that, used sparingly, can create extremely readable and intuitive code. However, just as using the same pronoun to mean several different things in the same sentence, using too many of these features makes code hard to read.
Take $_, for example. I am relatively inexperienced at Perl (I have used it a lot, but
Re:Speed and RAM (Score:2)
I am all for scripting languages such as perl and my favorite python, but this isn't the way I would describe it.
In C, some stuff needs to be done by hand, but it does what you want it to do.
In many scripting languages, it does what the interpreter thinks it should do and getting things to act the way you want is much harder if this differs from what the interpreter thinks it shou
Re:Speed and RAM (Score:3, Insightful)
I'm an experienced programmer who's done relatively little Perl, although its use is increasing significantly in my work. Like you, I deliberately avoid use of $_ because I find it a very confus
Re:Speed and RAM (Score:2, Insightful)
How ironic that you used the English cognate a mere four words later!
Re:Speed and RAM (Score:2)
e.g.
print <<"ENDHTML";
<html>
<head><title>$title</title>
</head>
<body>
Unquoted:<b>$blah</b><br>
Quote d: ${\( htmlquotearray($blah) )}
</body>
</html>
ENDHTML
Witho ut the $ or other special character this would be very difficult. Not sure how you'd do that sort of thing in other languages.
In addition to the associative arrays, I like CPAN - as you mentioned, there are plenty of expert
Re:Speed and RAM (Score:2, Informative)
I do agree that standardized documentation built into a language is quite powerful.
Re:Unification and Backtracking (Score:3, Insightful)