|
If there's a simple, obviously correct approach to a problem it's always a good idea to knock that up as a baseline before trying some sort of "clever" optimization, especially in a language like JavaScript which is interpreted and special-cased to hell by various JITs. Intuition for performance be very misleading in this type of runtime environment. JS has regexes as a first-class construct; in that language they should be preferred to ersatz charcode range checks until a performance shortfall is identified.
|
# ? Jun 1, 2016 19:30 |
|
|
# ? May 30, 2024 21:22 |
|
Absurd Alhazred posted:In Hebrew numbers are spoken LTR/big-endian, so it works out well for typing. I have just realized, though, that people using physical typewriters must have been writing numbers RTL/little-endian.That must have been an irritation, both getting used to it, and then getting used to the new way. Probably wasn't too big of a deal since with a typewriter you'd normally be just typing up something already written on paper, so you'd just have to get in the habit of mechanically translating the things on paper without thinking about them too much (which was useful anyway).
|
# ? Jun 1, 2016 21:01 |
|
They probably avoided it, the only typewritten Hebrew document with numerals I can find on GIS has them in the header as a date, and it looks LTR. https://imgur.com/GTVPG1E Linear Zoetrope fucked around with this message at 21:27 on Jun 1, 2016 |
# ? Jun 1, 2016 21:22 |
|
Jsor posted:They probably avoided it, the only typewritten Hebrew document with numerals I can find on GIS has them in the header as a date, and it looks LTR. Where did you find a letter from Ben Gurion to Aba Hushi talking about expropriating an old Arab technical school for Air Force use during the War of Independence/Nakba? Here's a letter from 1957 with inline numbers. It was either typed little-endian RTL or big endian LTR after creating an appropriate space. The latter seems unnecessarily complicated, though.
|
# ? Jun 2, 2016 04:06 |
|
If I had my way numbers would be typed little-endian LTR.
|
# ? Jun 2, 2016 04:43 |
|
Hammerite posted:I was going to say that he says that about regex, but then doesn't actually use regex as part of his model solution. But technically, he does - he uses it to filter out non-letter characters before he gets to the actual work of determining if it's a palindrome. I guess that's all he meant by "use regex as part of the solution". It's poor communication on his part, because he's unnecessarily drawing attention to a relatively unimportant preparatory step, which misleads the reader into thinking that the use of regex will be the meat of the solution. All round a fairly dubious article. On the other hand, if someone can write a regex that matches palindromes, they definitely get the job.
|
# ? Jun 2, 2016 06:16 |
|
KernelSlanders posted:On the other hand, if someone can write a regex that matches palindromes, they definitely get the job. Someone did on the last page I think, using nonstandard Perl stuff. I don't agree by the way. I don't want someone working with me who routinely uses the wrong tool for the job, even if they use that tool really well.
|
# ? Jun 2, 2016 09:25 |
|
Found today in maths code that's been around and in use for years.code:
|
# ? Jun 2, 2016 10:27 |
|
I've sorted through the unicode data in order to generate a long list of range comparisons for the letter character classes, but in .net using compiled regex with \p was nearly just as fast. Fast enough to regret making a parser for all of that unicode data. If you only want latin letters though, it is silly to not just compare ranges.
|
# ? Jun 2, 2016 10:29 |
|
Hammerite posted:Someone did on the last page I think, using nonstandard Perl stuff. I would hire that person since palindromes are not regular. They're context-free. It's not so much using the wrong tool as it is using a tool for which it is literally impossible to solve the problem and then solving it anyway.
|
# ? Jun 2, 2016 14:55 |
|
I wouldn't hire them because I don't want co-workers that produce unintelligible gibberish because it's a fun challenge. I'd hire the guy that does it in two pages of bash with an easy to read flow so it can be modified in two years when customer requirements change.
|
# ? Jun 2, 2016 15:00 |
|
I think disproving a basic result in computer science and upending the entire field is more important than readable code.
|
# ? Jun 2, 2016 15:06 |
|
Hammerite posted:Found today in maths code that's been around and in use for years. I don't know if I either hate or love this.
|
# ? Jun 2, 2016 15:11 |
|
Dr. Stab posted:I think disproving a basic result in computer science and upending the entire field is more important than readable code. The term "regular expression" as used by practicing software developers encompasses not only actual regular expressions as defined in the literature, but various extensions of the concept as used in this or that language (e.g. Perl, which was mentioned). Notwithstanding the impossibility of solving the palindrome problem with regular expressions per se, it is possible (but not a good idea, if you want maintainable code) to solve it with regular expressions per the second meaning of the term. An example was given in the thread, as I observed (I haven't checked its accuracy). Moreover, saying "if person did something impossible, I would hire them" is vacuously true; if person did something impossible, then I would hire them too, and build them a mansion on the moon, with a chocolate milk swimming pool and a lollipop orchard.
|
# ? Jun 2, 2016 15:14 |
|
Dr. Stab posted:I would hire that person since palindromes are not regular. They're context-free. It's not so much using the wrong tool as it is using a tool for which it is literally impossible to solve the problem and then solving it anyway. Some regex implementations aren't regular either. I think that .NET has a special capture group that acts like a stack. It's something like every time it matches the group, it pushes the capture onto a stack. Every time it encounters a back reference to the group, it matches against the top of the stack and then pops it.
|
# ? Jun 2, 2016 15:20 |
|
Hammerite posted:Found today in maths code that's been around and in use for years. Color me unsurprised. Presumably the second letter of each variable name here should be read as a subscript, making this code look like the mathematician's proof when they sketched out the algorithm in the first place.
|
# ? Jun 2, 2016 15:36 |
|
That's not the "horror" part.
|
# ? Jun 2, 2016 15:46 |
|
Hammerite posted:Found today in maths code that's been around and in use for years. Works well enough except when it doesn't for mysterious reasons. But seriously, it's nice to see a perfect example of why you should always wrap your branches in {} even when one of them is just one statement. I mean, unless this thing actually has the intended behavior in which case track down whoever is responsible for this indentation and kill them.
|
# ? Jun 2, 2016 15:48 |
|
1337JiveTurkey posted:Some regex implementations aren't regular either. I think that .NET has a special capture group that acts like a stack. It's something like every time it matches the group, it pushes the capture onto a stack. Every time it encounters a back reference to the group, it matches against the top of the stack and then pops it. "Yes, Virginia, you can parse HTML using regular expressions."
|
# ? Jun 2, 2016 16:00 |
|
CPColin posted:That's not the "horror" part. Oh right, sorry. Still waking up here. Yeah, this is why if you don't put curly braces on every loving control flow statement, your code has a bug.
|
# ? Jun 2, 2016 16:07 |
|
YeOldeButchere posted:But seriously, it's nice to see a perfect example of why you should always wrap your branches in {} even when one of them is just one statement. I'm sure I'm about to become the thread pariah, but I don't always wrap my single line if statements. And I almost never do so for early return or throwing exceptions. I've never once run into an issue like this. Granted, I also don't cram multiple statements into one line and my editor is good about automatic indentation so this type of mistake is easy to catch.
|
# ? Jun 2, 2016 16:09 |
|
Are you also good about making sure all your merges worked correctly?
|
# ? Jun 2, 2016 16:11 |
|
If I were in charge then control flow statements without braces would be a syntax error
|
# ? Jun 2, 2016 16:11 |
|
I wouldn't be surprised to find that there's some optional warning that can be enabled in gcc or clang to warn you if you have multiple statements on one line after an if/else, if not enforce mandatory braces outright.
|
# ? Jun 2, 2016 16:15 |
|
Congratulations, you work on the Swift team apparently.
|
# ? Jun 2, 2016 16:16 |
|
Should use the comma operator.code:
|
# ? Jun 2, 2016 16:19 |
|
YeOldeButchere posted:I wouldn't be surprised to find that there's some optional warning that can be enabled in gcc or clang to warn you if you have multiple statements on one line after an if/else, if not enforce mandatory braces outright. There sure is: https://www.phoronix.com/scan.php?page=news_item&px=GCC6-Misleading-Indentation
|
# ? Jun 2, 2016 16:23 |
|
Bognar posted:There sure is: https://www.phoronix.com/scan.php?page=news_item&px=GCC6-Misleading-Indentation This warning was only added this year. The mind boggles.
|
# ? Jun 2, 2016 17:11 |
|
TooMuchAbstraction posted:Oh right, sorry. Still waking up here. Yeah, this is why if you don't put curly braces on every loving control flow statement, your code has a bug. you know what I hate? languages that don't have curly braces. in vb, you do this: Visual Basic .NET code:
Also, because we use the ancient and terrible vb6 compiler, there is no highlighting of matching ifs/endifs like you'd get for braces in a modern IDE. Additionally, if a compile/run fails because of an unterminated If or an End If without an opening If, the editor will not bring you to or in any way indicate which line the error is on. Consequently it has become standard practice to verify your indentation and If structures by pasting your code into notepad++, whose syntax highlighting for VB will show you both of these errors. I long for death.
|
# ? Jun 2, 2016 21:04 |
|
LeftistMuslimObama posted:you know what I hate? languages that don't have curly braces. in vb, you do this: VB is horrid and you should move to c# with all possible and prudent haste. And we should never talk about VB again.
|
# ? Jun 2, 2016 22:45 |
|
Bognar posted:I'm sure I'm about to become the thread pariah, but I don't always wrap my single line if statements. And I almost never do so for early return or throwing exceptions. I've never once run into an issue like this. Why? I'm not asking this question to you specifically; just to the universe. Why are an opening and closing brace so aesthetically objectionable that we would rather risk these kinds of bugs? Excluding the braces offers almost no practical value, but here we are.
|
# ? Jun 3, 2016 01:48 |
|
The real question is are you a method/for/if{ } or method/for/if { } kind of person. I'm the latter, as God intended.
|
# ? Jun 3, 2016 01:53 |
|
with the second one im like "why even have an openning brace, just say that an empty line following a function declaration opens a block
|
# ? Jun 3, 2016 01:57 |
LeftistMuslimObama posted:you know what I hate? languages that don't have curly braces. MUMPS is non-curly-brace, right?
|
|
# ? Jun 3, 2016 02:53 |
|
VikingofRock posted:MUMPS is non-curly-brace, right? Should have vaccinated.
|
# ? Jun 3, 2016 03:02 |
|
VikingofRock posted:MUMPS is non-curly-brace, right? Yes, but mumps is actually better than vb here because each indentation level is marked by the number of '.' characters at the beginning of the line so it's completely unambiguous what scope each line is in: code:
|
# ? Jun 3, 2016 04:01 |
|
EmmyOk posted:The real question is are you a Ha ha same. Although most styles seem to support the first one (like the documentation for Java & C#). For one small project I was working on I decided to try out variables [N/n]amed_Like_This and I sadly I found out I prefer that too. I honestly thought it was obnoxious until I went back to camelCase and noticed longer variable names were harder to read. I try not to mention it in casual conversation though.
|
# ? Jun 3, 2016 04:07 |
|
Nude posted:Ha ha same. Although most styles seem to support the first one (like the documentation for Java & C#). For one small project I was working on I decided to try out variables [N/n]amed_Like_This and I sadly I found out I prefer that too. I honestly thought it was obnoxious until I went back to camelCase and noticed longer variable names were harder to read. I usually see camel case for variables and underscores for constants or typedefs.
|
# ? Jun 3, 2016 04:10 |
|
LeftistMuslimObama posted:you know what I hate? languages that don't have curly braces. in vb, you do this: I don't know this particular language, but "Else If" seems to already have a meaning. It's an else block where the first statement is an If. This isn't a problem in cool normal people languages, where you can say code:
code:
code:
|
# ? Jun 3, 2016 05:42 |
|
|
# ? May 30, 2024 21:22 |
|
EmmyOk posted:The real question is are you a The brace goes on the next line for declarations, and on the same line for control constructs. This isn't hard folks and I don't know why so many people get it wrong.
|
# ? Jun 3, 2016 07:48 |