Live data from Hacker News

Pure Python Vim clone

github.com

41–50 of 85 posts

Re: Pure Python Vim clone

#41
post #13

Q: Why Python? A: The only alternative would be Haskell, but I still have to learn that. Wow, that would be interesting.

Hi, I once tried that, but I ran into problems with lazyness. In particular my data structure was rather simple (famous gap data structure), but editing "large" files (>1000LOC) became rather unpleasant (too big input-feedback latency). However I managed to build a _very_ basic proof-of-concept editor (no dependencies) in just a few hundreds lines of code which I could explain, but until now I was too shy to share it…

> I was too shy to share it as it did not involve magic abstract Haskell-foo

Please don't be, simple understandable Haskell code is very nice :)

Plus if there is a better way of doing it you get to find that out too.

Re: Pure Python Vim clone

#43
post #21
post #9

My thought process upon seeing this: "Python, huh? Seems like typos in uncommon branches of the code would cause it to randomly fail at runtime, losing your work!" "Now evmar, don't be such a internet nay-sayer, plenty of people write reliable Python code. You just need tests and... yep, there's a tests directory right there in the repository." "Let's take a look. ...there's only one test!?" It looks pretty neat othe…

It's interesting that your first thought was to post a troll about how Python is a bad language.

I regret that this post is the top of the page. I failed to anticipate that people will take any opportunity to have yet another boring static typing debate.

But to be clear, in my day job I work on an app with 350k lines of Python in it and the reason I know it mostly works is due to our test coverage. As someone else mentioned in this thread, a lack of tests should not give you confidence regardless of the language.

Re: Pure Python Vim clone

#44
post #28

Earlier quoted context omitted.

print(arr[i]) Compiles, runs, fails if i is out of bounds. Which means that you need to test the code that you write, and that even if you have 100% line coverage (or branch coverage or MC/DC coverage or...), it doesn't mean i won't get the wrong value. People who claim that "once my C++/Haskell/Agda/whatever program compiles, I know it probably has no bugs" thus tempt others to mention "a false sense of security." (…

I've never seen anyone claim that types (even a very strong type system like Haskell or Rust) mean you don't have to write tests. They just mean you don't have to write the very silly tests you would otherwise have to to feel secure in a dynamically typed language.

In Rust you can use (wrt exhaustive match) and traits to a really great extent to provide safety.

Quite often I write some Rust code and know that it will work if it compiles (though I still write tests)

Re: Pure Python Vim clone

#45
post #28
post #23

Earlier quoted context omitted.

Can you elaborate?

print(arr[i]) Compiles, runs, fails if i is out of bounds. Which means that you need to test the code that you write, and that even if you have 100% line coverage (or branch coverage or MC/DC coverage or...), it doesn't mean i won't get the wrong value. People who claim that "once my C++/Haskell/Agda/whatever program compiles, I know it probably has no bugs" thus tempt others to mention "a false sense of security." (…

[deleted]

Re: Pure Python Vim clone

#47
Why not decouple the following things:

- Core editor (internal representation, etc.)

- Key bindings (so you could easily create an emacs instead of a vi)

- Rendering

- Scripting language (for customized behavior)

Finally, make sure you thoroughly document these building blocks, so others can create really cool stuff with it. Also, think of possible use-cases when defining the modules. A smart architecture could allow for a collaborative editor, for example.

Re: Pure Python Vim clone

#48
post #28

Earlier quoted context omitted.

print(arr[i]) Compiles, runs, fails if i is out of bounds. Which means that you need to test the code that you write, and that even if you have 100% line coverage (or branch coverage or MC/DC coverage or...), it doesn't mean i won't get the wrong value. People who claim that "once my C++/Haskell/Agda/whatever program compiles, I know it probably has no bugs" thus tempt others to mention "a false sense of security." (…

I've never seen anyone claim that types (even a very strong type system like Haskell or Rust) mean you don't have to write tests. They just mean you don't have to write the very silly tests you would otherwise have to to feel secure in a dynamically typed language.

I dunno. If you cover every source line at least once, that catches the dumb type errors as it does dumb bounds errors etc. If you don't have a test covering every source line at least once, then you will have dumb type errors as well as dumb bounds errors in those uncovered lines. So I don't think dynamic languages force you to write silly tests when you look at it that way.

If however you say, "hey, I seriously don't want to cover all the lines including say error messages", then in Python,

if error: print obj.name

...might be a problem because obj doesn't have a name; in C++,

if(error) cout ...might only blow up because obj is a null reference (which is what you get when you dereference the null pointer, in practice, even though null references aren't supposed to exist); and in a language with non-nullable pointers, the equivalent of the above can only blow up if printing the name (which is surely valid if obj is non-nullable and type-checks as having a name) somehow blows up, which for a string in a memory-safe language is very very unlikely.

So if you leave uncovered lines in your code which we all do then yes, the stricter the type system, the better your chances are, statistically, all else being equal (for instance, the number of lines being the same... which might not be the case.)

Overall the silly tests people sometimes write in dynamic languages are needless IMO and result from over-applying "TDD" or "unit testing" or some other buzzword and/or paranoia of someone coming from a statically typed language background. I personally think I have pretty much the same amount of tests regardless of the type system.

Re: Pure Python Vim clone

#49

Earlier quoted context omitted.

I am, right now, or at least two minutes ago before I started reading HN, refactoring big chunks of _my_ text editor, WordGrinder. It's a almost-pure-Lua word processor. In the process I have been writing unit tests. Previously the program didn't have any, which was really dumb. It was dumb because, in the three days I've spent doing this, I have found (and fixed) so, _so_ many bugs. And now I have a decent set of te…

Types. They Will Save You Tests™ :-)

I had actually gone and looked for Lua static type checkers. Some exist, but none that'll work with Lua 5.2.

I had a really hilarious bug today where under some circumstances all the text in the display would be replaced by numbers. Small integers, each placed where the word should be.

What had happened is that I'd added a layer of indirection; where previously, after line wrapping, the data structure for a rendered paragraph was an array of pointers to the word objects, now it was an array of indices into the paragraph's word array. And I'd forgotten about one particular exotic code path. Lua was seeing the array of indices, automatically casting the ints to strings, and then using those strings instead of the word data itself...

Static types would have made this bug impossible.

...way back when, there was a really nice and thoroughly obscure language called Strongtalk; it was a Smalltalk 80 clone with optional strict types. You could annotate your classes and methods with type information. If it was there, it would be checked; if it wasn't, you got the traditional behaviour. The JIT knew about the type information and could use it to produce really fast code. It combined the ultimate dynamic language with an expressive static type system (complete with parametric polymorphism).

It was open sourced in 2006 and sank without trace. Sigh.

Re: Pure Python Vim clone

#50

Earlier quoted context omitted.

I am, right now, or at least two minutes ago before I started reading HN, refactoring big chunks of _my_ text editor, WordGrinder. It's a almost-pure-Lua word processor. In the process I have been writing unit tests. Previously the program didn't have any, which was really dumb. It was dumb because, in the three days I've spent doing this, I have found (and fixed) so, _so_ many bugs. And now I have a decent set of te…

Types. They Will Save You Tests™ :-)

Here's some research on the topic, limited to just types- http://evanfarrer.blogspot.com/2012/06/unit-testing-isnt-eno...

Types are one mechanism for static analysis. Better contracts (nullability, valid ranges, etc) goes much further.

Post reply on HN