Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
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.

Adbot
ADBOT LOVES YOU

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

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).

Linear Zoetrope
Nov 28, 2011

A hero must cook
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

Absurd Alhazred
Mar 27, 2010

by Athanatos

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.

https://imgur.com/GTVPG1E

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? :psyduck:

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.

sarehu
Apr 20, 2007

(call/cc call/cc)
If I had my way numbers would be typed little-endian LTR.

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.

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.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

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.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Found today in maths code that's been around and in use for years.

code:
if (dt<dc)
{
	ar=ac; ac=at;
	dr=dc; dc=dt;
}
else
	al=at; dl=dt;

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
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.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Hammerite posted:

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.

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.

xzzy
Mar 5, 2009

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.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
I think disproving a basic result in computer science and upending the entire field is more important than readable code.

Space Kablooey
May 6, 2009


Hammerite posted:

Found today in maths code that's been around and in use for years.

code:
if (dt<dc)
{
	ar=ac; ac=at;
	dr=dc; dc=dt;
}
else
	al=at; dl=dt;

I don't know if I either hate or love this.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

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.

1337JiveTurkey
Feb 17, 2005

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.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Hammerite posted:

Found today in maths code that's been around and in use for years.

code:
if (dt<dc)
{
	ar=ac; ac=at;
	dr=dc; dc=dt;
}
else
	al=at; dl=dt;

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.

CPColin
Sep 9, 2003

Big ol' smile.
That's not the "horror" part.

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal

Hammerite posted:

Found today in maths code that's been around and in use for years.

code:
if (dt<dc)
{
	ar=ac; ac=at;
	dr=dc; dc=dt;
}
else
	al=at; dl=dt;

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.

qntm
Jun 17, 2009

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."

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

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.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

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.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Are you also good about making sure all your merges worked correctly?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
If I were in charge then control flow statements without braces would be a syntax error

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal
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.

brap
Aug 23, 2004

Grimey Drawer
Congratulations, you work on the Swift team apparently.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Should use the comma operator.

code:
if (dt<dc)
{
	ar=ac, ac=at;
	dr=dc, dc=dt;
}
else
	al=at, dl=dt;

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

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

qntm
Jun 17, 2009

This warning was only added this year. The mind boggles.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

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:
If Cond Then
    Call MsgBox("Hello!")
ElseIf OtherCond
     Call MsgBox("Goodbye!")
Else
     Call MsgBox("Default!")
End If
Yes ElseIf is one word while End If is two. I can't find any reasoning to this because both Else and End are keywords that can be used with other structures (like selects, fors, dos, etc) so there's no reason other than a lazy parser writer to do that.

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.

Dirty Frank
Jul 8, 2004

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.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

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.

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.

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.

EmmyOk
Aug 11, 2013

The real question is are you a

method/for/if{
}

or

method/for/if
{
}

kind of person. I'm the latter, as God intended.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
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

VikingofRock
Aug 24, 2008




LeftistMuslimObama posted:

you know what I hate? languages that don't have curly braces.

MUMPS is non-curly-brace, right?

Absurd Alhazred
Mar 27, 2010

by Athanatos

VikingofRock posted:

MUMPS is non-curly-brace, right?

Should have vaccinated. :smith:

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

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:

i cond d  i 1
. i cond2 d
.. w "hi" 
. e w "ho" 
e w "bye" 

Nude
Nov 16, 2014

I have no idea what I'm doing.

EmmyOk posted:

The real question is are you a

method/for/if{
}

or

method/for/if
{
}

kind of person. I'm the latter, as God intended.

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.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

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 try not to mention it in casual conversation though.

I usually see camel case for variables and underscores for constants or typedefs.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

LeftistMuslimObama posted:

you know what I hate? languages that don't have curly braces. in vb, you do this:

Visual Basic .NET code:
If Cond Then
    Call MsgBox("Hello!")
ElseIf OtherCond
     Call MsgBox("Goodbye!")
Else
     Call MsgBox("Default!")
End If
Yes ElseIf is one word while End If is two. I can't find any reasoning to this because both Else and End are keywords that can be used with other structures (like selects, fors, dos, etc) so there's no reason other than a lazy parser writer to do that.

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:
if(x) {
    a
}
else if (y) {
    b
}
which has the same meaning as
code:
if(x) {
    a
}
else {
    if (y) {
        b
    }
}
And the construction works fine. but because of how blocks are delineated in this language, you would have to say
code:
If x Then
    a
Else If y Then
        b
    End If
End If
Which isn't fun, so they invented an ElseIf keyword.

Adbot
ADBOT LOVES YOU

Soricidus
Oct 21, 2010
freedom-hating statist shill

EmmyOk posted:

The real question is are you a

method/for/if{
}

or

method/for/if
{
}

kind of person. I'm the latter, as God intended.

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.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply