6 ms·
BasicCoin, a cryptocurrency in less than 600 lines of Python
- sakai 12y agoHonest suggestion: Change the tagline to "less than 1000 lines" or exclude the GUI or whatever, but don't just not include line breaks anywhere. You have 7 very sensible, and indeed admirable, style guidelines and while no line breaks only clearly violates one of them (PEP8), it's not really in the spirit of the others either. I opened gui.py and immediately was overwhelmed, rather than compelled to dive in and digest your small codebase.
- cpach 12y agoAs someone more accustomed to Lisp than Python I must say the lack of extra line breaks didn't feel so weird to me :)
- eordano 12y agoVery cool! Though it looks like "less than 600 lines" made you write awfully styled code :/
- stuki 12y agoI have to say I think crypto currencies is an area where the keep it simple approach is extremely beneficial. If it means fever optimizations, and leads to a greater dependency on off chain transactions, so be it. For genuinely wide spread adoption, more important than speed and transaction volumes, are an ironclad faith in the integrity of the underlying code itself.
- vojfox 12y agoI wonder how practical it would be to take Bitcoin Core and gradually reduce its # of (non-blank) lines.
- wyager 12y agoSadly, the core client has the job of being capable of bootstrapping itself starting at the genesis block and ending at the most recent block. That means that, barring a huge design change in Bitcoin itself, the core client has to support every single feature ever implemented in Bitcoin, no matter how half-assed or poorly thought out. That's why things like the way P2SH got implemented really grind my gears. Bitcoin has a few idiosyncratic and unintuitive design additions that make it really hard to make simple clients.
- codexon 12y agoI wish you tried to make the code readable rather than making as many 1-liners as you could.
- roasbeef 12y ago600 lines, however the codebase is quite unreadable. Typically, code written in python is rather readable and easy to follow, but this is heavily condensed and somehow completely void of any sort of pythonic code. Programs are the communication of thoughts between fellow software writers, readability should be your #1 priority.
- kylnew 12y agoYeah. The author says they are following pep8 but I thought spaces between functions was part of those guidelines. Definitely trying hard to reduce the lines below 600. Yet I feel like if the bragging rights had been "under 1000 lines" we still would be equally interested.
- meowface 12y agoVery little of this follows PEP8. The code appears to have been written as tersely as possible, even in cases where it would have utterly no effect on the 600 SLOC limit.
- shabinesh 12y agoThe idea is cool and helps to learn crypto coin systems. But restricting the number of lines of code might only make it obfuscated. :)
- rabino 12y agoUnless I'm missing something, the only advantage of it being only 600 lines of code is for educational purposes. But condensing the code in such way to reduce line count goes against such objective. Any other reason to advertise brevity in LoC?
- maaku 12y agoFewer points of failure for consensus. Of course, being written in a dynamic interpretive language goes against that.
- agorism 12y agoIt just happens to be 600 lines right now, and it is now functioning properly. I am hoping that it's small size will make people less afraid to take part. I am not trying to do it in the minimal lines possible. It just happens to be that short.
- kordless 12y agoMillions of currencies. I was standing at the back of the room when Andreas said that and I was like, yeah, I can see it. The blockchains deliver trusted communication of stored work to us. The network has value in and of that function alone. That I can verify you have thing of X value and I have thing of Y value and that the ratio of X to Y is such as established by these market APIs/feeds. Which themselves are running on a trusted computing platform that is a fair and accurate representation of what is what in this world, up to a point. That there will be a million blockchains working together in a mishmash of interconnected markets, is no more difficult than imagining a million seperate computer networks, each of which is using a private address block 10.0.0.0/24. Some things are meant to be highly distributed, some are not. Why would you ever expect a cryptocurrency based on the thesis of high distribution to ever be a singleton itself?
- therealpatriot 12y agoerrm...what tha fuck did you just say?
- roasbeef 12y agoSee Sidechains[0], and Treechains[1]. But as always, without the proper incentives a block chain is unsustainable and vulnerable. [0]: http://sourceforge.net/p/bitcoin/mailman/message/32108143/ http://sourceforge.net/p/bitcoin/mailman/message/32108143/ [1]: https://www.mail-archive.com/bitcoin-development@lists.sourceforge.net/msg04388.html https://www.mail-archive.com/bitcoin-development@lists.sourc...
- yeukhon 12y agoI am bother by the desire to get smaller and smaller. A secure implementation will have a lot of code to verify incoming data and handle exceptions. It is fun to learn and implement HTTP server from the raw socket module (I did that once for my security project in my computer security class too), but if you are just looking for a simple server that you can handle GET and POST look into bottle.py A single file / pip install write into setup.py and you are good to go. This I consider as educational, which I assume is the case by the desire to go smaller and implementing such socket server.
- limmeau 12y agoWouldn't it be even easier to just use Git for most of the heavy lifting? - Ledger is a file in a Git repo - Blocks are confirmed by committing them with a SHA1 with sufficiently many leading zeros (adjust a nonce in the commit msg until it fits) - Some bot accepts all pull requests into the Github repo that are fast-forward and whose commits have sufficiently many leading 0s (possibly after confirming that the booking is valid ;) We could call that... oh I don't know, DvcsCoin or so.
- knocte 12y agoInteresting idea, but I hate the name :)
- philtar 12y ago'gitcoin' Perfect name. Knowing HN this is gonna be a show HN in a couple of days and rewritten in 10 lines of js a week after that.
- zachlatta 12y agoThis was a challenge in Stripe CTF3. As mentioned by aljungberg, see https://github.com/ctfs/write-ups/tree/master/stripe-ctf3/level1 https://github.com/ctfs/write-ups/tree/master/stripe-ctf3/le...
- aljungberg 12y agoThat's what Stripe's CTF3's Gitcoin was like: https://github.com/ctfs/write-ups/tree/master/stripe-ctf3/level1 https://github.com/ctfs/write-ups/tree/master/stripe-ctf3/le...
- btmorex 12y agoBasically unreadable. Not sure what you were going for, but I think it was the wrong thing. Off the top of my head: 1.) There's no reason not to use newlines. They have no chance of introducing bugs in any reasonable language and they aid readability. 2.) You're using closures all over place and I haven't checked every occurrence, but I strongly suspect that almost all of them are unnecessary and unhelpful. Closures are not free in terms of code complexity. Use them only when necessary.
- agorism 12y ago1) newlines reduce the amount of code that you can see on the page at a time. Skipping newlines is identical to purchasing a bigger monitor. 2) Some people group similar functions into classes. I dislike classes and prefer grouping code this way.
- DavidBradbury 12y ago> Skipping newlines is identical to purchasing a bigger monitor. Wat.
- python26rocks 12y agoThis is really poor
- frantzmiccoli 12y agoThe idea seems legit ; however trying to reduce the number of lines of code by a "no skipped lines & no comments" policy is not helping the ease of modification, which seems to be one of the target.
- drcode 12y agoCan anyone figure out where in this code it determines the addresses of other peers?
- agorism 12y agotools.py it uses pybitcointools library.
- drcode 12y agoHmm... I still don't understand... There has to be some place(s) online where peers register their existence, to find others to connect with. Near as I can tell, this app doesn't have a feature for this yet. I'd argue it isn't a cryptocurrency unless there's a mechanism for finding other peers included in the code. (That said, this is still an awesome proof of concept, and I'm going to work through all the source code carefully.)
- xiphias 12y agoIt's awesome idea but..could you add comments? (hint: you don't need to count the comments when counting lines of code :) it's normal to have more comments than code for a dense code, and it make things easier to understand )
- joyofdata 12y agoIf I'd get one Bitcoin for every cryptocurrency that is promoted on HN, ...
- drcode 12y agoI find it depressing that someone puts into the work to make a cool library and 2/3rds of the comments are whining about the author using the "wrong" number of newlines and other stylistic issues.