News for hackers. Stuff that matters.
Re:Is your programming language unreasonable? by geocar on Wednesday February 04, 2015 @01:46PM (#8998752)
This is not a nice job.

The first "issue" is that ``DoSomething accesses x directly rather than through the parameter'', but then goes on to talk about types.

I think this is a big part of why we are bad at programming: A because 6 therefore Go Fish.

I have noticed that when a program is small enough that I can see all of it, then I can reason about all of it, and when I cannot see all of the code, then I cannot. I may resort to note-taking or trying to remember while flipping tabs quickly, or even outright guessing, but I certainly am not reasoning about it.

I do not buy that typing variables, or lambdas, or long method names (like `Equal`), or having "compile time", or `null` or "function signatures" offers anything like the gains had by able to see all of the program, so I'm disinclined to waste energy on what I view as premature optimisation.

Re:Is your programming language unreasonable? by stcredzero on Wednesday February 04, 2015 @02:31PM (#8999091)
I have noticed that when a program is small enough that I can see all of it, then I can reason about all of it, and when I cannot see all of the code, then I cannot.

You've made a powerful observation about how programmers and human minds in general interface with complex systems. What if you had language semantics that could let you ignore most of your codebase with 100% reliability?

I've had a long career dealing with very complex "enterprise" software for multi-nationals. Semantic tricks that let you make far-reaching deductions and securely ignore most of the code are absolutely vital in contexts like that. It was precisely in the parts of the code where things weren't structured to allow this, that things broke down, and everyone dreaded to check-in code.

I'm disinclined to waste energy on what I view as premature optimisation.

There are certain contexts where one already knows that this sort of thing is not premature optimisation. (Granted, lots of programmers seem to make a fetish of acting like they are in such a context, when they really aren't. Analogous to: http://xkcd.com/538/ )

Re:Is your programming language unreasonable? by geocar on Wednesday February 04, 2015 @04:03PM (#8999768)
Most of my professional life has been reading other people's code and finishing other people's programs. One thing I've noticed is that nobody has ever asked me to help fix a small codebase.

Another thing I've noticed is that having well documented interfaces between small components is extremely effective at improving isolation time.

Another thing I've noticed is that interfaces with two or fewer arguments (none of which boolean) tend to be used correctly more often than interfaces with a large number of arguments, or booleans.

I would very much enjoy having a conversation about those language semantics. I haven't noticed any language semantics that would be useful in that way, however I have noticed a number of these "disciplines" that are helpful at reducing search time, reducing defect count and increase performance (run-time and programmer).

What exactly are you thinking about?

Re:Is your programming language unreasonable? by stcredzero on Wednesday February 04, 2015 @06:24PM (#9000767)
Another thing I've noticed is that having well documented interfaces between small components is extremely effective at improving isolation time.

Good point. There aren't languages that do a complete job of absolutely enforcing such patterns of behavior, but there are environments that do a fairly good job of encouraging them.

Another thing I've noticed is that interfaces with two or fewer arguments (none of which boolean) tend to be used correctly more often than interfaces with a large number of arguments, or booleans.

Goes to the same point. Most of my work with complex stuff was in Smalltalk, and there is practically no enforcement of anything in that language. However, my experience is that it's practical to have codebases that adhere very closely to a number of patterns or coding standards. Also, there were very powerful search facilities in the environment that facilitated powerful deductions about the codebase. Often, work would involve making deductions, figuring out how those could be broken, then quickly searching for these instances. Often enough, the deductions could stand and make debugging and modifications easy.

Your preference in interfaces is also the one preferred by better Smalltalkers. Also, the environment is built up entirely of small components. One path of least resistance is to build new systems along the same lines. (That said, one could still write Fortran and COBOL in Smalltalk, and I had to deal with this professionally.)

Re:Is your programming language unreasonable? by enjoy-your-stay on Wednesday February 04, 2015 @05:22PM (#9000407)
I really like your observations, and have noticed pretty much the same thing.

Your point about the boolean arguments especially, I can't tell you the number of times I've painstakingly documented the parameter in the /// section of the function (in c#) just to make sure it's clear what passing false actually means.

I should just create an enum{ doTheDance,dontDoTheDance} with two values instead, often thought about it, but for some reason never actually done that.

Re:Is your programming language unreasonable? by geocar on Thursday February 05, 2015 @04:05AM (#9002315)
Just do it!

The next guy will thank you.

Re:Is your programming language unreasonable? by tel on Wednesday February 04, 2015 @01:57PM (#8998839)
I disagree strongly. Good types can serve as very adequate reasoning tools for programs at large. This is the source of claims in Haskell/ML/Etc where "if it compiles it works" is used to guide 90% of even massive refactoring endeavors.

It can be hard to believe how useful good types can be.

Re:Is your programming language unreasonable? by geocar on Wednesday February 04, 2015 @02:10PM (#8998933)
I don't understand you.

Do you believe "good types" in a 1000 line program is easier to reason about than a 20 line program?

Re:Is your programming language unreasonable? by tel on Wednesday February 04, 2015 @02:30PM (#8999077)
I don't think you can make comparisons like that and feel good about them.

I certainly believe that there are 20 line programs which are harder to reason about than some 1000 line programs with types. That's a big silly, though, I'd believe the same even without the "with types" caveat.

So, here's what I believe:

    * Types impose logical structure on programs which is continuously 
      checked, high-level, and very human interpretable

    * All things being equal, shorter programs are easier to comprehend 
      than longer programs

    * If I were to list the things which aid program comprehensibility 
      then types + most of the things on the list in this blog post 
      actually go *far* higher on that list than "short length"
(Edit: I should add, given what came after this point, that "all things being equal" above is, in my eyes, a very difficult hypothesis to satisfy.)
Re:Is your programming language unreasonable? by geocar on Wednesday February 04, 2015 @03:40PM (#8999588)
> I don't think you can make comparisons like that and feel good about them.

I think most professional programmers could write a relational database in under 1000 lines. Arthur did SQL92 in 20:

http://web.archive.org/web/20060505221834/http://kx.com/q/e/...

I think this example is perfectly illustrated: I find it more valuable than anything else I have found to have the entire program all on one screen.

> If I were to list the things which aid program comprehensibility then types + most of the things on the list in this blog post actually go far higher on that list than "short length"

I think there are so many useful and successful applications that "use types" and so many useful and successful applications that do not "use types" that types are probably irrelevant for success.

That many of those useful and successful programs are very large suggests that size has very little (or nothing at all) to do with success.

But comprehensibility?

I cannot imagine what universe would have a large program as being "easier to comprehend" than a short program.

Re:Is your programming language unreasonable? by tel on Wednesday February 04, 2015 @03:56PM (#8999703)
> I find it more valuable than anything else I have found to have the entire program all on one screen.

Then we'll merely have to agree to disagree. I personally think this example is remarkable levels of incomprehensible. I'm not going to claim that my personal opinion has any level of generality, though. More power to you if that page of code is easy to comprehend.

> I think there are so many useful and successful applications that "use types" and so many useful and successful applications that do not "use types" that types are probably irrelevant for success.

The existence of examples both positive and negative is insufficient to demonstrate that some cause has no effect. You might strengthen that to say that in your experience the use of types has zero correlation with "useful and successful". I think with a little qualification there we could again get to a point where we'd merely have to agree to disagree.

It's also vital to point out the selection bias incurred by either of our experiences.

> I cannot imagine what universe would have a large program as being "easier to comprehend" than a short program.

I could try to demonstrate examples of both, but it'd just be my opinion as to that selection. So, instead of trying to be comprehensible, I'll just state for posterity:

Offhand, I believe it would be very easy to write a 1000 line (or even larger) implementation of SQL92 which I would find to be far more comprehensible than the example you've linked.

In particular, I believe in this case that attempting to make that code fit on one page is a significant detriment to its comprehensibility.

And again, I'm not going to try to convince you but merely state that as the fact of my opinion.

Re:Is your programming language unreasonable? by icefox on Thursday February 05, 2015 @10:42AM (#9003760)
> I think most professional programmers could write a relational database in under 1000 lines. Arthur did SQL92 in 20: > http://web.archive.org/web/20060505221834/http://kx.com/q/e/....

I can make any program only 1 line long if I remove all the newlines. I don't care if a program fits on one screen if it is unreadable. The example you cite is a poor example of a valuable program as it is on purpose made to be difficult to reason about.

Re:Is your programming language unreasonable? by jfoutz on Wednesday February 04, 2015 @02:23PM (#8999025)
Can't speak for tel, but i believe that. Types establish the rules of the game, and the compiler backs you up enforcing those rules.

On the other hand, i'm the kind of guy that has read 20 lines of code and missed possible null value bugs. Sucks when you have to tell customers to wait for the next point release before they can use this new feature.

Re:Is your programming language unreasonable? by geocar on Wednesday February 04, 2015 @02:28PM (#8999067)
Why would you make a customer wait for a "point release" for a program that is only twenty lines long?

I wonder if you thought I meant "a bug in 20 lines" when I meant a "20 line program".

EDIT: e.g. 20 lines is enough for SQL http://web.archive.org/web/20060505221834/http://kx.com/q/e/...

Re:Is your programming language unreasonable? by tormeh on Wednesday February 04, 2015 @03:22PM (#8999457)
Re:Is your programming language unreasonable? by geocar on Wednesday February 04, 2015 @03:32PM (#8999542)
It's part of kdb http://kx.com/ , a rather fast and powerful database, which is written in a language called k.

Here's an excellent introduction to K: http://archive.vector.org.uk/art10010830

Most kdb users use Q though, which is something else.

Re:Is your programming language unreasonable? by Dylan16807 on Wednesday February 04, 2015 @02:56PM (#8999273)
How many functions do I have to read simultaneously in those 20 lines? Good use of types can isolate functions from each other.

The typical '1000 line program' could be compacted like your program is and all fit onscreen at the same time, if you really wanted. It's not anywhere close to 50 times as much code.

Re:Is your programming language unreasonable? by geocar on Wednesday February 04, 2015 @03:47PM (#8999634)
None of the lines have more than 4 functions on them (that's the parse utilities which has a bunch of short helpers on it), and most have only one function.

Most of the functions are independent, with the exception of the parse utilities, so it's easier to list the exceptions: cre depends on col, w depends on w0 and w1; v and w are used in e (for tokenising); where (wh) is reused by select (sel) and update (upd). c and a are used for the pull parser.

Re:Is your programming language unreasonable? by mannykannot on Wednesday February 04, 2015 @03:18PM (#8999425)
A false dichotomy. How many well-designed, well-typed 1000 line programs can be turned into 20-line programs simply by dropping the typing requirement?
Re:Is your programming language unreasonable? by geocar on Wednesday February 04, 2015 @03:30PM (#8999518)
Straw man.

I'm not proposing "dropping the typing requirement".

I think having the program small and fit on the page is more important than types or no types.

To that end: I don't even want to have the argument about types because I think they're so irrelevant.

I'm sure most professional programmers could write an SQL92 implementation in around 1000 lines; Again, types or no types.

Here's Arthur's SQL written in 20 lines (including lexing and parsing):

http://web.archive.org/web/20060505221834/http://kx.com/q/e/...

Here's Steve Apter's relational (not SQL) database in 16:

http://nsl.com/k/t.k

Re:Is your programming language unreasonable? by mannykannot on Wednesday February 04, 2015 @03:45PM (#8999624)
"I don't even want to have the argument about types..."

But that is exactly what you chose to do in your original post.

Re:Is your programming language unreasonable? by geocar on Wednesday February 04, 2015 @03:51PM (#8999664)
No it is not.

I'm happy to see an argument that (having or not having types) is more important than a short program.

but I'm not happy having an argument whether to have a language with types versus one without.

That's what "I think types are irrelevant" means.

It seems like at least some people realise this e.g. https://news.ycombinator.com/item?id=8999077 but if after re-reading my post you disagree, let me know how I could better articulate what I mean.

Re:Is your programming language unreasonable? by mannykannot on Wednesday February 04, 2015 @05:29PM (#9000443)
I should have written 'the post to which I was replying' rather than 'your original post.'

With regard to your larger issue, almost all programs other than exercises are vastly larger than a screenful, so either the way all software is written is completely wrong, or your preference for screen-sized programs is irrelevant to the real problems of writing real-world software. Just as professional mathematicians need to be able to follow proofs that occupy more than one page, professional programmers need to be able to reason about code that occupies more than one page.

Re:Is your programming language unreasonable? by geocar on Thursday February 05, 2015 @03:58AM (#9002302)
> With regard to your larger issue, almost all programs other than exercises are vastly larger than a screenful, so either the way all software is written is completely wrong, or your preference for screen-sized programs is irrelevant to the real problems of writing real-world software.

Agreed.

Arthur wrote an SQL in 20 lines of K, and a dynamic window manager in around 60 of C. His programmers editor with syntax highlighting easily fits on a page.

kOS's kernel is under 60 lines of C as well (including annotations; paging, filesystem, syscalls, etc).

Where I work, I wrote an RTB service for digital advertising demand-side platforms- implements HTTP, application protocol decoding, maps and bidding in under 100 lines of C. I fit a video player with VAST+VPAID support in 42 lines of Javascript.

So it follows how programmers write software is completely wrong.

However the inertia will be hard to overcome.

Re:Is your programming language unreasonable? by mannykannot on Thursday February 05, 2015 @07:54AM (#9002944)
A few examples, impressive as they are, do not make the case that most of the world's programs can be replaced by programs of no more than one screenful. If you really know how to do this, you could achieve fame and wealth of Edison-like proportions as the person who revolutionized software development. If all you are going to do is brag about it in HN comments, that is not a profession, it is a hobby.
Re:Is your programming language unreasonable? by geocar on Thursday February 05, 2015 @09:26AM (#9003350)
These few examples don't need to make the case that "most of the world's programs can be replaced by programs of no more than one screenful", because again that's your strawman, and not my argument. People pay millions of dollars for kx's database so it's not by any reasonable definition mere "exercises", and it's certainly not "vastly larger than a screenful".

I'm writing this way; I'm finding value writing this way, and at the moment I'm making no other claims other than the shortness of a program is the single best indicator of correctness, performance, and "reasonableness". It's certainly more important than a "types" argument.

While your best counterargument against short programs is inertia, suggesting we shouldn't leave the trees isn't helpful. You should try it. You might like it.

Re:Is your programming language unreasonable? by mannykannot on Monday February 09, 2015 @07:11AM (#9020755)
"at the moment I'm making no other claims other than the shortness of a program is the single best indicator of correctness, performance, and 'reasonableness.'"

If you had not strayed from that position, I would not have joined the discussion. I happen to agree that there is an inordinate amount of unnecessary complexity in the present code base, but I think it is an orthogonal issue to that being raised by the original article. That is because it seems to me that the main causes of this introduced complexity is developers' poor understanding of the requirements they are trying to satisfy, together with a trial-and-error approach to programming, rather than the language features covered by the original article.

Re:Is your programming language unreasonable? by tormeh on Wednesday February 04, 2015 @03:20PM (#8999438)
Depends whether the 20 lines are stack-based assembly or not... Anyway, what is initially written in 1000 lines can very rarely be written in 20.