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
qntm
Jun 17, 2009
Haskellers seem to manage.

Adbot
ADBOT LOVES YOU

Polio Vax Scene
Apr 5, 2009



Make all the text boxes visible so he can recreate the Matrix

KaneTW
Dec 2, 2011

qntm posted:

Haskellers seem to manage.

Bindings are just immutable variables

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

hackbunny posted:

Using the _ line continuation you mean?

Yep. You can only get 3 lines into a method signature that way, so if you're writing abominations you'll still end up with hella long lines.

Rectus
Apr 27, 2008

invision posted:

Overheard at work today:

"Yeah, I'd love to be able to use your code. I'm just not very good at programming, you know? Hell, like 3 hours ago I discovered how to use variables. I've been making an invisible form with a bunch of text boxes on it and using those to keep data around."

...and sure enough, he opens up msvs and shows me his hidden form with like 800000 text boxes on it.
e:dude's been writing code for at least 3 years.

Oh hey, I did that in Visual Basic when I was like 5. It's a lot easier to grasp manipulating data with GUI elements when everything related to it is nicely laid out in the IDE, and you don't understand what classes or members are.

canis minor
May 4, 2011

HardDisk posted:

Just how do you program without using variables?

From what I imagine, he's been doing it the same way as you'd create mockups in uxpin - user clicks here, show this container, etc.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
It could be worse; he said he'd just discovered variables and it was a pleasant surprise. He might have reacted with "bah, I have a system that works fine already". That's a worse kind of situation entirely.

SiliconCactus
Oct 21, 2009

Bognar posted:

C# code:
public class MyModelClassThatIsSavedToTheDatabase
{
    private void UpdateExpectedTime()
    {
        using (var db = new DbContext())
        {
            var newExpectedTime = // do some date math here, query DB twice
            ExpectedTime = newExpectedTime;
        }
    }
}
A private method that updates a time based on some values queried from the database? Ok, kind of annoying but whatever. Let's see, where is this called?

C# code:
private string _status;
public string Status
{
    get { return _status; }
    set
    {
        _status = value;
        UpdateExpectedTime();
    }
}

// 3 other god drat properties with the same thing
Oh, it's called in the setter. So every time I set one of these commonly used properties, we make 2 round trips to the database. Awesome.

But wait, what else calls those setters? Of course, the ORM does anytime it's trying to deserialize this object from the database. So if I load this object from the database even once, four properties are calling UpdateExpectedTime which makes 2 database calls, so eight in total just for loading the object. Even better, if I load a list of 100 of these objects in one DB call (as is done all over this drat application), we now make 800 more DB calls. And people wonder why this system is slow.

I got that beat. Try debugging code where merely accessing a property causes other properties to mutate. After an hour of banging my head on the wall I found it.
C# code:
private string someProperty = "";
public string SomePropertyName { 
                         get{ this.OtherUnrelatedProperty = "other value"; 
                                 this.IntNotRelated = 0; 
                                 return someProperty;}
                         set{someProperty = value;}}
Yes, because that's reasonable. In a readmodel class, consumed by a traditional razor view. So much badness. :/

Karate Bastard
Jul 31, 2007

Soiled Meat
Brings Kirk to mind for some reason.

Chill Callahan
Nov 14, 2012

HardDisk posted:

Just how do you program without using variables?

Very carefully

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Memory allocation is a side effect.

Vanadium
Jan 8, 2005

We have Delphi forms at work that have "query" components splattered all over them because since those are available as a drag+drop component, it's apparently bad form to query the db without having one or thirty clearly visible in the form designer. Like, we're all aware of variables but I guess we don't really trust them to hold objects.

loinburger
Jul 10, 2004
Sweet Sauce Jones
Joy, my co-worker submitted a pull request that includes a "SemaphoreService." This doesn't sound good
code:
@Component
@Scope(value = "singleton")
public class SemaphoreService {
    private static final Semaphore flagSem = new Semaphore(1, true);
    private static final Semaphore clearSem = new Semaphore(1, true);
    private static final Semaphore loadSem = new Semaphore(1, true);
    private static final Semaphore storeSem = new Semaphore(1, true);
    private static final Semaphore updateSem = new Semaphore(1, true);

    public Semaphore getFlagSem() { return flagSem; }
    public Semaphore getClearSem() { return clearSem; }
    public Semaphore getLoadSem() { return loadSem; }
    public Semaphore getStoreSem() { return storeSem; }
    public Semaphore getUpdateSem() { return updateSem; }
}
For gently caress's sake. The icing on the cake is that he always uses "Semaphore#acquireUninterruptibly" just to make it all the more difficult to figure out where the inevitable deadlocks are occurring.

Edit: We don't even need these stupid locks - we could get rid of this entire service and replace it with properly encapsulated AtomicBooleans. I added this comment to the pull request, but I predict that my lazy boss is just going to merge this lovely code anyway. Hopefully I'll have found another job by the time this bites us in the rear end.

loinburger fucked around with this message at 02:14 on Dec 12, 2015

brap
Aug 23, 2004

Grimey Drawer
Lol that he named it a "service" instead of a "pile of globals"

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal

fleshweasel posted:

Lol that he named it a "service" instead of a "pile of globals"

The technical term is singleton.

xzzy
Mar 5, 2009

I prefer simpleton.

Oh, you mean the code.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

fleshweasel posted:

Lol that he named it a "service" instead of a "pile of globals"

/service/dicksucker/gi and watch your codebase become more entertaining.

Carbon dioxide
Oct 9, 2012

Not sure what this is but it certainly looks ugly

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

looks like machine obfuscated code.

Winter Stormer
Oct 17, 2012

Carbon dioxide posted:

Not sure what this is but it certainly looks ugly



It appears to be a photo of a screen

xzzy
Mar 5, 2009

I can tell from the pixels and from seeing a lot of pixels in my time.

baquerd
Jul 2, 2007

by FactsAreUseless

Carbon dioxide posted:

Not sure what this is but it certainly looks ugly



That thar appears to be Javascript.

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

baquerd posted:

That thar appears to be Javascript.

Point stands, then?

Karate Bastard
Jul 31, 2007

Soiled Meat
Well how about that, that's exactly what I said at work today: "this [_0x5b14[0]] function!" I said, over and over again, for hours (or some minor variations thereof).

Mr Shiny Pants
Nov 12, 2012

HardDisk posted:

Just how do you program without using variables?

They call it functional programming. :)

Pythagoras a trois
Feb 19, 2004

I have a lot of points to make and I will make them later.
I always considered wild sed|awk|greg chains to be programming without variables. The stream don't stop for readability

Karate Bastard
Jul 31, 2007

Soiled Meat
Lol if you don't have Greg do all work for you.

Impotence
Nov 8, 2010
Lipstick Apathy

Carbon dioxide posted:

Not sure what this is but it certainly looks ugly



code:
var _0x5b14=["\x7a\x32\x66\x37\x31\x62\x34\x34\x64\x62\x32","\x47\x65\x74\x43\x6f\x75\x6e\x74",
"","\x69\x6e\x74\x65\x67\x72\x61\x74\x65\x64\x20\x63\x69\x72\x63\x75\x69\x74"]

var _0x5b14 = ["z2f71b44db2", "GetCount", "", "integrated circuit"]


zc1c28ca67f(param) -> z2f71b44db2(param2) increments var i=0; and alerts param+param2
zc1c28ca67f(param) -> getCount() returns i

(i here is _0x3f02x3)

obj = new zc1c28ca67f("") with empty param1
last line calls obj[z2f71b44db]("integrated circuit");
it's run through javascriptobfuscator.com/Javascript-Obfuscator.aspx, something i'd recognise anywhere

Impotence fucked around with this message at 21:43 on Dec 15, 2015

pr0k
Jan 16, 2001

"Well if it's gonna be
that kind of party..."
Saw this. It's art. Sorry if it's a repost, I just saw it.


http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags

Linear Zoetrope
Nov 28, 2011

A hero must cook
I still think almost everybody on that page misunderstood the actual question. The asker wasn't trying to parse HTML with a regex, they were trying to recognize HTML tags. They essentially wanted a lexer, which would be a first pass towards implementing a parser. You pretty much need a tokenizer that does exactly what that question was asking for to implement a real HTML parser. Doing that was actually the first project in my compilers course when I took it.

Edit:

Such a thing would be used to transform something like

code:
<html>
<head>Some text</head>
<body>More text</body>
</html>
to

code:
HTMLOPEN HEADOPEN TEXT HEADCLOSE BODYOPEN TEXT BODYCLOSE HTMLCLOSE
Which would then be further processed with some sort of BNF parser or something.

In their case, it looks like they weren't discriminating between specific tags, so it would be transformed into

code:
TAGOPEN TAGOPEN TEXT TAGCLOSE TAGOPEN TEXT TAGCLOSE TAGCLOSE
but the same principle applies.

Linear Zoetrope fucked around with this message at 05:46 on Dec 17, 2015

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
I agree. Every time that's linked, I'm just bemused by how quickly stackoverflow's nerdlords sprang to win e-peen by totally misconstruing his question so they can score sick meme slamdunks. The guy just wanted to recognize HTML tags, which is totally possible with a regex, not parse and interpret them. There's lots of ways to write a regex that will match <STUFF HERE> but not <STUFF HERE/>

vOv
Feb 8, 2014

But you don't need to escape <> in an attribute value, so this is perfectly legal (paste it into the W3 validator if you want):

code:
<!DOCTYPE html>
<title>something</title>
<body>
<div id="/><nope>"></div>
</body>
And of course any simple regex solution will match tags inside comments or JS.

vOv fucked around with this message at 06:36 on Dec 17, 2015

Linear Zoetrope
Nov 28, 2011

A hero must cook

vOv posted:

But you don't need to escape <> in an attribute value, so this is perfectly legal (paste it into the W3 validator if you want):

code:
<!DOCTYPE html>
<title>something</title>
<body>
<div id="/><nope>"></div>
</body>
And of course any simple regex solution will match tags inside comments or JS.

Which is why most lexers are implemented in an alternate syntax where you define a separate regex for each token, and match most-greedy-first (so comments will always consume actual tags)*, since it makes individual regexes less complex because you no longer need to worry about explicitly guarding against comments. But in principle you should still be able to match any single token with a regex (or whatever superset of DFAs modern regexes operate off of).

E: Also, the < and > in quotes isn't really a huge issue, it's definitely something a real answer to that SO question should have mentioned, though!

* The flex syntax for matching multi-line C comments is actually pretty impressive, since you get to define your own embedded mini-FSM, but I can't recall it off the top of my head.

Linear Zoetrope fucked around with this message at 08:41 on Dec 17, 2015

Blue Footed Booby
Oct 4, 2006

got those happy feet

Jsor posted:

I still think almost everybody on that page misunderstood the actual question. The asker wasn't trying to parse HTML with a regex, they were trying to recognize HTML tags. They essentially wanted a lexer, which would be a first pass towards implementing a parser. You pretty much need a tokenizer that does exactly what that question was asking for to implement a real HTML parser. Doing that was actually the first project in my compilers course when I took it.

Edit:

Such a thing would be used to transform something like

code:
<html>
<head>Some text</head>
<body>More text</body>
</html>
to

code:
HTMLOPEN HEADOPEN TEXT HEADCLOSE BODYOPEN TEXT BODYCLOSE HTMLCLOSE
Which would then be further processed with some sort of BNF parser or something.

In their case, it looks like they weren't discriminating between specific tags, so it would be transformed into

code:
TAGOPEN TAGOPEN TEXT TAGCLOSE TAGOPEN TEXT TAGCLOSE TAGCLOSE
but the same principle applies.

If they misunderstood the question, it is because the question they think is being asked is asked with regularity.

I really don't think they misunderstood the question. I feel like if the OP were working on a tokenizer for a parser they would have anticipated the response and given some explicit indication of that. Or, y'know, responded to some of the people who answered to say "you guys misunderstood."

pr0k
Jan 16, 2001

"Well if it's gonna be
that kind of party..."
It's still funny, sperglords. :/

Volte
Oct 4, 2004

woosh woosh

Blue Footed Booby posted:

If they misunderstood the question, it is because the question they think is being asked is asked with regularity.

I really don't think they misunderstood the question. I feel like if the OP were working on a tokenizer for a parser they would have anticipated the response and given some explicit indication of that. Or, y'know, responded to some of the people who answered to say "you guys misunderstood."
They definitely did misunderstand the question. You can tell by reading the question, followed by reading the responses, which are to a completely different question. If you're assuming the OP meant to ask a different question, then that's the whole reason asking questions on SO is an infuriating proposition. Getting XY-problem'd when you---believe it or not---actually know what you're doing (and nobody else does) is a great way to waste an afternoon.

canis minor
May 4, 2011

Try posting a question on SO that contains any references to HTML and regexp in any context - one of the respondents will link that exact answer.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

canis minor posted:

Try posting a question on SO that contains any references to HTML and regexp in any context - one of the respondents will link that exact answer.

Good.

Regex and HTML: Just don't do it.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

canis minor posted:

Try posting a question on SO that contains any references to HTML and regexp in any context - one of the respondents will link that exact answer.

Exactly. It's a meme at this point and those dorks were falling all over themselves to pile on. I saw a chart of SO answers once (it was on some webcomic), where they basically categorized SO answers into something like:
1% - Correct answer, conveyed in language so detailed and jargony that only the answerer actually understands it.
.1% - Correct answer usable by anyone
50% - Honest attempts to answer the question, but wrong in subtle ways or misunderstanding the question subtly
48.9% - Trolls, jokes, and idiots repeating blog posts about hawt programming opinions or the coolest new library of the week

Adbot
ADBOT LOVES YOU

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
My favorite SO moment was when I answered a question and someone commented on it "no ur wrong"... when the question was about the product I built.

Gave me flashbacks to argumentative know-it-all students from my CS teaching days. The more things change :allears:

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