These are chat archives for voodooattack/nexusjs

6th
May 2016
Abdullah A. Hassan
@voodooattack
May 06 2016 16:43
Oh wow
That will answer so many questions for anyone asking why nexus is inherently atomic.
jtenner
@jtenner
May 06 2016 16:44
LOL
They are trying to make the Primitives for SharedArrayBuffer
Abdullah A. Hassan
@voodooattack
May 06 2016 16:44
Yeah
jtenner
@jtenner
May 06 2016 16:44
I want it so badly.
Abdullah A. Hassan
@voodooattack
May 06 2016 16:45
Sooo bookmarked.
Thanks for finding that
jtenner
@jtenner
May 06 2016 16:45
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
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
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
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
  • SPIT TAKE *
oops
SPIT TAKE
Abdullah A. Hassan
@voodooattack
May 06 2016 16:47
lol
jtenner
@jtenner
May 06 2016 16:48
yeah.
that's crazy.
Abdullah A. Hassan
@voodooattack
May 06 2016 16:48
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
Have you considdered using WTF::ParkingLot lol
Abdullah A. Hassan
@voodooattack
May 06 2016 17:56
It's used internally by JSC
jtenner
@jtenner
May 06 2016 17:56
Oh.
The WTF namespace makes me lol every time.
Abdullah A. Hassan
@voodooattack
May 06 2016 17:56
hehe
yeah
jtenner
@jtenner
May 06 2016 17:56
They paid JSC to put up a WTF::ParkingLot
Abdullah A. Hassan
@voodooattack
May 06 2016 17:57
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
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
Sure
jtenner
@jtenner
May 06 2016 18:01
I'm prepared to read the source code.
shudders
Abdullah A. Hassan
@voodooattack
May 06 2016 18:01
Haha
Okay
jtenner
@jtenner
May 06 2016 18:02
I have the repo open
I'm looking at the src/ directory.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:02
Just don't mock my coding skills
jtenner
@jtenner
May 06 2016 18:02
I have no opinion on coding skills :)
Abdullah A. Hassan
@voodooattack
May 06 2016 18:02
hehe
jtenner
@jtenner
May 06 2016 18:02
What exactly are .h files? (general question)
Abdullah A. Hassan
@voodooattack
May 06 2016 18:02
I'm sure you will
jtenner
@jtenner
May 06 2016 18:02
It stands for header, I know this.
Is a header file like a C# interface?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:03
.h are the headers. That's where you declare stuff
jtenner
@jtenner
May 06 2016 18:03
What do you mean by declare stuff?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:04
Hang on. I need a keyboard to type this. Phone won't work for this
jtenner
@jtenner
May 06 2016 18:04
Hahaha. Thank you for your time.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:04
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
Great. They probably function exactly like interfaces
Abdullah A. Hassan
@voodooattack
May 06 2016 18:06
Something like that
jtenner
@jtenner
May 06 2016 18:06
.h files define WHAT functions show up in classes. right?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:06
You use headers to declare classes.. some of them are abstract (interfaces)
Yes
jtenner
@jtenner
May 06 2016 18:06
Oh okay.
the CPP files define the functions.
Can you show me a simple example
Abdullah A. Hassan
@voodooattack
May 06 2016 18:06
You can't define a function in a .cpp file without declaring it first in a .h
jtenner
@jtenner
May 06 2016 18:07
Can you actually define a full function in a .h file?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:09

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
Yeah that's an interface
Abdullah A. Hassan
@voodooattack
May 06 2016 18:09
You could, that'd inline it.
No, that's not an interface
jtenner
@jtenner
May 06 2016 18:09
void A::hello() attaches the function compile time, right?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:10
That's a regular class. an interface would have abstract methods
Yes
jtenner
@jtenner
May 06 2016 18:10
in that case, header files are more like a contract
not exactly the whole blueprint
Abdullah A. Hassan
@voodooattack
May 06 2016 18:10
Yeah, something like that
The header files have the declarations, the cpp files have the definitions.
jtenner
@jtenner
May 06 2016 18:11
What if you don't define A::hello() in the cpp file?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:11
You get an undefined reference error at link time.
jtenner
@jtenner
May 06 2016 18:11
Great. That makes sense to me.
Are you familiar with c#
Abdullah A. Hassan
@voodooattack
May 06 2016 18:12
I used to be.
jtenner
@jtenner
May 06 2016 18:12
Do namespaces function the same way?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:12
Yeah
There's one more thing.
jtenner
@jtenner
May 06 2016 18:13
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
A .cpp file compiles to an object file (.obj/.o depending on the compiler)
jtenner
@jtenner
May 06 2016 18:13
Yep.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:13
Directory structure is irrelevant.
Anyway, the compiled object files are then linked.
jtenner
@jtenner
May 06 2016 18:14
Cool.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:14
That's when you'd get the undefined reference error.
jtenner
@jtenner
May 06 2016 18:14
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
You put public: before them
No
jtenner
@jtenner
May 06 2016 18:15
 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
Yep
I define it inline
I'm lazy sometimes :P
jtenner
@jtenner
May 06 2016 18:16
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
Small/trivial code can go into the headers sometimes
jtenner
@jtenner
May 06 2016 18:16
It's basically up to the developer where the code goes.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:16
Whereupon the compiler will inline it
jtenner
@jtenner
May 06 2016 18:16
Does that make it faster?
Or is it just "i like it this way"
Abdullah A. Hassan
@voodooattack
May 06 2016 18:17
Yes, but that's irrelevant nowadays
jtenner
@jtenner
May 06 2016 18:17
So it's kindof both?
Neat.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:17
Most compilers can inline definitions as well
Nowadays I mean
It was much harder in the past
jtenner
@jtenner
May 06 2016 18:18
  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
The last is a destructor
jtenner
@jtenner
May 06 2016 18:18
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
For when an object is destroyed.
jtenner
@jtenner
May 06 2016 18:19
That's actually really neat.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:19
Haha
Yes
All classes manage their own memory.
jtenner
@jtenner
May 06 2016 18:19
I feel like such a noob. Thanks for being patient with me.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:20
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
 JSValueRef operator[](int index) { return myArguments[index]; }
Abdullah A. Hassan
@voodooattack
May 06 2016 18:20
That's the [] operator
x[1]
....would call that.
jtenner
@jtenner
May 06 2016 18:20
So this is an array, and you are overriding the syntax for array access
Abdullah A. Hassan
@voodooattack
May 06 2016 18:21
No, this is a class, and I'm giving it array semantics.
jtenner
@jtenner
May 06 2016 18:21
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
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
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
Aha
You got it right
jtenner
@jtenner
May 06 2016 18:22
    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
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
I think I don't understand what this means.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:24
Okay
Here we go
jtenner
@jtenner
May 06 2016 18:24
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
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
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
Yes
jtenner
@jtenner
May 06 2016 18:26
I remember this vaugely
Abdullah A. Hassan
@voodooattack
May 06 2016 18:26
*y = 10;
This changes x to 10
jtenner
@jtenner
May 06 2016 18:27
*y = 10;
x;
//10
Abdullah A. Hassan
@voodooattack
May 06 2016 18:27
Yep
jtenner
@jtenner
May 06 2016 18:27
that's neat.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:27
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
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
Yeah
You can use them to implement all kinds of crazy things
jtenner
@jtenner
May 06 2016 18:28
Linked lists
Abdullah A. Hassan
@voodooattack
May 06 2016 18:28
Linked lists, graphs, etc
jtenner
@jtenner
May 06 2016 18:28
Yep
Abdullah A. Hassan
@voodooattack
May 06 2016 18:28
Jinx :D
jtenner
@jtenner
May 06 2016 18:28
Hahaha
Abdullah A. Hassan
@voodooattack
May 06 2016 18:29
So you have pointers
And then you have const pointers
jtenner
@jtenner
May 06 2016 18:29

SO...

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

this defines how *y = 10; would operate

Abdullah A. Hassan
@voodooattack
May 06 2016 18:29
Yes
jtenner
@jtenner
May 06 2016 18:29
I should really say:
*args[x] = ...;
Abdullah A. Hassan
@voodooattack
May 06 2016 18:30
This both gives you the address and lets you dereference it
Awesome, correct.
jtenner
@jtenner
May 06 2016 18:30
I don't understand the last sentence
Abdullah A. Hassan
@voodooattack
May 06 2016 18:30
Now, as for const pointers.
jtenner
@jtenner
May 06 2016 18:30
gives you the address and lets you dereference it
before you move onto const
Abdullah A. Hassan
@voodooattack
May 06 2016 18:30
Okay
JSValueRef * x = args[0]; // taking the address
*x = ....;  // dereferencing 
*args[0] = ...; // also dereferencing
jtenner
@jtenner
May 06 2016 18:32
dereference means grab the location using the & symbol, right?
Abdullah A. Hassan
@voodooattack
May 06 2016 18:32
No, that's referencing
Dereferencing is accessing a pointer via *
jtenner
@jtenner
May 06 2016 18:32
OH I understood the concept first before the word.
Good.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:32
You sure you don't know C++ already? :P
jtenner
@jtenner
May 06 2016 18:32
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
Haha
Ready to move on?
jtenner
@jtenner
May 06 2016 18:33
You bet
Abdullah A. Hassan
@voodooattack
May 06 2016 18:35
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
Hang on.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:38
Ok
jtenner
@jtenner
May 06 2016 18:38
const Type & alwaysReferences(objectToRefernce);
OH wait
Abdullah A. Hassan
@voodooattack
May 06 2016 18:39
Not copy, reference
A reference is another kind of variable that differs slightly.
Another kind of variable*
jtenner
@jtenner
May 06 2016 18:40
alwaysReferences will permanently point to objectToReference
Abdullah A. Hassan
@voodooattack
May 06 2016 18:40
Yep
jtenner
@jtenner
May 06 2016 18:40
Okay.
Abdullah A. Hassan
@voodooattack
May 06 2016 18:41
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
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
You could say that.
Or static strings
jtenner
@jtenner
May 06 2016 18:47
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
I think so
jtenner
@jtenner
May 06 2016 18:48
:)
Rares Golea
@rgolea
May 06 2016 18:49
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
Yeah, sorry.
Rares Golea
@rgolea
May 06 2016 18:50
No worries :)
Abdullah A. Hassan
@voodooattack
May 06 2016 18:50
I thought we were alone :P
jtenner
@jtenner
May 06 2016 18:51
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
lol
jtenner
@jtenner
May 06 2016 18:52
(moves to a private chat)
Rares Golea
@rgolea
May 06 2016 18:52
Oh! Sorry! Haven't seen before the option on mobile...
Abdullah A. Hassan
@voodooattack
May 06 2016 18:53
Haha
Rares Golea
@rgolea
May 06 2016 18:53
You can keep discussing here, don't mind me
:)
Abdullah A. Hassan
@voodooattack
May 06 2016 18:53
Nah, it's ok, we're moving to a private chat
More suited to this anyway