18 ms·
Little is a statically typed, C-like scripting language
- BruceEel 6y agoCompiles to Tcl byte codes Interesting, I didn't even know there was such a thing. Good to see <> and =~ live on.
- simias 6y ago=~ is nice and convenient but I really don't think <> was worth bringing back. I'm sure people who never used Perl could figure out what `buf =~ /${regexp}/` does, but I wonder if they'd be able to figure out the `while (buf = <>)`. Perl has a lot of good ideas and things I find myself missing a lot when I use Python or JS (autovivification being probably #1) but IMO these one or two symbol magic variables would generally be improved if they were more descriptive, with maybe one exception for $_/@_. Although I must admit reminiscing about this made me realize how much I miss Perl now that I'm forced to use Python for work.
- tyingq 6y agoI do find <> helpful. Perhaps if it were more descriptive? <ARGVorSTDIN> or similar?
- simias 6y agoYeah to be clear it's not the functionality that bothers me, it's just the syntax. Ideally since it's not even a proper variable since it changes after reading it should probably look like a function call. These ultra terse shorthands make some sense in the shell because it's meant for interactive, write-only commands but a scripting language should be a little more verbose and consistent IMO.
- luckydude 6y agoI'm a huge fan of preserving knowledge and building on it. Most people, at the time at least, knew what while (buf = <>) did. So I didn't want to invent a new syntax, there is way too much of that going on, I like C, I like perl, pull the useful stuff from each and move on. I freely admit it's not how everyone would do it.
- Spivak 6y agoThere’s a balance because people really seem to like ? as null coalescing, => for lambdas =~ for regex match, etc.. I think <> as a fancy readline and _ as a default/throwaway variable does really improve readability and lowers the mental load of understanding programs.
- derefr 6y agoIn Ruby it's called ARGF (https://ruby-doc.org/core-2.7.1/ARGF.html https://ruby-doc.org/core-2.7.1/ARGF.html) — which, if not perfectly descriptive, is at least evocatively similar to ARGV. If you're already aware that ARGV exists, you'll guess that ARGF might be used in relation to it, and so when writing a CLI program that uses ARGV, you might wonder if ARGF could simplify your code and look up what it is/does.
- jiofih 6y agoAutovivification was one of the most painful features I’ve had to live with - in a large codebase it completely erases trust on any kind of defined() check and breaks all sorts of things unexpectedly. Yet another horrible hack in Perl that for some reason is advocated for. Optional chaining / null propagation is a much, much better idea and shouldn’t have been any harder to implement.
- simias 6y agoI see how that can become a problem but I think the pros outweigh the cons. Maybe the problem is because of a "very large" codebase, my general hot take is that dynamic languages like Perl and Python should be used primarily for scripts. The lack of static typing makes dealing with very large codebases rather painful in any case, in my experience. Null propagation is nice too, but it doesn't address all the uses cases of autovivification when you have, say, a hash table of arrays and you want to insert a new entry in an array, creating it if it doesn't exist. In python you have to use setdefault which I always found clunky.
- lizmat 6y agoFWIW, that was one of the things that Larry fixed in Perl 6 (now the Raku Programming Language https://raku.org https://raku.org #rakulang). You can bind to a non-existing hash element (even multiple levels deep) and it won't exist until you actually assign to it: my %h; my $c := %h<a><b><c>; say %h<a>:exists; # False $c = 42; say %h<a>:exists; # True
- luckydude 6y agoI wrote most of my first source management system (NSElite, mentioned elsewhere in this thread) in perl4. I was learning perl at the time and my first and second efforts were awful. Perl really lets you get sloppy and create unmaintainable code. My 3rd rewrite was very stylized and, I felt, maintainable. Which proved to be true as I had to fix bugs in it. I did weird stuff like using $whatever as the index into the @whatever array. But I digress. On the <>, Little has argv so you can do int main(string argv[]) { int i; string buf; FILE f; if (defined(argv[1]) && streq(argv[1], "-") && !defined(argv[2])) { while (buf = <STDIN>) bputs(buf); } else { for (i = 1; defined(argv[i]); i++) { if (defined(f = fopen(argv[i], "r")) { while (buf = <f>) puts(buf); fclose(f); } else { fprintf(stderr, "unable to open '%s'\n", argv[i]); } } } return (0); } but why would you want to when all of that is int main(string argv[]) { string buf; while (buf = <>) puts(buf); return (0); } I mean, come on, that's cat(1) in 8 lines of code. edit: I need to learn hacker markup. My code looks like crap.
- hyperpallium2 6y agoIt's indent by two spaces. Guessing your style: int main(string argv[]) { string buf; while (buf = <>) puts(buf); return (0); }
- forgotmypw17 6y agothis is amazing, like a dream come true!
- deleted 6y ago[deleted]
- fuball63 6y agoNot to be confuse with lil, which is a small scripting language based on TCL: http://runtimeterror.com/tech/lil/ http://runtimeterror.com/tech/lil/ I think this is a super interesting project. It reminds me what Groovy is to Java, but backwards. Groovy is a “looser” version of Java that compiles Java. Little is a “stricter” version of TCL that compiles TCL.
- narrator 6y agoTCL had some bad features that kind of killed it. For example, "upvar" was a really bad idea. Bad features tend to kill languages over time. Everyone used to use Perl in the late 90s. It had too many bad features though, and nobody wanted to maintain those programs.
- derefr 6y agoI've always been surprised that nobody has tried to take a "The Good Parts" subset of a big language (C++, Perl, etc.), codified/formalized it as its own language, and then attempted to popularize the new reduced language as a distinct effort/project/community to that of the original language. One could release this "language" as a distribution of the inner language's compiler together with a wrapper (like C++ originally was to C), that, rather than adding features and compiling down, just analyzes the source file and errors out on use of forbidden syntax; or, if no forbidden syntax is used, just passes your code straight through to the inner compiler. A bit like a pre-commit-hook style checker, but a pre-compile-hook style checker.
- luckydude 6y agoI just liked what is in Little, it's enough like C that it is trivial for me to jump into it (tcl always took a half a day, I really dislike the tcl syntax), it's got enough of the shortcuts from perl that it is pretty terse, and credit where credit is due, syntax aside, tcl has a bunch of useful stuff, check out Little's switch(), that's tcl's switch.
- TimWillebrands 6y ago
- mannykannot 6y agoThis language clearly avoids some of the run-time errors that can occur with C, but I would like to learn a little more about the remainder. For example, if you make an out-of-bounds assignment to an array, the array is grown to accommodate it (for +ve offset only, I assume) - but what about out-of-bounds retrieval?
- luckydude 6y agoYou get undef, that's part of the reason we added an undef concept (it's a value that isn't a value, though if you treat it like an int I believe it is zero, like a string and you get "").
- IshKebab 6y agoSo there's `undef` and `null`? I wonder if there's a popular language that made the same mistake you could have learnt from :-P
- luckydude 6y agoThere is no null, only undef. It's not a value, there is no value that means undef. We implemented by stealing the high order bit from the reference counter that tcl uses for garbage collection. If it is set, the variable undefined, if it isn't, it's a normal variable. I thought that was clever given that tcl's reference counter was signed and it only uses positive values. So we made it unsigned and got the bit for free.
- skybrian 6y agoWhat happens if you call a Tcl function with an undef argument? Is this running Tcl code on a slightly different runtime, or do they interop in some other way?
- luckydude 6y agoIn Tcl, everything is a string. The string rep of undef is "" so Tcl gets "" but doesn't know that it is undef. So yeah, there is some sloppiness there. Tcl tends to use "" as sort of a null or undef so lots of stuff just works but no promises on that. This is sloppy simply because the Tcl die hards (are there any left?) refused to see the value of undef, a value for a variable that said there is no value. We used it all over the place, there clearly is value. They didn't see that, Little never got pushed back into the Tcl source base so Tcl never thought about undef. It is what it is, we live in an imperfect world. I tried.
- dilawar 6y agois there a list of acomputer languagesn(dead or alive) and spoken languages (dead or alive)? Would like to see at what time computer languages are likely to outnumber spoken language.
- zabzonk 6y agoUnsurprisingly, Wikipedia has both.
- rvense 6y agoThe highest estimate for number of natural languages I've seen is about 7,000 living. But I think you'd have to have a very, very restrictive definition of programming language for it to be lower than that.
- endergen 6y agoDefinitely depends on the definition, it seems every programmer and their mother has some toy programming language they poke at.
- mhd 6y agoMost of which would probably more qualify as dialects in natural language terms. We're all mostly speaking broken Algol with some fancy loan words and maybe a slight lisp.
- asicsp 6y agohttp://www.little-lang.org/why.html http://www.little-lang.org/why.html is pretty interesting >We (BitKeeper folks) did our GUI interfaces in Tcl/Tk years ago because it meant we could have one gui person and get the same gui tools on Windows, Mac, Unix, and Linux. >While some of us could switch from C to Tcl easily, our pointy-haired boss could not, he's mostly C and would lose about a half a day to get back into Tcl. >Success was realized when one of our engineers, who is not a Little fan, fixed a bug in a patch that flew by in email without realizing it was Little instead of C
- nightowl_games 6y agoCurious on performance benchmarks. For me, I'm comparing this to wren: https://wren.io/ https://wren.io/
- tyingq 6y agoTcl is historically very slow. Especially for synthetic CPU intensive benchmarks. However, since it's so easy to interop with C, it didn't seem to matter much in the real world. You just put anything performance sensitive in C and left the bits that didn't matter in tcl. Some benchmarks: https://github.com/trizen/language-benchmarks https://github.com/trizen/language-benchmarks
- luckydude 6y agoThere are some benchmarks here: http://mcvoy.com/lm/L/tcl/tests/langbench/ http://mcvoy.com/lm/L/tcl/tests/langbench/ some results in the README. Perl holds up well. These are probably 10 years old though.
- synergy20 6y agoso this is a c-like-interface for tcl/tk libraries? I was thinking it's a c-style lua script alternative so I can use it on embedded boards.
- tyingq 6y agoThe repo is odd, it's hard to tell where the actual little-lang code is. I guess it's in the tclXXX directory? https://github.com/bitkeeper-scm/little-lang https://github.com/bitkeeper-scm/little-lang
- rbsmith 6y agoAll the files that begin with L in : https://github.com/bitkeeper-scm/tcl/tree/master/generic https://github.com/bitkeeper-scm/tcl/tree/master/generic
- Tade0 6y agoI originally read it as "Life is..." and thought "that's an interesting take on things".
- swagonomixxx 6y ago> undef(argv[1]); // left shift down the args Can someone explain what this does? Is this some Perl or Tcl thing? Unfortunately I've never used either :)
- luckydude 6y agoI'll grant you it is sort of weird. I think that's a perl thing, we just copied how they did it. undef is both a function and a (non) value. It is the main reason Little never got pushed back into tcl, the tcl crowd hates the idea that there can be a value for a variable that is undefined. I found that very useful, for example, undef is the error return from any function. Just made sense to me, didn't make sense to the Tcl people.
- tyingq 6y agoIt's not a Perl thing. In Perl, that would set argv[1] to undef. It would not delete or left-shift @ARGV. There is a delete() function that acts similarly, but is discouraged to use on regular arrays. Shift() would be more appropriate in this case. Given the context, in little-lang, it appears to delete argv[1] and shift all of the right of that down, such that argv[2] becomes argv[1] and so on. That's so that the the "while (buf = <>)" construct used right below it doesn't process the regex as if it were a file to "grep" through. In Perl, you would typically do it this way... if (!defined(my $regex=shift(@ARGV))) { die("usage: grep regexp [files]"); }
- luckydude 6y agoWow, just noticed this. I'm the guy who paid for Little, a bunch of other people did all the work. I'm surprised to see it getting some attention but happily so. Little is what I'd like C to evolve towards, there is a lot of useful (to me) stuff in the language. I'll wander through the comments and reply where I can.
- marktangotango 6y agoI'm curious if you've written about the decisions around licensing that essentially killed the bitkeeper business by inspiring Linus to create git? What are your thoughts around that today?
- luckydude 6y agoHind sight is 20-20. The BitKeeper business had a good run, we were around for 18 years. It made enough that I and my business guy are retired off of what we made. On the other hand, we didn't make enough for everyone to retire if they wanted to. We had a github like offering and it's pretty clear that we should have put a bunch of money into that and open sourced BitKeeper. All I can say is it is incredibly hard to make that choice when you have something that is paying the bills. I tried to get Sun to do it with the BSD based SunOS and they wouldn't. And even though I had that vision for Sun, when it was my livelihood, I couldn't see the path to doing so. Shoulda, coulda, woulda, my biggest regret is not money, it is that Git is such an awful excuse for an SCM. It drives me nuts that the model is a tarball server. Even Linus has admitted to me that it's a crappy design. It does what he wants, but what he wants is not what the world should want. It says a lot that we have a bk fast-export and we can incrementally run that and get idempotent results. As in go from BK to Git on an ongoing basis, have two people do it in parallel and they both get bit for bit identical results. If you try and go the other way, Git -> BK, if you do it in parallel you get different results because Git doesn't store enough information, so BK has to make up the missing bits. Git has no file create|delete|rename history, it just guesses. That's my biggest regret, I wish Linus had copied that part.
- brundolf 6y ago
- vram22 6y agoHas any one else noticed that programming-language-topic threads on HN seem to come in batches, sometimes? I'm not complaining. I like it, since I am a language fan, though not an implementer or lawyer. I have seen this phenomenon at least a few times in the last few years. (Did not check much during Covid.)
- JNRowe 6y agoI've been enjoying this series of "Breakfast With Forth Week", best one yet. It had left me wondering what had caused it. There was a thread a few weeks ago where the old guard were describing an actual attempt to game the system, and I wondered if we were seeing a version of that being played out. https://news.ycombinator.com/item?id=25787374 https://news.ycombinator.com/item?id=25787374
- vram22 6y agoWill check,thanks.
- sidpatil 6y agoIt's probably because one link leads to another, and interest in the topic is piqued for a while, until the next new (or old) cool topic comes along.
- vram22 6y agoYes, that's probably part of the reason - apart from a fad-of-the-month kind of thing, and also due to genuine interest in the topics.
- rurban 6y agoI really like the syntax. But it should be compiled to lua, not tcl.
- luckydude 6y agoWell the compiler is open source, have at it :-) Personally, I would love a gcc --little dialect complete with a String type (and others) that is garbage collected and auto resized just like tcl/Little. With all the other Little goodness in there. Man, that would make C super pleasant. And it wouldn't be a new syntax like Go/Rust/whatever.
- 0xbadcafebee 6y agoWhy are there so many different languages that are almost the same except for one or two attributes? Why not make one language that can do everything? If you can make one language strongly typed, and one weakly typed, then you should be able to build one language which can do either/or, depending on a compiler flag. Then you simply decide before you start writing your code whether you want to write it weakly typed or strongly typed, and pass the correct compiler option. Take that same idea, but add in every language's quirks, and just enable/disable them. Then we wouldn't need to constantly reinvent languages, because we'd have one that can do everything. Otherwise we're going to keep re-writing the same damn thing for hundreds of years, and that just seems like such a pointless waste of effort.
- deleted 6y ago[deleted]
- arunix 6y agoI think that's what Larry Wall was trying to do with Perl6/Raku: https://thenewstack.io/larry-walls-quest-100-year-programming-language/ https://thenewstack.io/larry-walls-quest-100-year-programmin...
- lizmat 6y agoHave you looked at the Raku Programming Language? https://raku.org https://raku.org using the #rakulang tag on social media.
- mastrsushi 6y agoThis sort of reminds me of the old MUD VM language Pike https://pike.lysator.liu.se/ https://pike.lysator.liu.se/
- luckydude 6y agoI remember Pike, I looked at it. It was too far away from C for me. I'm a died in the wool C programmer (I started as a kernel programmer and formed some strong opinions there). I get that C is not for everyone but for me, it's enough of a language to do what I want and not filled with this, that, and the other kitchen sink. So Little looks a lot more like C than Pike does. And I like it that way. It's not for everyone but C programmers will probably like it.
- nanofortnight 6y agoIs Little embeddable? This seems like a perfect scripting language for embedding into a larger C application.
- luckydude 6y agoI would think so but I haven't done it. People embed tcl all the time, perl/tk is perl with a tcl interpreter embedded just so they can get at the tk part (gui stuff).
- Thedarkb 6y agoI asked Oscar Bonilla on Twitter a while ago and he said that it should be the same process as Tcl, but beware I haven't tried.
- peteretep 6y agoStrongly recommend removing the Perl camel from the logo as it’s a trademark owned by a commercial entity
- luckydude 6y agoWho owns it? OReilly?
- peteretep 6y agoYep
- luckydude 6y agoPretty sure Tim doesn't care but I'll track him down and ask. Edit: sent an email to him, we'll see.
- luckydude 6y agoTim was cool, he said add "The Perl logo is a trademark of O'Reilly Media and is used with permission" and we're good. Now I have to remember how to get into that VM :-)
- sneak 6y agoI support any language that lets me use unless (if!) and until (while!). I really wish more languages would adopt this syntactic sugar.
- maskedoffender 6y agoBellard's tiny C compiler (tcc) can execute C so fast it's as if it were a scripting language. https://bellard.org/tcc/ https://bellard.org/tcc/