These are chat archives for voodooattack/nexusjs

6th
May 2016
Abdullah A. Hassan
@voodooattack
May 06 2016 16:43 UTC
Oh wow
That will answer so many questions for anyone asking why nexus is inherently atomic.
jtenner
@jtenner
May 06 2016 16:44 UTC
LOL
They are trying to make the Primitives for SharedArrayBuffer
Abdullah A. Hassan
@voodooattack
May 06 2016 16:44 UTC
Yeah
jtenner
@jtenner
May 06 2016 16:44 UTC
I want it so badly.
Abdullah A. Hassan
@voodooattack
May 06 2016 16:45 UTC
Sooo bookmarked.
Thanks for finding that
jtenner
@jtenner
May 06 2016 16:45 UTC
It showed up in my feed today, and I knew you would love to read it.
Does this affect your work? It's talking about JavaScriptCore
Abdullah A. Hassan
@voodooattack
May 06 2016 16:45 UTC
Yeah, thanks.
Yep, pretty much what I'm working with
I'm going to put that in my next article
jtenner
@jtenner
May 06 2016 16:46 UTC
I'm curious if you could use the primitives coming down from the top instead of making your own?
Abdullah A. Hassan
@voodooattack
May 06 2016 16:46 UTC
Yeah, but it would be cumbersome.
Linking into JSC is enough
Actually using the sources is like madness
I'd have to clone 5GB into a git submodule for that to happen. No chance of hell. yet.
jtenner
@jtenner
May 06 2016 16:47 UTC
  • SPIT TAKE *
oops
SPIT TAKE
Abdullah A. Hassan
@voodooattack
May 06 2016 16:47 UTC
lol
jtenner
@jtenner
May 06 2016 16:48 UTC
yeah.
that's crazy.
Abdullah A. Hassan
@voodooattack
May 06 2016 16:48 UTC
Exactly
I had to git clone --depth 0 to grab a copy of webkit as it is
And it took forever
jtenner
@jtenner
May 06 2016 17:55 UTC
Have you considdered using WTF::ParkingLot lol
Abdullah A. Hassan
@voodooattack
May 06 2016 17:56 UTC
It's used internally by JSC
jtenner
@jtenner
May 06 2016 17:56 UTC
Oh.
The WTF namespace makes me lol every time.
Abdullah A. Hassan
@voodooattack
May 06 2016 17:56 UTC
hehe
yeah
jtenner
@jtenner
May 06 2016 17:56 UTC
They paid JSC to put up a WTF::ParkingLot
Abdullah A. Hassan
@voodooattack
May 06 2016 17:57 UTC
WTF::Exception made me lol
It was a big moment when I first saw it
I thought my computer was making fun of me
jtenner
@jtenner
May 06 2016 18:00 UTC
As someone who knows how to code and has technically compiled C++ in his life, can you let me ask questions about how C++ and your repo works?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:01 UTC
Sure
jtenner
@jtenner
May 06 2016 18:01 UTC
I'm prepared to read the source code.
shudders
Abdullah A. Hassan
@voodooattack
May 06 2016 18:01 UTC
Haha
Okay
jtenner
@jtenner
May 06 2016 18:02 UTC
I have the repo open
I'm looking at the src/ directory.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:02 UTC
Just don't mock my coding skills
jtenner
@jtenner
May 06 2016 18:02 UTC
I have no opinion on coding skills :)
Abdullah A. Hassan
@voodooattack
May 06 2016 18:02 UTC
hehe
jtenner
@jtenner
May 06 2016 18:02 UTC
What exactly are .h files? (general question)
Abdullah A. Hassan
@voodooattack
May 06 2016 18:02 UTC
I'm sure you will
jtenner
@jtenner
May 06 2016 18:02 UTC
It stands for header, I know this.
Is a header file like a C# interface?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:03 UTC
.h are the headers. That's where you declare stuff
jtenner
@jtenner
May 06 2016 18:03 UTC
What do you mean by declare stuff?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:04 UTC
Hang on. I need a keyboard to type this. Phone won't work for this
jtenner
@jtenner
May 06 2016 18:04 UTC
Hahaha. Thank you for your time.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:04 UTC
No problem. Let's do this
So, imagine a machine.. You have a blueprint, and a physical model
The header files are the blueprints
The .cpp files are the parts
The executable is the assembled machine
jtenner
@jtenner
May 06 2016 18:05 UTC
Great. They probably function exactly like interfaces
Abdullah A. Hassan
@voodooattack
May 06 2016 18:06 UTC
Something like that
jtenner
@jtenner
May 06 2016 18:06 UTC
.h files define WHAT functions show up in classes. right?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:06 UTC
You use headers to declare classes.. some of them are abstract (interfaces)
Yes
jtenner
@jtenner
May 06 2016 18:06 UTC
Oh okay.
the CPP files define the functions.
Can you show me a simple example
Abdullah A. Hassan
@voodooattack
May 06 2016 18:06 UTC
You can't define a function in a .cpp file without declaring it first in a .h
jtenner
@jtenner
May 06 2016 18:07 UTC
Can you actually define a full function in a .h file?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:09 UTC

class_A.h:

class A {
  void hello(); // declaration
}

class_A.cpp:

#include <iostream>
#include "class_A.h" // import the declaration
void A::hello() {
  std::cout << "hello!" << std::endl;
}
jtenner
@jtenner
May 06 2016 18:09 UTC
Yeah that's an interface
Abdullah A. Hassan
@voodooattack
May 06 2016 18:09 UTC
You could, that'd inline it.
No, that's not an interface
jtenner
@jtenner
May 06 2016 18:09 UTC
void A::hello() attaches the function compile time, right?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:10 UTC
That's a regular class. an interface would have abstract methods
Yes
jtenner
@jtenner
May 06 2016 18:10 UTC
in that case, header files are more like a contract
not exactly the whole blueprint
Abdullah A. Hassan
@voodooattack
May 06 2016 18:10 UTC
Yeah, something like that
The header files have the declarations, the cpp files have the definitions.
jtenner
@jtenner
May 06 2016 18:11 UTC
What if you don't define A::hello() in the cpp file?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:11 UTC
You get an undefined reference error at link time.
jtenner
@jtenner
May 06 2016 18:11 UTC
Great. That makes sense to me.
Are you familiar with c#
Abdullah A. Hassan
@voodooattack
May 06 2016 18:12 UTC
I used to be.
jtenner
@jtenner
May 06 2016 18:12 UTC
Do namespaces function the same way?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:12 UTC
Yeah
There's one more thing.
jtenner
@jtenner
May 06 2016 18:13 UTC
You could have a .h file with a namespace that doesn't match the directory structure
Abdullah A. Hassan
@voodooattack
May 06 2016 18:13 UTC
A .cpp file compiles to an object file (.obj/.o depending on the compiler)
jtenner
@jtenner
May 06 2016 18:13 UTC
Yep.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:13 UTC
Directory structure is irrelevant.
Anyway, the compiled object files are then linked.
jtenner
@jtenner
May 06 2016 18:14 UTC
Cool.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:14 UTC
That's when you'd get the undefined reference error.
jtenner
@jtenner
May 06 2016 18:14 UTC
class ProtectedArguments {
public:
   //exposed stuff here
}
You don't have to attach public to every property now.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:15 UTC
You put public: before them
No
jtenner
@jtenner
May 06 2016 18:15 UTC
 ProtectedArguments(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[]):
      myContext(ctx), myArguments(arguments, arguments + argumentCount)
    {
      for(auto i: myArguments)
        JSValueProtect(myContext, i);
    }
This is the constructor, right?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:15 UTC
Yep
I define it inline
I'm lazy sometimes :P
jtenner
@jtenner
May 06 2016 18:16 UTC
it's in the util.h file, why isn't the constructor declared in the util.cpp file
Abdullah A. Hassan
@voodooattack
May 06 2016 18:16 UTC
Small/trivial code can go into the headers sometimes
jtenner
@jtenner
May 06 2016 18:16 UTC
It's basically up to the developer where the code goes.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:16 UTC
Whereupon the compiler will inline it
jtenner
@jtenner
May 06 2016 18:16 UTC
Does that make it faster?
Or is it just "i like it this way"
Abdullah A. Hassan
@voodooattack
May 06 2016 18:17 UTC
Yes, but that's irrelevant nowadays
jtenner
@jtenner
May 06 2016 18:17 UTC
So it's kindof both?
Neat.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:17 UTC
Most compilers can inline definitions as well
Nowadays I mean
It was much harder in the past
jtenner
@jtenner
May 06 2016 18:18 UTC
  class ProtectedArguments {
  public:
    ProtectedArguments(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[]):
      myContext(ctx), myArguments(arguments, arguments + argumentCount)
    {
      for(auto i: myArguments)
        JSValueProtect(myContext, i);
    }
    ProtectedArguments(const ProtectedArguments & other): myContext(other.myContext), myArguments(other.myArguments) {
      for(auto i: myArguments)
        JSValueProtect(myContext, i);
    }
    ~ProtectedArguments() {
      for(auto i: myArguments)
        JSValueUnprotect(myContext, i);
    }
}
These are all obviously different constructors
Abdullah A. Hassan
@voodooattack
May 06 2016 18:18 UTC
The last is a destructor
jtenner
@jtenner
May 06 2016 18:18 UTC
on line 49, there is a ~
Oh!
It looks like each class comes with a native IDisposable interface
Abdullah A. Hassan
@voodooattack
May 06 2016 18:19 UTC
For when an object is destroyed.
jtenner
@jtenner
May 06 2016 18:19 UTC
That's actually really neat.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:19 UTC
Haha
Yes
All classes manage their own memory.
jtenner
@jtenner
May 06 2016 18:19 UTC
I feel like such a noob. Thanks for being patient with me.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:20 UTC
No problem. I'm actually enjoying this. It's been a while since I explained anything to anyone.
jtenner
@jtenner
May 06 2016 18:20 UTC
 JSValueRef operator[](int index) { return myArguments[index]; }
Abdullah A. Hassan
@voodooattack
May 06 2016 18:20 UTC
That's the [] operator
x[1]
....would call that.
jtenner
@jtenner
May 06 2016 18:20 UTC
So this is an array, and you are overriding the syntax for array access
Abdullah A. Hassan
@voodooattack
May 06 2016 18:21 UTC
No, this is a class, and I'm giving it array semantics.
jtenner
@jtenner
May 06 2016 18:21 UTC
I think you and I understand what it means, and I'm using words that don't have meaning to you.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:21 UTC
Yes, I'm giving you the correct terminology.
Don't be offended when I point out the obvious. :D
jtenner
@jtenner
May 06 2016 18:22 UTC
I wasn't offended
I wanted to make sure I understood the concept before I got the word for it.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:22 UTC
Aha
You got it right
jtenner
@jtenner
May 06 2016 18:22 UTC
    JSValueRef operator[](int index) { return myArguments[index]; }
    operator JSValueRef *() { return &myArguments[0]; }

    JSValueRef operator[](int index) const { return myArguments[index]; }
    operator const JSValueRef *() const { return myArguments.data(); }
This is overloaded, what's the reason?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:23 UTC
See the last two versions, they have const next to them
That's for const access.. when you have a constant pointer to an object
Or a constant reference
jtenner
@jtenner
May 06 2016 18:24 UTC
I think I don't understand what this means.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:24 UTC
Okay
Here we go
jtenner
@jtenner
May 06 2016 18:24 UTC
I'm trying to figure out what I don't understand.

Here we go

Uh oh

lol
Abdullah A. Hassan
@voodooattack
May 06 2016 18:25 UTC
int x = 0; // define an integer with name x and value 0
int * y = &x; // define a pointer to an integer with name y and point at x
jtenner
@jtenner
May 06 2016 18:26 UTC
int * y points at the address of x
now how do I operate on y to modify x?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:26 UTC
Yes
jtenner
@jtenner
May 06 2016 18:26 UTC
I remember this vaugely
Abdullah A. Hassan
@voodooattack
May 06 2016 18:26 UTC
*y = 10;
This changes x to 10
jtenner
@jtenner
May 06 2016 18:27 UTC
*y = 10;
x;
//10
Abdullah A. Hassan
@voodooattack
May 06 2016 18:27 UTC
Yep
jtenner
@jtenner
May 06 2016 18:27 UTC
that's neat.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:27 UTC
Think of x here as a space in memory(the stack really) and y as the address of that space.
jtenner
@jtenner
May 06 2016 18:27 UTC
So now you can write a loop over a set of objects by changing a pointer
Abdullah A. Hassan
@voodooattack
May 06 2016 18:27 UTC
Yeah
You can use them to implement all kinds of crazy things
jtenner
@jtenner
May 06 2016 18:28 UTC
Linked lists
Abdullah A. Hassan
@voodooattack
May 06 2016 18:28 UTC
Linked lists, graphs, etc
jtenner
@jtenner
May 06 2016 18:28 UTC
Yep
Abdullah A. Hassan
@voodooattack
May 06 2016 18:28 UTC
Jinx :D
jtenner
@jtenner
May 06 2016 18:28 UTC
Hahaha
Abdullah A. Hassan
@voodooattack
May 06 2016 18:29 UTC
So you have pointers
And then you have const pointers
jtenner
@jtenner
May 06 2016 18:29 UTC

SO...

operator JSValueRef *() { return &myArguments[0]; }

this defines how *y = 10; would operate

Abdullah A. Hassan
@voodooattack
May 06 2016 18:29 UTC
Yes
jtenner
@jtenner
May 06 2016 18:29 UTC
I should really say:
*args[x] = ...;
Abdullah A. Hassan
@voodooattack
May 06 2016 18:30 UTC
This both gives you the address and lets you dereference it
Awesome, correct.
jtenner
@jtenner
May 06 2016 18:30 UTC
I don't understand the last sentence
Abdullah A. Hassan
@voodooattack
May 06 2016 18:30 UTC
Now, as for const pointers.
jtenner
@jtenner
May 06 2016 18:30 UTC
gives you the address and lets you dereference it
before you move onto const
Abdullah A. Hassan
@voodooattack
May 06 2016 18:30 UTC
Okay
JSValueRef * x = args[0]; // taking the address
*x = ....;  // dereferencing 
*args[0] = ...; // also dereferencing
jtenner
@jtenner
May 06 2016 18:32 UTC
dereference means grab the location using the & symbol, right?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:32 UTC
No, that's referencing
Dereferencing is accessing a pointer via *
jtenner
@jtenner
May 06 2016 18:32 UTC
OH I understood the concept first before the word.
Good.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:32 UTC
You sure you don't know C++ already? :P
jtenner
@jtenner
May 06 2016 18:32 UTC
Yeah. I don't know the definitions and words ;-)
I also would not ever remember how to do something like this
Abdullah A. Hassan
@voodooattack
May 06 2016 18:33 UTC
Haha
Ready to move on?
jtenner
@jtenner
May 06 2016 18:33 UTC
You bet
Abdullah A. Hassan
@voodooattack
May 06 2016 18:35 UTC
Okay, so we talked about pointers. Now things get a bit icky.
ProtectedArguments args = ....; // normal object
const ProtectedArguments & args2(args); /// const reference to object
args[0] // accesses the regular version of the [] operator
args2[0] // accesses the const version of the [] operator
Inside the const version, the *this value is also const.
So a const method can't call into a non-const method.
Unless it's declared mutable.
jtenner
@jtenner
May 06 2016 18:38 UTC
Hang on.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:38 UTC
Ok
jtenner
@jtenner
May 06 2016 18:38 UTC
const Type & alwaysReferences(objectToRefernce);
OH wait
Abdullah A. Hassan
@voodooattack
May 06 2016 18:39 UTC
Not copy, reference
A reference is another kind of variable that differs slightly.
Another kind of variable*
jtenner
@jtenner
May 06 2016 18:40 UTC
alwaysReferences will permanently point to objectToReference
Abdullah A. Hassan
@voodooattack
May 06 2016 18:40 UTC
Yep
jtenner
@jtenner
May 06 2016 18:40 UTC
Okay.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:41 UTC
And if objectToReference goes out of scope and you access alwaysReferences, you're basically out of luck. Crash.
But that situation is hard to make happen.
You gotta do lofty things to get that to occur. :)
jtenner
@jtenner
May 06 2016 18:44 UTC
Hang on :)
Okay
That makes sense.
That is a constant pointer
Those are useful for Immutable collections right?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:46 UTC
You could say that.
Or static strings
jtenner
@jtenner
May 06 2016 18:47 UTC
That's obviously a better example, I was trying to think outside the box lol
I wasn't thinking about DOMStrings
or other stuff like that
I need to go to a meeting, but this was super helpful, will you be available in about 15 minutes?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:47 UTC
I think so
jtenner
@jtenner
May 06 2016 18:48 UTC
:)
Rares Golea
@rgolea
May 06 2016 18:49 UTC
Hahaha... Guys!!! My phone is so vibrating in my pocket that I fear people might start thinking the wrong way :)
can you chat code learning in PM?
thanks!
Abdullah A. Hassan
@voodooattack
May 06 2016 18:50 UTC
Yeah, sorry.
Rares Golea
@rgolea
May 06 2016 18:50 UTC
No worries :)
Abdullah A. Hassan
@voodooattack
May 06 2016 18:50 UTC
I thought we were alone :P
jtenner
@jtenner
May 06 2016 18:51 UTC
You should turn off notifications. I'm actually discussing how Nexus works...
but that's okay!
Abdullah A. Hassan
@voodooattack
May 06 2016 18:52 UTC
lol
jtenner
@jtenner
May 06 2016 18:52 UTC
(moves to a private chat)
Rares Golea
@rgolea
May 06 2016 18:52 UTC
Oh! Sorry! Haven't seen before the option on mobile...
Abdullah A. Hassan
@voodooattack
May 06 2016 18:53 UTC
Haha
Rares Golea
@rgolea
May 06 2016 18:53 UTC
You can keep discussing here, don't mind me
:)
Abdullah A. Hassan
@voodooattack
May 06 2016 18:53 UTC
Nah, it's ok, we're moving to a private chat
More suited to this anyway