4 ms·
This looks promising. Nothing that has never been done before, but I really like the support for baked in doctests and contracts. This kind of sugar can make a
by thomasz 14y ago
This looks promising. Nothing that has never been done before, but I really like the support for baked in doctests and contracts. This kind of sugar can make a real difference in terms of quality and readability
#from the website, because it seems to be down for many right now.
class SmallSample
var _random = Random()
def randomString(length as int, alphabet as String) as String
require
length > 0
alphabet <> ''
ensure
result.length == length
test
utils = SmallSample()
assert utils.randomString(5, 'ab').length == 5
s = utils.randomString(1000, 'a')
for c in s, assert c == 'a'
body
sb = StringBuilder()
for i in length
c = alphabet[_random.next(alphabet.length)]
sb.append(c)
return sb.toString
- jksmith 14y agoI've always wanted to work with a language that supports contracts (originally Eiffel I guess). Would love to see this hacked into Go. Or maybe I shouldn't turn this into a Go thread and start using Cobra.
- draegtun 14y ago> I've always wanted to work with a language that supports contracts (originally Eiffel I guess). Would love to see this hacked into Go. There have been a few attempts to hack (design by) contracts into Perl. Here are some which can be found on CPAN: * Class::Agreement - https://metacpan.org/module/Class::Agreement https://metacpan.org/module/Class::Agreement * Class::Contract - https://metacpan.org/module/Class::Contract https://metacpan.org/module/Class::Contract * Sub::Contract - https://metacpan.org/module/Sub::Contract https://metacpan.org/module/Sub::Contract Sub::Contract is my favourite because it's lightweight, pragmatic & with a more Perlish implementation.
- thomasz 14y agoIf you work with .net, the code contracts project[1] is halfway there: It's quite ugly and they made some design decisions I don't agree with (for the wrong reasons, i guess...), but it has had a tremendous impact on the quality of my code. http://research.microsoft.com/en-us/projects/contracts/ http://research.microsoft.com/en-us/projects/contracts/
- darkstalker 14y agoOn that example, the syntax looks like Python with a bit of BASIC (the type declarations). That "StringBuilder" object reminds me of Java, I would prefer a concatenation operator. Seems that doesn't use explicit variable declaration. Supporting that would be a great improvement over Python.
- yogo 14y agoIt has explicit variable declaration. You can always do: varname as Type = expression You often won't see this for the sake of succinctness. I might have misunderstood what you were saying but thought I'd mention that.