4 ms·
Source code for those interested: https://github.com/corbett/QuantumComputing https://github.com/corbett/QuantumComputing
by adrenalinelol 10y ago
Source code for those interested: https://github.com/corbett/QuantumComputing https://github.com/corbett/QuantumComputing
- OJFord 10y agoOh great, it's a single >2k line file...
- leetrout 10y agoI realize this will probably be downvoted because it's not adding anything productive to the conversation but I agree with you 100%. I'm running in to that with Go. Go even makes it super easy to break things out in to multiple files transparently and people still just toss everything in one file. In this specific case, and I am a super pedantic, anal retentive when it comes to python, I really wish more people would use pylint / pyflakes / flake8. Use 4 spaces, order & organize your imports so I can easily see what's third party and what's core and as pointed out organize the code in to modules when it makes sense. I know PEP-8 (& PEP-257) polarizes people and one of the biggest things I LOVE about Go is `gofmt` & `go vet`. Just follow a community standard so we don't spend so much brain power figuring out so many independent styles & conventions. And if everyone disagrees (pretty much everyone complains about 80 cols width) then it usually ends up coming up in other community discussions and the diversions become common and expected. Rant over- tl;dr I really love community style / organization guidelines, code organization and linting.
- Waterluvian 10y agoEveryone doing it the same way is far more valuable than individuals doing everything 5% faster. Every Python library I read is immediately accessible to me. This hasn't been the case for JavaScript.
- wodenokoto 10y agoI never understood why python allows both spaces and tabs as indentation. Even 2 or 3 spaces sometimes work. It seems odd to allow this and then ask everyone to use 4 spaces.
- andrepd 10y agoBecause tabs make much more sense (to me personally) and so I would like to use them, and not have a specific convention imposed on me.
- wodenokoto 10y agoYou will always have syntax imposed on you. With python you have indentation imposed on you, whether you like it or not. In other languages, indentation is a style option. Using tabs makes your python code (potentially) incompatible with other peoples code, due to a style convention. This seems utterly crazy to me. Yes, I prefer tabs too, but this tabs/spaces/different number of space feels like if C had the option of using either curly braces or parenthesis for blocks.
- andrepd 10y agoPoint taken. I wish the decision was done to standardise tabs rather than spaces. But since the convention is now spaces, at least in Python, it would do well do follow those conventions.
- poooogles 10y agoThis has changed a little in Python 3 which disallows mixing the use of tabs and spaces for indentation.
- minitech 10y ago> Even 2 or 3 spaces sometimes work. What? Every number of spaces always works. Anyway, it's nice to separate style recommendations and syntax.
- realpeach 10y agoYou mean the sub-directory level structure with a file somewhere that defines the name of your TODO app?
- userbinator 10y agoGo even makes it super easy to break things out in to multiple files transparently and people still just toss everything in one file. I've heard it phrased thus: "scrolling through one file is easier than jumping around between files", and that fits with my experience. That said, although I'm not very familiar with Python, this file does have a lot of "verticality" with lines like t q[2]; h q[2]; h q[0]; h q[1]; ... which I would try to express in a bit more compact form, and I'd think stuff like this could be better written with arrays and/or procedurally generated: self.three_qubits_000=np.kron(self.two_qubits_00,State.zero_state) self.three_qubits_001=np.kron(self.two_qubits_00,State.one_state) ...
- rfrey 10y agoThat seems like a petty criticism. The code is very well formatted, variables are clearly named, it's indented well and consistently. I had no trouble reading and understanding the code, did you? It's not necessarily my style to keep everything together, but that's what it is, a style. Code folding works great and is a feature of every editor I'm aware of.
- hoov 10y agoI respectfully disagree, but I suspect this might be a disconnect between different Python communities. I find the code extremely difficult to parse. Even ignoring the egregious PEP-8 issues (and, I know that PEP-8'ing existing code can obfuscate commit history), there's too much logic on many lines. I strongly subscribe to the adage that "Code is read many more times than it's written".
- userbinator 10y agoThe essence of your argument is "I don't understand because it's too hard for me"? Maybe that's true --- it certainly is for me --- but since this is quantum computing, I wouldn't expect to just understand this code without at least some background in QM. "Everything is hard before it is easy."
- hoov 10y agoThat's not quite what I was trying to say. What I was saying is that there's many splits in the Python community. I work on large distributed systems, and have zero experience with quantum computing or advanced maths. But, I'm a curious individual. I'd love if the academic Python community (to try to put a label on it) would all write code that was "idomatic". I know that "idomatic" is a problmatic term, but specifically I'm asking for people to follow PEP-8 and generally follow the ethos of `import this`. Once we're speaking a common vernacular, we can better share ideas.
- cyphar 10y agoNote that many researchers in fields other than computer science do not program for fun. They know their code isn't the best in the world, but they'd rather spend their time testing hypothesis rather than reading screeds about the "right way" of formatting some bits on their disk. My experience with most other researchers' code is that taking the logic and rewriting the code is more efficient than trying to fix the code they've shown you. But they deserve respect for not evangelising formatting over function -- a form of respect I cannot extend to you.
- irfanka 10y agowell, literally half of that are unit tests (starting at line 1370)
- GFK_of_xmaspast 10y agohttps://github.com/corbett/QuantumComputing/pull/new/master https://github.com/corbett/QuantumComputing/pull/new/master
- mattcaldwell 10y agoOh, come on... this code is fine. Stop your naysaying.
- deleted 10y ago[deleted]