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
OddObserver
Apr 3, 2009

Crackbunny posted:

line 67 :toot:
edit: it works only because in another function there's "if( name==null) return "null";"

So relying on the implementation hashcons'ing the string literal constants? (I don't remember, is that a MUST or a MAY, anyway?). They also can't seem to get method naming/capitalization consistent...

Adbot
ADBOT LOVES YOU

OddObserver
Apr 3, 2009

manero posted:

code:
  function replaceAll( str, searchTerm, replaceWith, ignoreCase )
  {
    var regex = "/"+searchTerm+"/g";
    if( ignoreCase ) regex += "i"; 
    return str.replace( eval(regex), replaceWith );
  }
This function is used in exactly three places directly above the function definition, none of which actually change the ignoreCase parameter.

Bonus points for using eval.

OddObserver
Apr 3, 2009
Alternatively, I feel like it would be a whole lot more readable with conditionals like:

if (total >= 1000 && total < 10000)

if (total >= 10000 && total < 1000000)

etc.

OddObserver
Apr 3, 2009

Spazmo posted:


Comparison functions shouldn't return on first difference to avoid timing attacks on password comparison.

Reminds me of a hilarious attack vector mentioned in:
Butler Lampson's "Hints for computer system design" --- http://research.microsoft.com/en-us/um/people/blampson/33-Hints/Acrobat.pdf --- see at page 5, starting from "Another example".

OddObserver
Apr 3, 2009

McGlockenshire posted:

Garbage in, garbage out. If you want different behavior, ask for it expressly.

I am pretty sure it's normally a good design practice for the sensible behavior to be default.

Ruby, BTW, just largely keeps the types separate, and only converts if you ask (though it does ignore trailing stuff):

code:
irb(main):001:0> 0 == false
=> false
irb(main):002:0> 1 == true
=> false
irb(main):003:0> "0" == 0
=> false
irb(main):004:0> "1" == 1
=> false
irb(main):005:0> "0".to_i == 0
=> true
irb(main):006:0> "0boo".to_i == 0
=> true

OddObserver
Apr 3, 2009
You don't need a server to use SVN locally.

OddObserver
Apr 3, 2009

Plorkyeran posted:

Setting up a local svn server is a hell of a lot more work than "git init".

"svnadmin create" isn't. Again, there are lots of criticism to be made out of svn, but for
single-user use, it's perfectly capable of working off file system, w/o a server.

OddObserver
Apr 3, 2009
Never mind proper cryptography --- I've had a cable internet provider's 'forgot password' feature e-mail me what was clearly a password I entered, so they were storing it plaintext. Plus, it was all lowercased, so they're likely doing case-insensitive comparisons, too. Then there are websites that insist that your password not be longer than 8 characters, or that complain about using non-alphanumeric characters, etc. I really have to wonder what would cause someone to do that -- SQL field of 8 chars?

OddObserver
Apr 3, 2009
What are all the - for?

OddObserver
Apr 3, 2009

NotShadowStar posted:

It would be great if the DOM had a 'supported' namespace so we could do 'if (browser.supported.elements.video)' but that's too much to handle for the W3C.
It does. document.implementation.hasFeature. The actual feature granularity kinda sucks, though.

OddObserver
Apr 3, 2009

Wheany posted:

I prefer Opera's user agent to this:


That is the user agent of Mozilla-AppleWebKit-KHTML-Gecko-Chrome-Safari.

Just throw Internet Explorer and Trident in there for maximum compatibility.

And if you do navigator.appName, you'll get 'Netscape'.

OddObserver
Apr 3, 2009

brosmike posted:

As a TA for a university that does this, I can confirm that this is the primary reason our intro course uses Scheme. It does a pretty good job of leveling the playing field a bit.

As someone who TAd an intro course using Java, I think there may be other good reasons for Scheme... namely it being a very minimalist language (though I would be very worried about recursion). It's easy to ignore it for someone with experience, but there is really a LOT of stuff going on in Java that people have to grasp at once to be able to really understand what they're doing --- the most obvious examples being scopes, with both locals and members making a difference, etc.
People are also basically forced to try to understand OOP (which is a tool for structuring complicated things) at the time they don't know how to do really simple things /correctly/.

... Though really, bringing back Pascal might actually not be a horrible idea, either (after adding a string type, of course).

OddObserver
Apr 3, 2009

GrumpyDoctor posted:

Worried about recursion how?

That people just starting out would have lots of difficulty getting it.

OddObserver
Apr 3, 2009

Pollyzoid posted:

The Ruby require thing is from http://rhnh.net/2011/05/28/speeding-up-rails-startup-time
It has fancy graphs and stuff :shobon:

... And that, kids, is why you learn about big O...

OddObserver
Apr 3, 2009

Internet Janitor posted:

I just wrote a Fortran compiler for 'fun'. Here is a nontrivial program written in a language where the only meaningful flow control mechanism is a numbered goto. A language in which variable names cannot exceed two characters long and integral types must start with i, j, k, l, m or n. A language without facilities for named constants or procedure definitions.

Read this horrible thing and ponder the fact that I'm not intentionally obfuscating my source- this is what programming used to look like.

Why are you using > and not .gt., etc.? Softy.

OddObserver
Apr 3, 2009

Internet Janitor posted:

I based my implementation on this document, which does not indicate the use of stropped keywords or symbols. I thought that was mainly an ALGOL thing, anyway.

That thing is pretty awesome, thanks for the link (it's always fun to read those early document). As for .gt., etc.... well, I am pretty sure at least Fortran 77 required those:
http://www.fortran.com/F77_std/rjcnf0001-sh-6.html#sh-6.3.1
.. and looking at WP articles on early Fortran dialects, seem likes they pretty much dropped the conditional feature in favor of a simpler version...

Edit: or see Fortran 66: ftp://ftp.nag.co.uk/sc22wg5/ARCHIVE/Fortran66.pdf

OddObserver
Apr 3, 2009

ToxicFrog posted:

Oh. So "automatic semicolon insertion" is "a semicolon is inserted at each newline if one is not already present".

:gonk:

Nothing that logical. Some statements or expressions get it inserted only if not having it would produce a parse error, others have it inserted unconditionally.

OddObserver
Apr 3, 2009
This isn't a PLT thunk, is it?

OddObserver
Apr 3, 2009
That's not correct even when obj and prop are both variable names (and obj doesn't have custom setters or getters) :D

OddObserver fucked around with this message at 04:55 on Feb 21, 2012

OddObserver
Apr 3, 2009

tef posted:

assuming no integer overflow :confused:

Well, the compiler probably can (repeat after me: signed integer overflow in C is undefined...)

OddObserver
Apr 3, 2009

PrBacterio posted:

The fact that it can do that with calls to std::string's and std::vector's size() methods.

Those are both field accesses, not loops (often hand-rolled in assembly).

OddObserver
Apr 3, 2009
I am pretty sure Java desugars long String + chains into StringBuilder calls, does C# not do the same?

OddObserver
Apr 3, 2009

Mogomra posted:

Everything in JavaScript is an object

:ssh: that's not actually true.

OddObserver
Apr 3, 2009

UraniumAnchor posted:


On what planet is this sane behavior? Can somebody explain to me what is going on here?

I don't remember the details, but IIRC there is some sort of a syntax hack in Ruby involving determining what's a
local variable or not by looking for assignments of it.

OddObserver
Apr 3, 2009
Or signed overflow.

OddObserver
Apr 3, 2009

Volmarias posted:

Eagerly awaiting a ""considered harmful" papers considered harmful" meta paper that lets us just get a new meme already.

Pretty sure that exists.

OddObserver
Apr 3, 2009
Didn't git recently change to have push only affect one branch by default?

OddObserver
Apr 3, 2009

rjmccall posted:

You would not believe the number of uninitialized-variable bugs that go uncaught because they happen to occur in code that runs first thing in the process.
There used to be a problem that was reported by KDE users like this: if you run an app from command line it gets anti aliasing; if you run it from panel AA is off. Root cause?
uninitialized Boolean-semantic int in Xft (IIRC). Launching apps from panel used some tricks to reduce linking, while in command-line path it triggered the dynamic linker from a lazy resolution stub, which helpfully wrote out a non-zero on the right spot in the stack.

OddObserver
Apr 3, 2009

Zombywuf posted:

The correct way to test a bit in C++ is obviously:
C++ code:
#include <type_traits>
#include <cassert>

template<class Integer>
bool is_bit_set(int offset, Integer value) {
  static_assert(std::is_integral<Integer>::value, "Can only test integral types");
  assert(offset >= 0);
  assert(offset < sizeof(Integer) * 8);

  return value & (1 << offset);
}

Is the 8 correct?

OddObserver
Apr 3, 2009
The important part is to not end up with another "referer".

OddObserver
Apr 3, 2009
I am not sure it's guaranteed to work, I don't think Function.prototype.toString is required to preserve
comments though admittedly they are not explicitly listed as things it may change:

quote:

An implementation-dependent representation of the function is returned. This representation has the syntax of a FunctionDeclaration. Note in particular that the use and placement of white space, line terminators, and semicolons within the representation String is implementation-dependent.

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.

OddObserver
Apr 3, 2009
In fact the one thing 'this' can't be is a local variable scope.
(It could be some weird magic scopes like the scope of exception variable in ES3, but that insanity
got fixed in ES5)

OddObserver
Apr 3, 2009

Vanadium posted:

They used to have some of the features gated on <script type="text/javascript;version=1.8"> or whatever, not sure what happened to that. I guess it went under with the move to HTML5 as a "living standard".

It never had anything to do with standards, it's just a previous Mozilla "we own JavaScript so we do what we want" thing --- they've put in plenty of extensions way before
there was any real chance of them being standardized.

OddObserver
Apr 3, 2009

Jewel posted:

So it doesn't work like C/C++ where it just creates a "read-only memory" section and just maps it out to the process space on run? Which is still technically is a compiler thing because it has to grab the literals and put them in that read-only space.

You could do that for literals, yes, but some strings are computed at runtime.
(Though with some of the work in the simple case would have to be done by the JIT --- but then even in C or C++ case the dynamic linker might have to do work at runtime to patch up references to strings, too)

OddObserver
Apr 3, 2009

Subjunctive posted:

No, the class loader causes them to be allocated as interned strings at load time. Java classes may never be on disk at all (network fetch, etc.). I don't know of an implementation that maps the classfile persistently, but I'm not totally up to date.

Dalvik might, I think ;-)
(Though of course those would be .dex, or was it .odex files, not .class files)

OddObserver
Apr 3, 2009

Voted Worst Mom posted:

Let me personally assure you that gcc has never and will never accept that nonconformant code without error.

Are you really sure that something like 2.7 or somesuch prehistoric version didn't? ;-)

OddObserver
Apr 3, 2009

Dylan16807 posted:

Browsers let you do it but I don't think it's in the spec and it's definitely not something you would need to implement in your bespoke embedded JS.

It's in the spec, though sort of poorly phrased:

quote:

15.3.4.2 Function.prototype.toString ( )

An implementation-dependent representation of the function is returned. This representation has the syntax of a FunctionDeclaration. Note in particular that the use and placement of white space, line terminators, and semicolons within the representation String is implementation-dependent.

OddObserver
Apr 3, 2009

Subjunctive posted:

The IR I'm thinking of is pre-JIT interpreter bytecode, stack-based (Spidermonkey). The stack traffic adds up, lots of POP after ignored function returns, re-pushing as part of chained conditions, the nonsense you have to do for object iteration to be exception-correct, blah blah. Comment stripping is meaningful, because char-by-char parsing of big license headers can add up. Better, though, to just minimize and use something like source maps, if you that's appearing on the profiler.

That said, there was a time when JSCore executed the AST and Spidermonkey had stack-based bytecode, and JSCore beat us on a bunch of benchmarks because the object representation was better and there were a couple more optimizations done on the graph, so you can go relatively quickly if you do the rest of the stuff correctly.

(Spidermonkey actually doesn't or at least didn't preserve the source of scripts, instead decompiling from the bytecode to produce equivalent source as needed for error messages and function-as-string. That was some pretty annoying code to work on, but it did let us give pretty great error messages.)

As a aside: are you aware, is any implementation sophisticated enough to avoid constructing strings for a for ... in over an array for the indices?

Adbot
ADBOT LOVES YOU

OddObserver
Apr 3, 2009

rjmccall posted:


Examples of undefined behavior that would actually be reasonable to detect and warn about in 100% of situations:
  • literally nothing, because why would the language make it undefined behavior instead of just ill-formed if it were always trivial to detect?

What does the spec say about passing objects through varargs? gcc's "... will crash at run time" warning always struck me as, well, a bit of a horror.
(In being a warning, that is).

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