News for hackers. Stuff that matters.
Re:Pyret: A new programming language from the creators of Ra... by terhechte on Saturday November 09, 2013 @10:04AM (#6701785)
"""Pyret makes testing a natural part of the programming process. Functions can end in a where: clause that holds unit tests for the function. These assertions are checked dynamically."""

Fantastic idea! I'll keep that in mind, should be fairly easy to extend Lisps or other AST-Macro enabled languages (Elixir, Julia, Python) with such a functionality. I really like that. It makes it easy to work on a function and code tests down without switching contexts (files, workspaces, etc)

Re:Pyret: A new programming language from the creators of Ra... by 6ren on Saturday November 09, 2013 @10:36AM (#6701872)
It clutters the code.

Tests are a form of documentation, but too much in the code, like too many comments, obscures. Higher level unit tests (acceptance tests) can be quite long, especially if there's a lot of setup - unlike their example code. Literate programming tried embedded documentation, but didn't catch on (even with Knuth's backing). Embedding tests makes them easier to keep in sync, but tests are already kept in sync by (hopefully) failing when not. However, their idea of automatically running tests is interesting, so there's no infrastructure to set-up, run etc (though you'd want to be able to disable them).

Nice for teaching.

Re:Pyret: A new programming language from the creators of Ra... by stiff on Saturday November 09, 2013 @11:17AM (#6702026)
I don't think the story of literate programming can be of any help predicting how well this idea here can work out.

Literate programming is not "embedding documentation". The main idea was to separate the order in which the code is read from the order in which the compiler sees it, and it embeds the code in the documentation, not vice versa. It was a very idiosyncratic thing, hard to imagine a team of programmers in a typical current commercial setting, developing a nice LaTeX essay around the actual code of the next social network web-app. As the program grows larger it also gets harder and harder to maintain the "story" around it.

Re:Pyret: A new programming language from the creators of Ra... by jashkenas on Saturday November 09, 2013 @12:23PM (#6702270)
That's not the "main idea". Originally, it was a part of the suggested way to accomplish the goal ... but the main idea is this:

    > Let us change our traditional attitude to the construction of programs: 
    > Instead of imagining that our main task is to instruct a computer what 
    > to do, let us concentrate rather on explaining to human beings what we 
    > want a computer to do.
    >                          — Knuth
If your program can be read more as an enlightening explanation of the job-to-be-done, and is more oriented toward the human reader of the code than the machine that will execute it, then you've succeeded.

Hopefully, it's clear how a program written in such a way could potentially be beneficial to a large team, trying to understand, modify, and improve it.

Re:Pyret: A new programming language from the creators of Ra... by tokenrove on Saturday November 09, 2013 @01:44PM (#6702602)
Right, but it's important to emphasize what stiff was talking about, that the structure of the narrative needs to be oriented towards the human instead of the machine, because so many people don't bother to do this and decide that literate programming just means having LaTeX or docbook comments in your code. That total inversion (the code is in the documentation, not the documentation is in the code) is important. (That said, I admit that most modern languages are so much more flexible compared to C or Pascal with regards the ordering of code.)
Re:Pyret: A new programming language from the creators of Ra... by stiff on Saturday November 09, 2013 @12:30PM (#6702295)
It's like saying the main idea in C was to allow writing programs. At this level of generality it is indistinguishable from tens of projects with similar goals, including also earlier ones.
Re:Pyret: A new programming language from the creators of Ra... by pseut on Saturday November 09, 2013 @02:24PM (#6702769)
It's also much less necessary with packages, where you can trivially change the order of most of the code is read.
Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Saturday November 09, 2013 @01:30PM (#6702523)
You don't have to put the tests right in the middle of code. The `where` form goes with the definition, but a `check` form can float freely. So if you prefer a <Lang>Unit style of testing, where your tests reside in a separate file, you can do that with `check` blocks just fine.

However, the `where` tests play into the type-inference story for the language!

Re:Pyret: A new programming language from the creators of Ra... by tel on Saturday November 09, 2013 @11:17AM (#6702028)
I think that Python's doctests have shown this to be a greyer area than this. Not all tests can fit nicely next to function definitions, but a few well-chosen ones are both fantastic documentation and not too cluttery.
Re:Pyret: A new programming language from the creators of Ra... by sitkack on Saturday November 09, 2013 @02:07PM (#6702700)
Doc tests are a poor solution precisely because they are difficult to edit. The solved a non-problem and made writing documentation AND tests more difficult.

Instead of writing tests in strings, the documentation tool should have been modified to render that code _in_ the documentation.

Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Sunday November 10, 2013 @08:16AM (#6706313)
Doc tests are butt-ugly in several ways. Code shouldn't be written in strings, and they take twice as much vertical space as they need (which is a problem because monitors are typically used much wider than they are tall).
Re:Pyret: A new programming language from the creators of Ra... by tel on Saturday November 09, 2013 @07:50PM (#6704435)
I agree with you in that managing real code in a place that gets less frequently executed is a bear, but I wanted to emphasize the value of having tests very near to the primary documentation for a function. That's a complete win, I feel.
Re:Pyret: A new programming language from the creators of Ra... by sitkack on Sunday November 10, 2013 @11:25AM (#6707082)
Which it totally is! That is why all the functions I test are in pairs suitable for nose or py.test

    def test_foo():
        assert False, "test code for foo"

    def foo(farb):
        pass
Tests should absolutely be next to the code. The test should make it into the documentation. Code is documentation and should make it into the generated documentation, not the first thing you see but it should be there along with commit history, etc.
Re:Pyret: A new programming language from the creators of Ra... by tel on Monday November 11, 2013 @01:45PM (#6713161)
If that ended up nicely formatted beneath the definition of `foo` in the documentation I would recommend it wholeheartedly. In practice it doesn't happen, sadly.
Re:Pyret: A new programming language from the creators of Ra... by amenod on Saturday November 09, 2013 @02:05PM (#6702691)
Thank you! I never had any idea this kind of things exists in python... I can already see some code that would benefit from this (it would be insane to put it everywhere of course).
Re:Pyret: A new programming language from the creators of Ra... by driax on Saturday November 09, 2013 @11:23AM (#6702064)
On the other hand, inline test does make it easier to write tests while writing the function. Besides many well-written programs already contains inline documentation (not comments) that can be a lot longer than the function they describes.

Code folding in a IDE goes a long way to make this bearable.

Re:Pyret: A new programming language from the creators of Ra... by stcredzero on Saturday November 09, 2013 @02:39PM (#6702819)
> Code folding in a IDE goes a long way to make this bearable.

Code folding in IDEs is an indication that we are doing it wrong -- that is, we human beings are programming computers "wrong."

I'm not saying that code folding is a symptom. I'm saying that code folding shows how primitive our means of managing code is. It's as if the mesopotamians somehow invented computers, and because of tradition, all code has to be written as cuneiform on wet clay tablets, then fired in ovens before being read. At least text files in directories are digital, but they are as static and behavior-less as clay tablets, and all of the important relationships therein are expressed as implicit correspondences which programmers have to keep track of in their heads.

Code Bubbles is a beacon in the direction we should go.

https://www.youtube.com/watch?v=PsPX0nElJ0k

Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Sunday November 10, 2013 @08:10AM (#6706298)
Code Bubbles were invented one floor above me (by another team in computer science at Brown University). So, we're not at all unaware of it. And yes, it's great stuff.

But we also had to make a conscious decision about IDEs, and we decided to be IDE agnostic -- IDEs should enhance the language but not be the only means of working with it, because programmers are really attached to their editors, and a language predicated on tearing people away from their editors will stuggle. Also, having been part of DrRacket from version 0.0, I know how long it takes to make one that's any good.

Re:Pyret: A new programming language from the creators of Ra... by stcredzero on Sunday November 10, 2013 @02:32PM (#6708043)
Code Bubbles were invented one floor above me (by another team in computer science at Brown University).

I wrote a significant fraction of a Smalltalk class browser.

IDEs should enhance the language but not be the only means of working with it, because programmers are really attached to their editors, and a language predicated on tearing people away from their editors will struggle.

So, basically you made the pragmatic decision. What you say is true, but I suspect this tendency is ultimately holding us back.

Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Sunday November 10, 2013 @07:08PM (#6709143)
I've had this argument for twenty years. I had my a-ha moment in grad school when, after I'd put a fair bit of work into a build system and showed it around, my advisor asked me, "What is a file?" And then I was enlightened. So I can play this song back with fairly good fidelity.

If I could get a reliable, efficient, cross-platform, extensible, quickly-ported-to-new-platforms environment that gave me rich editing, I'd grab it. I don't know of such a platform. So we made the "pragmatic" decision, yes. That's because this isn't the problem we're trying to solve.

We are actually trying to innovate in the programming environment space, and have been running with that experiment for the past semester internally at Brown. At some point, after it's been knocked around a bit more, we'll make it public. So we're not avoiding the environment space. But this is not a battle we're seeking to pick in that space.

I wish you luck with it, and hope we can build on the work of people like you.

Re:Pyret: A new programming language from the creators of Ra... by kazagistar on Saturday November 09, 2013 @03:54PM (#6703159)
While in some sense I agree with you, stuff like code bubbles is just a incremental step from folding. If you want better interfaces for your coding, you write bidirectional transformations between your representation and the text; the point being that the underlying representation does not particularly matter. Having underlying text, however, means you have a good fallback in case your tools do fail.

I would say the more potent point is that it should not matter at all if the tests are in the function or in a different directory: the IDE should be able to fold them in either way, and in some sense, IDEs already do have partial support for this.

Re:Pyret: A new programming language from the creators of Ra... by stcredzero on Saturday November 09, 2013 @04:28PM (#6703322)
> While in some sense I agree with you, stuff like code bubbles is just a incremental step from folding.

I said it was a "beacon in the direction we want to go," not a lighthouse at the destination!

> the point being that the underlying representation does not particularly matter. Having underlying text, however, means you have a good fallback in case your tools do fail.

Sure, do this, so long as the representation doesn't limit the objective capabilities of the environment and so long as it doesn't limit the ways tool makers think about code. Unfortunately, our current representations clearly do both.

Re:Pyret: A new programming language from the creators of Ra... by andrewflnr on Saturday November 09, 2013 @03:39PM (#6703088)
Code bubbles looks cool, but I don't see the connection with your point about clay tablets. Any digital data is, by itself, flat and behavior-less, whether it's in the form of traditional files or some specially-designed backing store for something like Code Bubbles. I don't see any point in really trying to hide that base reality.

I am in favor of giving links between data a more prominent place in our storage systems. I envision a system where the data is mostly fine-grained trees, like sexprs, where hard-links between trees are first-class entities. But at the end of the day it's just an abstraction over a bunch of bytes.

Re:Pyret: A new programming language from the creators of Ra... by stcredzero on Saturday November 09, 2013 @04:31PM (#6703337)
> Any digital data is, by itself, flat and behavior-less, whether it's in the form of traditional files or some specially-designed backing store for something like Code Bubbles.

I know this is false. You can have a system where everything is an object and carries behavior around with it. We've had those for over 40 years.

> I am in favor of giving links between data a more prominent place in our storage systems.

A "more prominent place?" Isn't this a bit bass-ackwards? Aren't relationships in code where the primary value is?

Re:Pyret: A new programming language from the creators of Ra... by andrewflnr on Monday November 11, 2013 @07:47PM (#6715145)
The behavior carried around by those objects is ultimately in the form of flat digital data, interpreted by other, more general programs, executed on a CPU. Behavior, when it comes down to it, is a property of silicon, not data. This might seem like a useless distinction, but I don't think it is. I like to keep track of what things are underneath the abstractions.
Re:Pyret: A new programming language from the creators of Ra... by aidenn0 on Saturday November 09, 2013 @03:37PM (#6703079)
I think you're completely backwards on this.

Code folding in an IDE is an example of a way in which text files aren't necessarily static and behavior-less. I see no reason to move away from an underlying representation as text.

Re:Pyret: A new programming language from the creators of Ra... by stcredzero on Saturday November 09, 2013 @04:33PM (#6703343)
I see no reason to move away from an underlying representation as text.

A big reason is that otherwise people won't move away from the paradigm of static text files. The best they'll do is text files with little gimmicks attached to them.

Re:Pyret: A new programming language from the creators of Ra... by ash on Saturday November 09, 2013 @10:59AM (#6701952)
> Literate programming… didn't catch on

I would argue literate programming is experiencing a renaissance, thanks to docco:

https://github.com/jashkenas/docco

Re:Pyret: A new programming language from the creators of Ra... by e12e on Saturday November 09, 2013 @06:34PM (#6704109)
I think literate coffeescript might be a better example of popularizing literate programming:

http://ashkenas.com/literate-coffeescript/

There also seems to be some traction for literate Haskell:

http://www.haskell.org/haskellwiki/Literate_programming

I experimented a bit with literate programming on an introductory course in programming using java. It's an interesting experience -- it's very easy to produce a very readable language that is still pretty poor java code, as it becomes so easy to split out fragments and "procedures", rather than follow the more common java class-oriented object orientated way of doing things.

Re:Pyret: A new programming language from the creators of Ra... by pjmlp on Saturday November 09, 2013 @12:54PM (#6702392)
Not really, I never heard of docco and am yet to see a RFP for a node.js project from my employer's enterprise customers.
Re:Pyret: A new programming language from the creators of Ra... by vidarh on Saturday November 09, 2013 @10:34PM (#6705032)
Chances are much higher that you've seen the output of Docco or one of the multitude of imitations for other languages.
Re:Pyret: A new programming language from the creators of Ra... by msutherl on Saturday November 09, 2013 @01:01PM (#6702413)
You would think we'd have editors by now that could, say, hide all the tests to declutter the code while you're reading it.
Re:Pyret: A new programming language from the creators of Ra... by qznc on Saturday November 09, 2013 @02:32PM (#6702794)
I think you are both right. D even takes it to the next logical step: Present the unit tests as examples in the API documentation (like Doxygen,Javadoc). It means the API examples are kept in sync.

http://qznc.github.io/d-tut/testing.html

Re:Pyret: A new programming language from the creators of Ra... by acjohnson55 on Saturday November 09, 2013 @03:17PM (#6703000)
If the tests are pages long, that might be a sign that the function could be refactored. Also, the optional type annotations and refinements seem to decrease necessary testing quite a bit, compared to the typical scripting language. I would use this all the time.

And as other people mentioned, you can always use the check statement out of band, too.

Re:Pyret: A new programming language from the creators of Ra... by seanmcdirmid on Saturday November 09, 2013 @06:57PM (#6704212)
> It clutters the code.

Modern IDEs/code editors can support code folding as well as projections fairly easily. I don't see a problem.

Re:Pyret: A new programming language from the creators of Ra... by ash on Saturday November 09, 2013 @10:24AM (#6701837)
Making tests part of language syntax is an interesting idea.

Of course it's not equivalent, but Python doctest module at least allows you to keep tests close to the code. Here's Pyret example, ported to doctest:

  def sum(l):
      """
      >>> sum([])
      0
      >>> sum([1, 2, 3])
      6
      """
      return reduce(lambda x, y: x+y, l, 0)

  if __name__ == "__main__":
      import doctest; doctest.testmod()
Re:Pyret: A new programming language from the creators of Ra... by laureny on Saturday November 09, 2013 @11:24AM (#6702068)
> Making tests part of language syntax is an interesting idea.

It's been tried many times before and it has always failed. A few reasons:

- It clutters the code

- If you need simple tests, asserts suffice

- If you need more sophisticated tests, write functional tests, separately

The approach offered by Pyret (along with similar ones, such as design by contract) are compromises that are the worst of both worlds.

Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Saturday November 09, 2013 @01:34PM (#6702539)
It's actually widely used in Racket already. Yesterday a lead programmer at a major financial institution told me that he liked that style so much, he'd incorporated it into his company's OCaml system, and they use it in their production systems (lots of high-volume trading). Hardly "failure"s.

Nevertheless, perhaps you could provide some pointers to the "many" projects that have tried it before?

Assertions are not tests. This is a fundamental misunderstanding of the difference.

Pyret's `check` blocks exist to write complex tests, separate tests from definitions, or write tests that cross multiple functional units. So they offer the power of regular testing frameworks.

Thus, `where` is the bonus, not a "compromise".

Re:Pyret: A new programming language from the creators of Ra... by mercurial on Saturday November 09, 2013 @04:44PM (#6703397)
This might work better for pure functions. I can't imagine it working very well for complex, stateful code which requires mocking and resetting the state between tests.
Re:Pyret: A new programming language from the creators of Ra... by tel on Saturday November 09, 2013 @07:58PM (#6704485)
Given that Pyret is functional, there's a good chance there will be an emphasis on simple, pure functions.

Beyond that, I'd agree completely. Doctests, for instance, are quite terrible when you can't fit all of the logic into one line, but then I think it's usually a sign of a well-designed function when it's good a good enough interface to get a few pithy doctests in.

Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Sunday November 10, 2013 @08:23AM (#6706336)
Though Pyret is not pure, our emphasis is heavily on "functional first", even for objects. We believe state should be used carefully and for good reasons. HtDP (www.htdp.org) has two whole chapters on state at the end, giving design recipes for their use, and I'm revising some of these in PAPL (papl.cs.brown.edu/2013/).
Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Sunday November 10, 2013 @08:24AM (#6706338)
This is why a test block is a block. Writing inline tests for stateful functions in Racket was a bit painful because it is so heavily expression-oriented. We want to make this feel more natural.

(Another virtue of test blocks: you can write little local helper functions. There's an example of this on the Pyret home page.)

Re:Pyret: A new programming language from the creators of Ra... by acjohnson55 on Saturday November 09, 2013 @05:57PM (#6703905)
They didn't say one way or the other whether the language was pure FP, but I don't think any of the examples featured mutuality
Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Sunday November 10, 2013 @08:21AM (#6706330)
Pyret is not pure. We have mutation. But mutation has its own syntax different from regular binding. Variables (as opposed to identifiers) are preceded by "var", and variable mutation uses ":=". [Similarly for fields.] This it to make clear to all forms of readers -- programmers, compilers, IDEs -- when something is mutable.
Re:Pyret: A new programming language from the creators of Ra... by anaphor on Saturday November 09, 2013 @03:17PM (#6702998)
Have you thought about adding some kind of QuickCheck-ish model where test cases can be randomly generated for various types?
Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Sunday November 10, 2013 @08:19AM (#6706329)
Yes, of course, we've thought about it. Equally importantly, we have a "satisfies" keyword for stating checks about properties. (See the example on the Pyret home page.) We use test oracles extensively in teaching; see these two assignments: http://cs.brown.edu/courses/cs019/2012/assignments/sortacle , http://cs.brown.edu/courses/cs019/2012/assignments/oracle .
Re:Pyret: A new programming language from the creators of Ra... by tel on Saturday November 09, 2013 @07:56PM (#6704478)
This exists in Haskell's doctest library

    -- | Documentation goes here
    --
    -- > 2 + 2 == 4
    -- True
    --
    -- prop> \lst -> reverse (reverse lst) == lst
Re:Pyret: A new programming language from the creators of Ra... by ducklord on Sunday November 10, 2013 @01:28PM (#6707747)
> Yesterday a lead programmer at a major financial institution told me that he liked that style so much, he'd incorporated it into his company's OCaml system, and they use it in their production systems (lots of high-volume trading).

Hmm...Jane Street?

Re:Pyret: A new programming language from the creators of Ra... by ufo on Saturday November 09, 2013 @10:49AM (#6701906)
Racket has a very powerful contract system that you might want to out. It also has support for higher-order contracts on functions (contracts that have delayed checks instead of being just assertions) and they also have a typed version of Racket (Typed Racket) built using the contract system.
Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Saturday November 09, 2013 @01:37PM (#6702563)
Some of the Pyret designers are part of the Racket community, and know these ideas well. Where Pyret differs is that Racket has two different languages (for the purposes of this discussion), Racket and Typed Racket, and a program has to live in one or the other. Whereas Pyret takes a different "gradual" philosophy to type annotations, so a program doesn't have to move between the two languages.
Re:Pyret: A new programming language from the creators of Ra... by ufo on Saturday November 09, 2013 @08:18PM (#6704582)
I was just trying to point out that Pyret is not inventing the contract-checking and that Racket, the language Pyret owes a lot to, already has the contract system terhechte was looking for. Maybe I should have been more clear.

That said, I'm going to take the opportunity to ask a question: does Pyret's gradual typing cover parametric polymorphism and mutable data structures? Those usually are specially though to do in these fully gradual systems so I'm curious what you guys have done about that.

Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Sunday November 10, 2013 @08:52AM (#6706406)
Sorry, lost track of what you were responding to.

Re. your other question, yes, this is a wide-open problem, and we're trying to not get bogged down in research issues like this. We actually have one answer about what to do, presented in a paper we wrote some time ago (http://cs.brown.edu/~sk/Publications/Papers/Published/gmfk-r...), but we don't really want to do that. But because we're working on a (curious) type inference story, we may be able to carve up this problem in a very different way.

Sorry for the non-answer. You're right, and we're working on it.

Re:Pyret: A new programming language from the creators of Ra... by ufo on Sunday November 10, 2013 @09:11AM (#6706459)
Thanks, in a way the non-answer is more useful than a real answer for me :)
Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Sunday November 10, 2013 @02:46PM (#6708088)
I'll read between the lines and just say, "Send us a link to your paper when it's done" (-:.

In fact, we'd really love it if gradual typing folks would tell us what set of primitives they miss in a language. They aren't constrained to what Racket or Python or whatever; there may be a primitive that makes sense that Pyret can add to enable space-efficient, semantically-meaningful contracting or gradual typing in the presence of such operations.

Re:Pyret: A new programming language from the creators of Ra... by samth on Monday November 11, 2013 @07:47AM (#6711308)
As one of those gradual typing folks, I'm not sure what you mean by "primitives we miss". The things I'd want for space efficiency are things like a contract language with decidable 'and', and for regular efficiency, a compiler that is good at seeing through wrappers.
Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Monday November 11, 2013 @08:09AM (#6711384)
Well, there's a preliminary answer!

Though I'm not enamored of the Typed Racket style of wrapping everything at the boundary (even as I appreciate why it's there). Not even hypothetical: we actually began developing Pyret in TR but, with great sadness, ended up having to move it out because of the enormous performance hits.

Re:Pyret: A new programming language from the creators of Ra... by samth on Monday November 11, 2013 @09:05AM (#6711607)
But neither of those is a "primitive". The first is a major restriction on contracts (and not a restriction Pyret enforces, AFAICT). The second isn't a language feature at all. How would having a new language help give me either of these?

And yes, soundness + interoperation + structural types = heavy performance cost. You can give up on one of those easily, but the combination can't be free.

But the best way to make TR programs not pay that cost is to not cross the boundary all the time, which it sounds like is what you were doing. Why was that necessary?

Re:Pyret: A new programming language from the creators of Ra... by vidarh on Saturday November 09, 2013 @10:53AM (#6701921)
Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Saturday November 09, 2013 @01:35PM (#6702547)
Not even remotely in just about any respect.
Re:Pyret: A new programming language from the creators of Ra... by vidarh on Saturday November 09, 2013 @07:24PM (#6704330)
Really? The concept of a block that specifies a contract does not sound similar to the design by contract capabilities of Eiffel. Care to enlighten us why not?

Perhaps you think I was referring to something other than the quote in the comment I replied to.

Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Sunday November 10, 2013 @08:27AM (#6706341)
Contracts are fundamentally different from tests. Contracts are abstract specifications about values while tests are concrete specifications about values. The concrete vs abstract distinction is fundamental, as I hope is clear.

That's why Pyret has both tests and contracts (for now, in the form of refinements). This is a distinction that has been explored extensively in Racket also, all fully aware of Eiffel DBC.

Re:Pyret: A new programming language from the creators of Ra... by catwell on Tuesday November 12, 2013 @09:46AM (#6718085)
Those refinements are nice. Pre- and Post- conditions are illustrated, is there any way to describe an invariant?

Also, maybe you should have called them something else since a lot of people will think about completely different when they hear this word... (http://www.ruby-doc.org/core-2.0.0/doc/syntax/refinements_rd...)

Re:Pyret: A new programming language from the creators of Ra... by draegtun on Wednesday November 13, 2013 @08:46AM (#6725081)
re: refinements nomenclature...

Rebol got there first though! - http://www.rebol.com/r3/docs/datatypes/refinement.html

Matz is known to like Rebol - https://twitter.com/matz_translated/status/25061436079433318...

Re:Pyret: A new programming language from the creators of Ra... by ufo on Saturday November 09, 2013 @08:21PM (#6704598)
Eiffel contracts are relatively primitive compared to the more modern Racket and Pyret contracts. Eiffel contracts are basically limited to assertions and don't support contracts on higher order function arguments, refinements, etc.

There is also the whole dynamic typing thing. Eiffel is still fully statically typed.

Re:Pyret: A new programming language from the creators of Ra... by vidarh on Saturday November 09, 2013 @10:17PM (#6704987)
None of which changes what I wrote earlier.

In terms of my opinion of Racket/Pyret, though, there's been a number of Ruby projects to do similar stuff to this over the years, since it's trivial to add (just add a class method that redefines a method and wraps it in code to execute the contracts), and a lot of Ruby newbies try to find ways of adding back the restrictions they've lost when moving from statically typed languages.

Invariably they've ended up dying or not getting much interest, largely because a large part of the appeal of dynamic languages for a lot of people is that the code reads simple. In the Ruby world at least, aesthetics is a big deal. And putting the tests inline destroys that aesthetic and makes it harder to read the code.

Especially because tests tends to be trite and repetitive and contain a lot of stuff that is obvious to a human when you have the code right in front of you.

Especially when they go beyond documenting contracts that are intended to bind subclasses to an interface.

That code readability is important.

I have a prototype for my own Eiffel inspired language with DbC support, and my own experience with it was that as much as I love the idea, even Eiffel level contracts are bordering on being too verbose, for these reasons.

Pull them out into separate files, and they're a lot more acceptable, but then what is the difference from any other unit testing framework?

Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Sunday November 10, 2013 @08:40AM (#6706378)
This "static" vs "dynamic" distinction is largely artificial. Every program has parts that make sense to think of as "static" and parts that will be very "dynamic", and the ratio of these two differs from program to program (and even within a program, from day to day).

The same goes for making statements about programs.

Therefore, in Pyret, we recognize that there are lots of different levels at which we make statements about our programs: from tests through types to specifications, spanning both static and dynamic aspects. They not only aren't in conflict, they're even related. Most languages include only a subset of them or make them appear to be disjoint. In contrast, in Pyret, we're already working on linking these to one another, and are going to keep pushing in this direction.

Languages that leave out one or more of these end up forcing users to reinvent these wheels for themselves (because they're each good ideas that people inevitably want). But by forcing people to reinvent a wheel, they end up giving users ad hoc versions of these tools, and also introduce friction between these parts. (E.g., as Robby Findler found several years ago, just about every single bolted-on DBC system had significant limitations or errors.)

Re:Pyret: A new programming language from the creators of Ra... by jacques_chester on Saturday November 09, 2013 @10:11AM (#6701796)
D has something like this[1]. It might have come from a still-earlier language.

[1] http://dlang.org/unittest.html

Re:Pyret: A new programming language from the creators of Ra... by sparkie on Saturday November 09, 2013 @11:53AM (#6702173)
My biggest gripe with these is the inability to name the tests. What exactly is a unittest block testing for? You need to rely on comments or read the test code where none exists. Doesn't seem like Pyret fixed that issue.
Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Saturday November 09, 2013 @01:38PM (#6702564)
Everything is fixable in a new language (-:. Say more!
Re:Pyret: A new programming language from the creators of Ra... by akkartik on Saturday November 09, 2013 @03:37PM (#6703078)
One of my favorite things about tests is that they let me read a new codebase more interactively. If I don't understand why a function is built like this and not that I can rewrite it the new way, run the tests. Without names I'd know I broke something, but with a good name I'll often realize why that something matters in the big picture.

(I think about tests a lot: http://akkartik.name/post/tracing-tests)

Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Saturday November 09, 2013 @06:58PM (#6704219)
I understand your point. One thing I pushed for initially, dropped because we had bigger fish to fry, and will revisit later, is the idea that you should be able to name everything: not just tests but an individual variant in your data definition, lines of code, etc. And this should be intrinsic to the language.

That said, I couldn't see what your post had to do with this concept; if I've missed something, please explain. (As an aside, I believe this -- http://cs.brown.edu/~sk/Publications/Papers/Published/mcskr-... -- generalizes the idea in your tracing post.)

Re:Pyret: A new programming language from the creators of Ra... by akkartik on Saturday November 09, 2013 @09:32PM (#6704845)
Thanks. My post wasn't about names, I was just looking for feedback. Which I got; thanks.
Re:Pyret: A new programming language from the creators of Ra... by alexatkeplar on Saturday November 09, 2013 @08:42PM (#6704669)
I would like it if the `where` tests supported DataTables for a slightly more declarative style. Here's an example from Scala/Specs2: https://github.com/snowplow/snowplow/blob/master/3-enrich/ha...
Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Sunday November 10, 2013 @08:48AM (#6706398)
The fact that they don't now doesn't mean they can't in future!

One of the advantages of having a separate block for tests is we can do things in that block that won't necessarily pervade the whole language where it might not make sense (which we already do: eg, the keywords "is" and "satisfies"). We've all done some sort of "here's a list of tuples, now map the prefix of this as arguments and the suffix as the expected value over this function", so it is something on our mind.

But I've struggled a bit to find a good way of writing it. We've written a few things where it looked truly "naked" to have these tuples without the surrounding function call. So it's as much a matter of syntax design as anything else.

I must say that the code on that page does not look like something I want to copy; it looks like a good compromise, but with emphasis on both words. We don't need to compromise.

Re:Pyret: A new programming language from the creators of Ra... by alexatkeplar on Sunday November 10, 2013 @02:09PM (#6707936)
If you can up with a cleaner syntax for test data tables that would be awesome, thanks Shriram.
Re:Pyret: A new programming language from the creators of Ra... by sitkack on Saturday November 09, 2013 @02:10PM (#6702716)
Could the tests be more declarative, defining properties over a space?
Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Saturday November 09, 2013 @05:31PM (#6703685)
Absolutely! Pyret's test section has a "satisfies" keyword for property tests. E.g.:

  check:
    insert(a-value, a-balanced-tree) satisfies is-balanced
  end
or even

  check:
    tree-examples = [ ... ]
    values = [ ... ]
    for each2(t in tree-examples, v in values):
      insert(t, v) satisfies is-rbtree
    end
  end
Re:Pyret: A new programming language from the creators of Ra... by amenod on Saturday November 09, 2013 @02:08PM (#6702705)
That's an advantage in my book... it is testing the unit (function in this case) and it is testing all the corner cases... do you have a name for each of them? Description through comments is much more suitable IMHO.
Re:Pyret: A new programming language from the creators of Ra... by lukeschlather on Saturday November 09, 2013 @04:31PM (#6703335)
I really hate some things about the Rspec/Cucumber suite, but providing a way to output what the tests are testing as they run is a major advantage. I like being able to run my test suite and see "it does what it's supposed to do in this case" output.

At a glance, the Pyret default appears to be that tests run silently. How do I know the right tests were run?

Re:Pyret: A new programming language from the creators of Ra... by mercurial on Saturday November 09, 2013 @04:39PM (#6703374)
Corner cases? Tests test the behaviour of the function. Functions, depending on their complexity, have a range of behaviour. And yes, you should (usually) be able to come up with a name for it. As a bonus, you'll get immediately an idea of what broke upon test failure.
Re:Pyret: A new programming language from the creators of Ra... by keppy on Saturday November 09, 2013 @01:18PM (#6702478)
in clojure:

  (with-test
      (defn my-function [x y]
      (+ x y))
    (is (= 4 (my-function 2 2)))
    (is (= 7 (my-function 3 4))))
Re:Pyret: A new programming language from the creators of Ra... by rmc on Saturday November 09, 2013 @11:37AM (#6702122)
AST-Macro enabled languages (... Python)

What?! You can't write macros in Python? (right? have I missed something?)

Re:Pyret: A new programming language from the creators of Ra... by anonymous on Saturday November 09, 2013 @11:54AM (#6702177)
Re:Pyret: A new programming language from the creators of Ra... by eliben on Saturday November 09, 2013 @10:52AM (#6701917)
I'm not sure I like having tests in the same file with the code. In real code bases it's very common to just read the code, and cluttering that with huge swaths of unit-tests is counter-productive.

That said, Pyret appears to be aimed at education so this may make more sense.

Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Saturday November 09, 2013 @04:47PM (#6703411)
Then you can put your tests in a `check` block and move them elsewhere. You don't have to use `where` except when it makes sense.
Re:Pyret: A new programming language from the creators of Ra... by reeses on Sunday November 10, 2013 @03:05AM (#6705710)
This is bouncing against the perpetual "code as text" problem.

Put the tests and docs in with the code and you end up going into "scanning" mode. The actionable information density per character is lower.

Put the tests and docs outside the code and you (or that obnoxious guy who just changed > to >=) don't update the tests or the docs. In the worst case (cough functional web tests) people tend to disable the tests because it's too much work to get them to conform to the changes and everyone is on fire and babies are dying and this needs to be done in production now.

Re:Pyret: A new programming language from the creators of Ra... by pjmlp on Saturday November 09, 2013 @10:30AM (#6701860)
Contracts?
Re:Pyret: A new programming language from the creators of Ra... by skrishnamurthi on Saturday November 09, 2013 @05:32PM (#6703696)
Every time you write a refinement on a type, you're actually writing a contract. You can gracefully move between types and contracts this way, and also between thinking of them as checked assertions vs tested ones. The goal is to make this migration more and more seamless.
Re:Pyret: A new programming language from the creators of Ra... by pjmlp on Sunday November 10, 2013 @03:34AM (#6705750)
Yes, I although I have used a multitude of dynamic languages on my career I tend to lean on the static type languages with type inference side.
Re:Pyret: A new programming language from the creators of Ra... by GhotiFish on Saturday November 09, 2013 @10:36AM (#6701871)
That really caught my eye!

Does anyone have any experience with workflows like this? Are tests next to code a pragmatic technique?

Re:Pyret: A new programming language from the creators of Ra... by qiemem on Saturday November 09, 2013 @12:36PM (#6702318)
Python has them in the form of doctests. They are generally frowned upon as they tend to significantly clutter up code and documentation when they actually provide comprehensive testing. That said, Pyret's format may escape that fate as they are given their own section which most modern editors should be capable of folding.

Doctests: http://docs.python.org/2/library/doctest.html

Re:Pyret: A new programming language from the creators of Ra... by swift on Saturday November 09, 2013 @08:19PM (#6704587)
Haskell also has a library for doctests, though I don't see them used that frequently:

https://github.com/sol/doctest-haskell#readme

Re:Pyret: A new programming language from the creators of Ra... by keppy on Saturday November 09, 2013 @01:25PM (#6702499)
I use this in clojure where I am interacting with the code from the repl. run-tests will execute tests for function defns wrapped with the with-test macro. This is fast and no external file or namespace needs to load just type run-tests; http://richhickey.github.io/clojure/clojure.test-api.html
Re:Pyret: A new programming language from the creators of Ra... by wuschel on Saturday November 09, 2013 @10:38AM (#6701875)
Interesting. Could you propose such an extension by posting a code sample e.g. in scheme?
Re:Pyret: A new programming language from the creators of Ra... by ek on Saturday November 09, 2013 @11:15AM (#6702016)
Sure. These are basically simple contracts. Contracts are implemented in Racket: http://docs.racket-lang.org/reference/contracts.html
Re:Pyret: A new programming language from the creators of Ra... by mck- on Saturday November 09, 2013 @01:17PM (#6702470)
I was thinking exactly the same thing after I read that :)