3 ms·
For my use cases, the vast majority of errors with dynamic languages boil down to being able to run scripts that have undefined variables; I'm prone to (mental)
by chousuke 6y ago
For my use cases, the vast majority of errors with dynamic languages boil down to being able to run scripts that have undefined variables; I'm prone to (mental) typos, so if I had a dialect of Python that failed before runtime when undeclared references exist, I could probably cut the number of iterations I need to arrive at a working script by at least half.
I've never found a valid use case for allowing undefined references, though I suppose it does make the language implementation significantly easier.
Writing tests is not really a solution either. Tests are also code and suffer from the same problem.
- christophilus 6y agoAt least in JavaScript, these are flagged by a linter. I imagine Python has a decent linter and code editor integration of said linter?
- petters 6y agopyflakes finds these. It has virtually 0% false positives and runs extremely quickly. Run it on save or in a git commit hook. (I agree that they should be a syntax error though)
- samanator 6y agoWould be very difficult (or impossible) to make this a syntax error since exec() Modifies the global scope
- samanator 6y agoPycharm warns you when that happens. I'm guessing they are using a combination of the abc module (to parse the abstract syntax tree) and some linter that can be found on pypi. Would a validator that runs before your main python executable solve your problem?
- samanator 6y agoOops I meant the ast module, not the abc module
- knocte 6y agoJust make the jump for once: https://github.com/knocte/2fsharp/blob/master/python2fsharp.md https://github.com/knocte/2fsharp/blob/master/python2fsharp.... (yes you can write scripts with this language).
- chousuke 6y agoI most often choose Python because it's what's available, and it's good enough for the things I need to use it for. Other people can generally understand my code, too. F# probably is a good language, but I haven't had a good enough reason to use it.