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
Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.

KARMA! posted:

Why would a toString on a function even work? :confused:

Because Javascript.

Adbot
ADBOT LOVES YOU

canis minor
May 4, 2011

Internet Janitor posted:

eithedog: The readme does address this. A line continuation using \ will not insert newlines automatically when you continue the string on another line. You'd need \n\.

Oh, sorry, didn't read the comments, I've read the code you posted. Are there any situations when manipulating HTML actually needs \n?

It works because the functions source actually contains the comments and you can access the functions code, per:

code:
(function a(){/* hi */ window.alert((a+"").match(/\/\*.*\*\//g))})()
You can run it in console to find out.

canis minor fucked around with this message at 19:24 on Jul 12, 2014

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

KARMA! posted:

Why would a toString on a function even work? :confused:

I tried making it not work at one point, and it broke a bunch of sites including eBay that were decompiling, manipulating the source, and then recompiling the function. Opera used to have a ton of web compat issues because they didn't produce legal source (it was a parse error, something like "function () { [ecmascript source] }"). IIRC ES3 required that it at least parse.

I think prototype and jQuery also used decompilation, one of them in order to recompile in the context of another frame.

eithedog posted:

Oh, sorry, didn't read the comments, I've read the code you posted. Are there any situations when manipulating HTML actually needs \n?

You need whitespace at least.

JavaScript code:

var link = "<a\
href='about:blank'>";

gives you <ahref='about :blank'>, which isn't what you want.

Subjunctive fucked around with this message at 04:16 on Jul 13, 2014

OddObserver
Apr 3, 2009
5.1 at least requires it to be a valid FunctionDeclaration, but it doesn't say anything explicit about it being semantically equivalent to the original ;-)
(I suppose stuff like function() { [native code] } is justifiable by host functions having an own [[DefaultValue]] for hint=String?)

Expecting comments to be retained is sort of extra unreasonable in my book since it means you pretty much have to keep pointers into source code around even if your IR is something like an AST that's high-level enough to reconstruct from. I am probably horror-level paranoid about memory usage in high-count data structures, though.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

Subjunctive posted:

I think prototype and jQuery also used decompilation, one of them in order to recompile in the context of another frame.

Isn't this the sort of situation bind() is meant for, or am I misunderstanding the issue?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Internet Janitor posted:

Isn't this the sort of situation bind() is meant for, or am I misunderstanding the issue?

"Different frame" as in, an iframe or whatever.

In terms of memory use, it's a pointer and a length per function-statement (not per function instance), which you can stick out of the critical path (e.g. off in the AST which is only looked at if you need line numbers for a stack-trace or need to recompile because your optimistic optimizations were invalidated) to use the function declaration as it's written in the source. This seems way easier than decompiling your AST into semantically equivalent code every time.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Jabor posted:

"Different frame" as in, an iframe or whatever.

In terms of memory use, it's a pointer and a length per function-statement (not per function instance), which you can stick out of the critical path (e.g. off in the AST which is only looked at if you need line numbers for a stack-trace or need to recompile because your optimistic optimizations were invalidated) to use the function declaration as it's written in the source. This seems way easier than decompiling your AST into semantically equivalent code every time.

It is easier, but also requires you to preserve eval source and pin cache entries in memory, etc. Firefox decompiles bytecode (or did through the previous engine iteration, at least) because keeping the source around was a meaningful memory issue when the engine was first deployed. We talked about source preservation instead, but it can be a lot of memory in some cases, and we already had the decompiler. In your model, you have to preserve the AST, too, and they can be a meaningful size.

fritz
Jul 26, 2003

The guy I have to work with broke the CI server (as in, like, totally hosed and now it won't run on any branch at all) and all he had to say was, almost literally, 'it works on my machine'.

Pythagoras a trois
Feb 19, 2004

I have a lot of points to make and I will make them later.
I keep thinking that projects written in Javascript is a fad that will go away, and then I see something like this: http://breach.cc/

Soricidus
Oct 21, 2010
freedom-hating statist shill
If all you know how to use is a hammer ...

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Javascript is a pretty crummy language in many respects, but as far as being stuck with a universal scripting language we could've done so much worse.

If I could only use one programming language for the rest of my life and my choices were Perl, PHP, Python, Ruby or Javascript I think I'd go with Javascript. The sheer force of people hammering their heads against it even seems to be slowly making the language less hosed up. The more I think about it the easier it is for me to understand why Node.js exists.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

fritz posted:

The guy I have to work with broke the CI server (as in, like, totally hosed and now it won't run on any branch at all) and all he had to say was, almost literally, 'it works on my machine'.

Yeah, there's basically a call and response if someone blocks deploy:

"aw man, it worked on my dev server"
"np, we'll just route all the users to your dev server"

nielsm
Jun 1, 2009



Cheekio posted:

I keep thinking that projects written in Javascript is a fad that will go away, and then I see something like this: http://breach.cc/

A browser written in JS? Ehh...
...oh, it's not actually written in JS, it's just another Chromium frontend.
So it's a browser user interface written in JS. And for some reason HTML5 too.

Hasn't Mozilla done that exact thing for 10+ years?

QuarkJets
Sep 8, 2008

I learned today that MATLAB, in the year of our lord 2014, doesn't support placing a title over a group of subplots. An official answer from MathWorks is that it's simply impossible. The workaround is to hack in an additional tiny set of axes with a text box inside of it.

:suicide:

fritz
Jul 26, 2003

Subjunctive posted:

Yeah, there's basically a call and response if someone blocks deploy:

"aw man, it worked on my dev server"
"np, we'll just route all the users to your dev server"

This is a dude who if he's not being actively obstinate or abusive I just work around him, and it's either I fix the CI server or the ceo does because he's just going to mess it up more.

No Safe Word
Feb 26, 2005

Subjunctive posted:

Yeah, there's basically a call and response if someone blocks deploy:

"aw man, it worked on my dev server"
"np, we'll just route all the users to your dev server"

Even better when it's not hosted:

"we'll just ship them your laptop then"

substitute
Aug 30, 2003

you for my mum
Designers are the worst.

code:
body.derp ol {list-style:disc; margin-left:15px;}

...10 lines later...

body.derp_derp ol {list-style:disc; margin-left:15px;}
YES, it's perfectly logical to make an ordered list look like an unordered list, and to do it multiple times throughout your CSS.

substitute fucked around with this message at 15:54 on Jul 14, 2014

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

substitute posted:

Designers are the worst.

code:

body.derp ol {list-style:disc; margin-left:15px;}

...10 lines later...

body.derp_derp ol {list-style:disc; margin-left:15px;}

YES, it's perfectly logical to make an ordered list look like an unordered list, and to do it multiple times throughout your CSS.

How much of a PITA is it for them to change the markup that's emitted for just those cases?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Subjunctive posted:

How much of a PITA is it for them to change the markup that's emitted for just those cases?

They're already doing all that work to add the derp class to the body. You want the to do more? You monster.

canis minor
May 4, 2011

Lumpy posted:

They're already doing all that work to add the derp class to the body. You want the to do more? You monster.

Our designers have access to code and indeed do change it.

The results are... interesting.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

I want to add something to a program I use (Dwarf Therapist), and it's written in Qt. Haven't used it before, but that's fine, I can pick up a toolkit without too much trouble I'm sure.

It uses modified C++ syntax to express its signal/slot stuff, the plugin that lets VS cope with that poo poo doesn't work with Express, and getting the toy QtCreator IDE to produce a 32-bit binary required 2 reinstalls of the whole thing to excise all knowledge of 64-bit architectures. Maybe there was a way to force it to 32-bit, but I couldn't find it in the docs that were pretty much all for older versions and/or dead because the links point at dead Nokia-hosted sites.

Dicky B
Mar 23, 2004

What does the Qt VS plugin do? I've used Qt for years and can't imagine needing any kind of IDE plugin to "cope" with the signal/slot syntax. I'm all for trying it if it makes my life easier somehow though.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Since Qt uses its own magic preprocessor to add features to C++ you could almost argue that it is a distinct language from C++.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Dicky B posted:

What does the Qt VS plugin do? I've used Qt for years and can't imagine needing any kind of IDE plugin to "cope" with the signal/slot syntax. I'm all for trying it if it makes my life easier somehow though.

It looked like VC was choking on the slots: declarations, but my setup was a mess by that point and I don't really have any familiarity.

The plugin looks like it just does ancillary stuff around debugging and build machinations, so I guess I must not have needed it in order to do the stuff with the thing.

http://qt-project.org/faq/answer/what_is_the_qt_visual_studio_add-in

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.
Realistically you only need to run the preprocessor (moc or what was it) over those files, and that and linking with some visual UI designer thing is all the plugin does.

If you run qmake from the commandline you can make it poop out Visual Studio project files.

Hammerite
Mar 9, 2007

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

substitute posted:

Designers are the worst.

code:
body.derp ol {list-style:disc; margin-left:15px;}

...10 lines later...

body.derp_derp ol {list-style:disc; margin-left:15px;}
YES, it's perfectly logical to make an ordered list look like an unordered list, and to do it multiple times throughout your CSS.

I thought the choice of ordered vs. unordered list just indicated whether the order of the items matters. As in, if it's an unordered list then the list items' order can be changed and it doesn't matter. I see no reason why you shouldn't use bullets but still care about the order of the list items.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

e- the hell am I posting in here for

baka kaba fucked around with this message at 20:01 on Jul 14, 2014

Space Kablooey
May 6, 2009


Hammerite posted:

I thought the choice of ordered vs. unordered list just indicated whether the order of the items matters. As in, if it's an unordered list then the list items' order can be changed and it doesn't matter. I see no reason why you shouldn't use bullets but still care about the order of the list items.

Then you should use ul instead of hacking css to do it with ol, but worse.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

baka kaba posted:

Me again, with the unit tests (in Java specifically).

This is really a general approach question that I haven't really got the hang of - what do y'all usually do when testing a method relies on another one working? The simplest example is a getter and setter pair - testing the setter involves testing the getter too (unless the variable being set is exposed, or you can expose it through a stub). You can't actually test one method call in isolation, because you need to call another to get your results.

Are there any general approaches for this? Do you just compromise and test 'setting and getting', and then use them for setting up and checking your test cases? It just seems to break the whole idea of not having tests rely on other tests, if you break something in your set/get code it'll cause failures all over the place. And making private variables public (or protected so you can make some stub methods) seems like a compromise.

Generally I'm tempted to go the protected/stub route, it works well when the visibility already allows it, but I'd like to hear some other suggestions if anyone has any

Don't test get/set methods unless they actually have some sort of logic in them; it's wasted effort if they don't. That said, I'd write test cases for the get/set methods as one cohesive unit. Your only concern is that if you put value X in, you get value Y out. It doesn't matter if it's mutating as part of the get operation or the set operation. Other parts of your application might care about that distinction, but you'll write other tests that will cover that aspect. In C#, the relationship between get/set is a little bit clearer because it has properties, so you'd have public string Foo {get;set;} instead of two explicit methods to retrieve/mutate some private _foo member.

Don't go crazy with mocks. Purists will tell you to mock out every single thing that goes into every single class, but there are going to be times when that's impractical or silly. Apply common sense liberally. Java actually has an easier time with mocks since everything is virtual by default, so you don't need to sprinkle virtual keywords everywhere or rely heavily on single-implementation interfaces like you would in C#.

New Yorp New Yorp fucked around with this message at 20:04 on Jul 14, 2014

Hammerite
Mar 9, 2007

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

HardDisk posted:

Then you should use ul instead of hacking css to do it with ol, but worse.

I'll try this again. ul is an unordered list. Therefore if you care about the order of the items, isn't it appropriate to use ol (ordered list) even if you want to display the list items with bullets?

I mean, I think I was pretty clear in my post before. If you think I'm wrong, then fine, say so, but it seems like what I was saying went straight over your head.

vOv
Feb 8, 2014

Hammerite posted:

I'll try this again. ul is an unordered list. Therefore if you care about the order of the items, isn't it appropriate to use ol (ordered list) even if you want to display the list items with bullets?

I mean, I think I was pretty clear in my post before. If you think I'm wrong, then fine, say so, but it seems like what I was saying went straight over your head.

So your argument is that if you want to display the steps to make a meal with bullets for whatever reason, you'd use ol and style the items to use bullets since the items are still logically ordered? I can sort of see that.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Ithaqua posted:

Don't test get/set methods unless they actually have some sort of logic in them; it's wasted effort if they don't. That said, I'd write test cases for the get/set methods as one cohesive unit. Your only concern is that if you put value X in, you get value Y out. It doesn't matter if it's mutating as part of the get operation or the set operation. Other parts of your application might care about that distinction, but you'll write other tests that will cover that aspect.

Don't go crazy with mocks. Purists will tell you to mock out every single thing that goes into every single class, but there are going to be times when that's impractical or silly. Apply common sense liberally. Java actually has an easier time with mocks since everything is virtual by default, so you don't need to sprinkle virtual keywords everywhere or rely heavily on single-implementation interfaces like you would in C#.

Cheers, I posted that in completely the wrong thread so uh thanks for the genuine reply! I've just been trying to get into the 'don't have tests relying on other tests' mentality, and this feels like it completely violates that idea. It seems mostly harmless when your methods are simple, but when they're not (or if they get more complex later) it could introduce problems where the cause isn't immediately obvious. That's what I'm worried about really. But yeah, wrong thread!

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

HardDisk posted:

Then you should use ul instead of hacking css to do it with ol, but worse.

No, the point is that "order" is semantic ("these are our top concerns, in descending order of urgency"), and independent of whether or not sequential labeling is how you want to present it. This seems like an entirely appropriate use of CSS, since it's controlling presentation and the markup expresses semantics. It's one of the motivations for list-style's range of values IIRC.

e;fb

hobbesmaster
Jan 28, 2008

Internet Janitor posted:

Since Qt uses its own magic preprocessor to add features to C++ you could almost argue that it is a distinct language from C++.

Theres no magic preprocessor, signals/slots is standard preprocessor stuff which is also used by boost::signals. The declarations like Q_OBJECT are also expanded by the standard preprocessor. moc automatically generates C++ code for classes containing Q_OBJECT and other macros in scanned headers - you're free to create the C++ metaobject functions yourself if you hate maintainability.

fritz
Jul 26, 2003

fritz posted:

The guy I have to work with broke the CI server (as in, like, totally hosed and now it won't run on any branch at all) and all he had to say was, almost literally, 'it works on my machine'.

He pushed the same broken branch and now it's broken again in exactly the same way, and I'm not gonna fix it this time.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

baka kaba posted:

Cheers, I posted that in completely the wrong thread so uh thanks for the genuine reply! I've just been trying to get into the 'don't have tests relying on other tests' mentality, and this feels like it completely violates that idea. It seems mostly harmless when your methods are simple, but when they're not (or if they get more complex later) it could introduce problems where the cause isn't immediately obvious. That's what I'm worried about really. But yeah, wrong thread!

One last derail, then:

The idea you have of not coupling tests is correct, but I think your understanding is a bit off. It's not the end of the world if you change the behavior of your property accessor methods and it breaks down-stream tests -- that's an indication that something isn't working the way it should be! You should be minimizing the extent to which that happens by mocking dependencies, but like I said, it's not always going to be worthwhile to mock every single dependency.

The actual problem when you have tests depend on other tests is when those tests mess with global state, and other tests depend on that state. Each test should be starting from the exact same point and constructing the artifacts it needs to run successfully. This is why singletons are anathema to good unit testing practices -- they represent global state and can be a huge pain in the rear end to test around.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

hobbesmaster posted:

Theres no magic preprocessor, signals/slots is standard preprocessor stuff which is also used by boost::signals. The declarations like Q_OBJECT are also expanded by the standard preprocessor. moc automatically generates C++ code for classes containing Q_OBJECT and other macros in scanned headers - you're free to create the C++ metaobject functions yourself if you hate maintainability.

I thought it was choking on the "slots: " pieces in the C++ files, but as has become eminently clear I may in fact be the Qt PEBKAC hazard. Tool ergonomics are still lovely, though.

Space Kablooey
May 6, 2009



I wasn't trying to direct the snark at you. Sorry for that.



I see now. I still think there's something wrong when you want to present something with an order and not order it somehow (not accounting for the positioning in the page, which is a type of order in itself). I just wouldn't expect a bulleted list to be a ol tag in any page, but I'll have to live with that.

hobbesmaster
Jan 28, 2008

Subjunctive posted:

I thought it was choking on the "slots: " pieces in the C++ files, but as has become eminently clear I may in fact be the Qt PEBKAC hazard. Tool ergonomics are still lovely, though.

Just use Qt creator, the visual studio plugin has always seemed a bit broken. Its supposed to read in qmake .pro files and manage qt versions and such but seems to be more trouble than its worth to me.

Intellisense can be quite confused by Qt's macros, while Qt Creator's completion isn't as good as intellisense its pretty decent.

Adbot
ADBOT LOVES YOU

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

HardDisk posted:

I see now. I still think there's something wrong when you want to present something with an order and not order it somehow (not accounting for the positioning in the page, which is a type of order in itself).

I think *most* ordering you encounter in communication is unlabeled, because sequence of reading or hearing carries the ordering information. "Today we're going to 1) finish the code review, then 2) have lunch, then 3) write a witty post on SA" wouldn't be totally awkward, but is uncommon.

hobbesmaster posted:

Just use Qt creator, the visual studio plugin has always seemed a bit broken. Its supposed to read in qmake .pro files and manage qt versions and such but seems to be more trouble than its worth to me.

Yeah, I started with QtCreator, but it insisted on building 64-bit and wouldn't let me pick the 32-bit runtime once I forced it to find the 32-bit compiler and...yeah, I said a swear or two. I'll try again after a glass of wine later this week and see if I get there, because I'd really like to add this thing to the program!

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