Live data from Hacker News

How I fixed a bug in Atom

davidvgalbraith.com

101–110 of 189 posts

Re: How I fixed a bug in Atom

#101
post #81

Earlier quoted context omitted.

I've never used a language mode that worked properly in all cases. That's why I've stopped using them, aside from very clever and extraordinarily useful ones like paredit. It terrifies me to think about how these language modes contain regexps for matching regexp syntax. Of course those are wrong.

> I've never used a language mode that worked properly in all cases. You need a full parser for that to happen, most mode authors don't bother[0]. JS2-mode ( https://github.com/mooz/js2-mode/ ) does that (or attempts to). Most syntactic colorisers are souped-up tokenisers, not actual parsers. It suffices in 99% of cases, but breaks badly elsewhere. [0] it would help if more languages made fast parsing machinery exter…

[0] - typescript does this I believe

Re: How I fixed a bug in Atom

#102

I am still unsure why anyone uses Atom when it consumes so many resources. The emacs instance I have had open for some time now is using 92Mb. Atom instances have been reported in the hundreds of megabytes [1]. Of course, this is because it is actually a web application running in an entire browser, renderer and helper processes included. I understand the need for people to be able to "easily" hack on it (easily in q…

If you care about resources then you should really be using ed[1], not emacs.

"easily in quotes here because really that just means "people who know web languages""

It's my go-to editor/IDE for Rust, which is far from a web language.

"that goal could still be accomplished in a native application that embedded a JS runtime for plugins"

Kind of like Chromium with V8? With full hardware/OS access and linking to native code? If only such a thing existed.

[1]:http://www.gnu.org/fun/jokes/ed-msg.html

Re: How I fixed a bug in Atom

#103
post #27

Earlier quoted context omitted.

The support of fancy features like backtracking does not cause any degradation of performance for simple regular expressions. You are not obliged to use them, but they do not hurt you when you do not use them. Some other people may love them despite their poor complexity.

Actually, this is false. A lot of regex implementations use a backtracking approach in all cases, causing pathological behavior even on regexes which match a regular language (and so should never take any significant amount of time to process). See https://swtch.com/~rsc/regexp/regexp1.html , which gives a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa (see the backtracking?…

> (see the backtracking? me neither)

If I understand the article correctly, the Perl regex evaluator, if given a string consisting of only the minimum required number of 'a's, first matches them to the optional 'a's, and then has to backtrack to match the required 'a's.

Re: How I fixed a bug in Atom

#104
post #99
post #82

Earlier quoted context omitted.

With anything less than a full-featured lexer and parser of the latest edition of the language in question, I'd say. Including understanding of whatever metaprogramming features or preprocessors that are in play.

It's even more than full-featured for a code editor, really, you really want a language parser that can more gracefully handle partial statements than even the core language parser itself can handle. von Neumann help you if your language was complicated to parse even before you added that requirement.

Visual Studio doesn't even do a full-blown AST - even though it has a full-blown internal parser. It frequently messes up auto-indenting when using macros involving blocks.

Lexing and producing tokens with a loop is probably enough given that auto-indentation works on a subset of states of the parser, if any. As my comment alluded to, using regex is harder to both write and read than a simple loop; it's also most likely slower.

Re: How I fixed a bug in Atom

#105
post #81

Earlier quoted context omitted.

I've never used a language mode that worked properly in all cases. That's why I've stopped using them, aside from very clever and extraordinarily useful ones like paredit. It terrifies me to think about how these language modes contain regexps for matching regexp syntax. Of course those are wrong.

> I've never used a language mode that worked properly in all cases. You need a full parser for that to happen, most mode authors don't bother[0]. JS2-mode ( https://github.com/mooz/js2-mode/ ) does that (or attempts to). Most syntactic colorisers are souped-up tokenisers, not actual parsers. It suffices in 99% of cases, but breaks badly elsewhere. [0] it would help if more languages made fast parsing machinery exter…

Does Atom have an API for syntax highlighting with full parsers? I'm pretty sure it only supports bix trees of regexes for that.

Re: How I fixed a bug in Atom

#106
post #76

Earlier quoted context omitted.

> Constructing the minimal DFA for a given NFA is PSPACE-hard. This isn't really a problem if you incur that cost only once by having the regex compiled when the script is parsed. However, idiomatic JS usually includes regex literals in the closure where it is used - decreasing performance, code reuse and clarity. Why? Probably for the same reasons that regex is being used in the first place.

Well, PSPACE-hard is pretty damn hard, so this really depends on the size and complexity of your NFA ;) Of course most of the time you don't hit the pathological cases like the one I described above. My comment was not meant to provide a guideline on how to fix this, consider it a fun observation on automata theory.

Indeed. What I failed to communicate was that there is no reason to incur that cost multiple times per process/application. For some reason idiomatic JS encourages incurring that cost multiple times. Your comment shows that this idiomatic form is even more absurd than I originally thought.

Re: How I fixed a bug in Atom

#107
post #11

I got to the bottom and couldn't believe that the solution chosen was to modify the regexp instead of use a for loop. He did such a great job explaining that the code is really just trying to count the number of parentheses or braces to see if they're imbalanced, that it felt the next step was "so I wrote a really simple set of loops that is fast enough on short strings and way less crazy otherwise".

  Some people, when confronted with a problem,
  think "I know, I'll use regular expressions."
  Now they have two problems.
  - Jamie Zawinski

Re: How I fixed a bug in Atom

#108
post #58

Performance wise I never understood why ATOM is even used. it is lackluster compared to a notepad++ and there is a delay in every action: loading the software, clicking on a tab, on a menu, on an option. it seems to me like a very wrong idea to push the web into softwares

Totally agree. The performance is atrocious. Most plugins don't work. It can't handle files bigger than a few hundred lines. Update fails often requiring a reinstall. It's such garbage, I don't even have it installed anymore. I thought it'd compete with Sublime. Was I ever wrong! It doesn't compete with TextPad or Notepad, let alone Sublime. I couldn't find a single redeeming feature.

Re: How I fixed a bug in Atom

#109
post #45

Earlier quoted context omitted.

Same here. Also, I don't use Atom, but looking at the expression I'm pretty sure it fails to account for strings with parentheses. The way the matching is done, it looks like it will happily count: func("some call :)") as extra closing paren. (regex101 agrees)

Sometimes I feel like the difference between a junior, intermediate, and senior developers is that the junior hasn't yet figured out how to use regexps, the intermediate dev has, and the senior dev has figured out not to. I kid, but...really. The number of times I've seen people burnt by non-trivial regexps in production code is absurd. "Oh, I need to mangle this CSV that's in the wrong format"? Sure, write a one-off…

[deleted]

Re: How I fixed a bug in Atom

#110
In general, when you are working on a problem and you think "let me use a regex for that" and then you come up with

    ^\s*[^\s()}]+(?[^()]*\((?:\g|[^()]*)\)[^()]*)*[^()]*\)[,]?$
to solve your problem, then you have IMHO come across a problem which you should not be solving using regular expressions.

Case in point is counting and balancing parentheses which is very easily done using a single loop over the string in question.

Post reply on HN