• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

JeTmAn81

Member
Got very flustered at an exam. Was supposed to be an example for a power function as a small side part of a question, not necessarily important to the question itself. Sooo, I forgot to keep the base and just foolishly do this:
Code:
for(int i = 0; i < exp; i++)
{
    pow = pow * pow;
}
return pow;
Whyyyyy did I do this :(. So much shame coursing through my body right now.

tumblr_m287qhzkjs1r3d43kxs.gif

It's ok, I don't think that code would work right even if you set the base. There's no zero case, and you're doing extra multiplication.
 
Well I'm blindly moving to Seattle so likely a bigger company out there that could pay moving expenses at least until we get settled. The problem is I'm likely going to be going through the automated application process as I don't really know anyone out there and all resume templates I've been finding just list "X position @ company Y (20XX - 20XY) which isn't especially applicable to my situation (and probably for the better). I know what I want to list just not a good succinct format.

You could try going through the back door and trying to get in touch with some Seattle based devs via Twitter etc. for general tips and help.
 

Kieli

Member
Hey Gaf, just checking in to confirm a few things.

int i = (byte) 0xAB << 8; yields 0x00 00 AB 00 or 0xFF FF AB 00? If it's the latter, why is that a bad thing and why do we want to mask it.

i.e. int i = (someByte << 24) & 0xFF000000?
 

Makai

Member
Holy shit, Swift 3.0. This is unacceptable.

You are required to label all arguments you pass into a function. And even though they're named they have to be in the same order.

Code:
func function(parameterA: Int, parameterB: String, parameterC: Bool) -> Float {
    return 0.0
}

function(parameterA: 0, parameterB: "hello", parameterC: true)

Oh, but there's a workaround. You just have to put underscores in front of every parameter in the original defintion.

Code:
func function(_ parameterA: Int, _ parameterB: String, _ parameterC: Bool) -> Float {
    return 0.0
}

function(0, "hello", true)

What the fuck, Apple?
 

Somnid

Member
Holy shit, Swift 3.0. This is unacceptable.

You are required to label all arguments you pass into a function. And even though they're named they have to be in the same order.

Code:
func function(parameterA: Int, parameterB: String, parameterC: Bool) -> Float {
    return 0.0
}

function(parameterA: 0, parameterB: "hello", parameterC: true)

Oh, but there's a workaround. You just have to put underscores in front of every parameter in the original defintion.

Code:
func function(_ parameterA: Int, _ parameterB: String, _ parameterC: Bool) -> Float {
    return 0.0
}

function(0, "hello", true)

What the fuck, Apple?

I'm not opposed to requiring labels on all arguments. People who get very involved in programming (and most things really) love to make things overly terse because there's a lot of repetition involved and this usually seeps into language syntax and makes it much harder to adopt for novices. Languages should really be optimized for readability, not writability because the former is like 10x more common than the latter.

Now as for this particular solution, having labels and parameter names seems like overkill especially as the concepts are too confusingly similar. I understand labels are to help make it more fluent while the names are semantic but it doesn't seem like the gain is that much. The reason the ordering matters is because the labels aren't required to be unique, but since the style guide seems to dissuade duplicates I have no idea why they even allow it.
 

JeTmAn81

Member
Holy shit, Swift 3.0. This is unacceptable.

You are required to label all arguments you pass into a function. And even though they're named they have to be in the same order.

Code:
func function(parameterA: Int, parameterB: String, parameterC: Bool) -> Float {
    return 0.0
}

function(parameterA: 0, parameterB: "hello", parameterC: true)

Oh, but there's a workaround. You just have to put underscores in front of every parameter in the original defintion.

Code:
func function(_ parameterA: Int, _ parameterB: String, _ parameterC: Bool) -> Float {
    return 0.0
}

function(0, "hello", true)

What the fuck, Apple?

Doesn't Objective C make you do the same thing? I don't really mind labels but if they're required you should be able to reorder as you please or drop parameters entirely.
 
I had to do a Codility test for a data analyst position today, of all things. It consisted of a really easy SQL task, a modified FizzBuzz task and then a question about a linked list. I'd never even heard of a linked list before (I only know basic-intermediate Python, R and SQL) so I had to google the shit out of that. Sounds like they're not used often in Python anyway? I was able to come up with an inelegant solution to the problem, which was counting the length of the linked list (but with some caveats so it wasn't as simple as it sounds) so I was happy about that, but I was so confused why it was one of the tasks for a data analyst position.

Has anyone else had to do Codility tests? I've read a bunch of negative things about them online. My experience wasn't terrible but I'm a bit baffled by the tasks I was given.
 

digdug2k

Member
Holy shit, Swift 3.0. This is unacceptable.

You are required to label all arguments you pass into a function. And even though they're named they have to be in the same order.

Code:
func function(parameterA: Int, parameterB: String, parameterC: Bool) -> Float {
    return 0.0
}

function(parameterA: 0, parameterB: "hello", parameterC: true)

Oh, but there's a workaround. You just have to put underscores in front of every parameter in the original defintion.

Code:
func function(_ parameterA: Int, _ parameterB: String, _ parameterC: Bool) -> Float {
    return 0.0
}

function(0, "hello", true)

What the fuck, Apple?
The first parameter name isn't required ever. i.e.
Code:
function(0, parameterB: "hello", parameterC: true)

The _ is really just saying "this has no external name". i.e. by using it I think you're fucking over anyone who might want to use the name when calling the function. You should really only use it for things where the parameters are obvious and should never be named. i.e.
Code:
multiply(1, 2)
Swift has been this way since 1.0. It was my first time using named parameters much and I was excited to get to move them around at first, and frustrated when I couldn't. Then... life goes on.

Since it was asked, yes you can also drop parameters as long as they have defaults (but even then Swift recommends you move them to the end of the list).
 

Koren

Member
Doesn't Objective C make you do the same thing? I don't really mind labels but if they're required you should be able to reorder as you please or drop parameters entirely.
I think the last Python 3k take on arguments is quite an interesting one: when you create a function, you can choose between named arguments, or both methods (and even mix them), and if you chose to use named arguments, order don't matter.

I'm not opposed to requiring labels on all arguments. People who get very involved in programming (and most things really) love to make things overly terse because there's a lot of repetition involved and this usually seeps into language syntax and makes it much harder to adopt for novices. Languages should really be optimized for readability, not writability because the former is like 10x more common than the latter.
I'd argue that longer sentences also go against readability, so it's a dual-edge sword.

Many people think you should avoid triadic function and never use polyadic ones. Then required named arguments become a hurdle, since you'll have a lot of monoadic functions, and several diadic functions that commute... It's nice to have them, but at least make them an option when there's really no reason to use those (and since in this case the first one is an option, it's not that a bad design choice, I'd say).

I have no idea why they even allow it.
For functions where both arguments play the same role, add(some_element, some_element) ?

Hey Gaf, just checking in to confirm a few things.

int i = (byte) 0xAB << 8; yields 0x00 00 AB 00 or 0xFF FF AB 00?
If that's C, if I'm not mistaken, chars and unsigned chars are promoted to int and unsigned int for arithmetics.

So :
(uint8_t) 0xAB << 8 gives 00 00 AB 00 because AB is converted to 00 00 00 AB
(int8_t) 0xAB << 8 gives FF FF AB 00 because AB is converted to FF FF FF AB


If it's the latter, why is that a bad thing and why do we want to mask it.
i.e. int i = (someByte << 24) & 0xFF000000?
Not sure... The mask MAY be in case "int" isn't 32 bits (which is rare)
 

Somnid

Member
I'd argue that longer sentences also go against readability, so it's a dual-edge sword.

I think the complexity of the "sentence" is directly proportional to the logic. That is, if it's really long and difficult to describe or has a lot of parameters then it's probably not a good function. A code smell of sorts.

Many people think you should avoid triadic function and never use polyadic ones. Then required named arguments become a hurdle, since you'll have a lot of monoadic functions, and several diadic functions that commute... It's nice to have them, but at least make them an option when there's really no reason to use those (and since in this case the first one is an option, it's not that a bad design choice, I'd say).

For functions where both arguments play the same role, add(some_element, some_element) ?

In that case you'd omit the labels.

https://swift.org/documentation/api-design-guidelines/#argument-labels

Apple said:
Omit all labels when arguments can’t be usefully distinguished, e.g. min(number1, number2), zip(sequence1, sequence2).

In initializers that perform full-width type conversions, omit the first argument label, e.g. Int64(someUInt32)

When the first argument forms part of a prepositional phrase, give it an argument label. The argument label should normally begin at the preposition, e.g. x.removeBoxes(havingLength: 12).

Otherwise, if the first argument forms part of a grammatical phrase, omit its label, appending any preceding words to the base name, e.g. x.addSubview(y)

Label all other arguments.
 

MikeRahl

Member
I'm finally coming close to the end of a horrible project at work.

I have to create a 3d object using 3 2d representations of 3 of the faces (2 horizontal ones in the x-z plane and then 1 that overlaps then in the y-z plane). Once each of those 2d faces become 3d I have to calculate where they overlap/intersect and add or subtract them accordingly.

Once that is finished other objects are connected to it, which requires determining if it is actually valid, which is done by extending out the normal vector of the plane created by the connected face to make sure it is happening in a reasonable manner.

If anyone ever tries to tell you will never need calculus in programming kick them for me.
 

Koren

Member
I think the complexity of the "sentence" is directly proportional to the logic. That is, if it's really long and difficult to describe or has a lot of parameters then it's probably not a good function. A code smell of sorts.
I agree, and even said as much.

But honestly, I almost never read code on paper anymore, and any decent IDE will give you the parameters names when you hover the mouse or put the caret inside the function. So the advantage of having them interleaved with the arguments can be discussed.

I mean,
Code:
foo( topos(x, y), tospd(vx, vy) )
or
Code:
foo(pos=topos(coordx=x, coordy=y), spd=tospd(spdx=vx, spdy=vy) )
or
Code:
apos = topos(coordx=x, coordy=y)
aspd = tospd(spdx=vx, spdy=vy)
foo(pos=apos, spd=aspd)
?

When I was reading functions on paper, I would have said that the third was (usually) the better, I had even the habit to put /* */ comments inside some function calls in C to explain the parameters.

Now, with calltips and similar IDE mechanisms, I'm not that sure anymore.

I can see why some languages want you to specify the parameters names, but I'd say it can be subjet of debate. Even more when the arguments have meaningful names, and the functions are straightforward...
 

Somnid

Member
But honestly, I almost never read code on paper anymore, and any decent IDE will give you the parameters names when you hover the mouse or put the caret inside the function. So the advantage of having them interleaved with the arguments can be discussed.

I mean,
Code:
foo( topos(x, y), tospd(vx, vy) )
or
Code:
foo(pos=topos(coordx=x, coordy=y), spd=tospd(spdx=vx, spdy=vy) )
or
Code:
apos = topos(coordx=x, coordy=y)
aspd = tospd(spdx=vx, spdy=vy)
foo(pos=apos, spd=aspd)
?

When I was reading functions on paper, I would have said that the third was (usually) the better, I had even the habit to put /* */ comments inside some function calls in C to explain the parameters.

Now, with calltips and similar IDE mechanisms, I'm not that sure anymore.

I can see why some languages want you to specify the parameters names, but I'd say it can be subjet of debate. Even more when the arguments have meaningful names, and the functions are straightforward...

Here the labels and the names serve slightly different purposes, an example might be

Code:
func slice(from index: Int){
   ....
}
Object.slice(from: 3)

Where index is meaningful in the function but less meaningful to the outside because the context isn't there. But if you named it "from" is not a very good variable name inside the function because it really doesn't give a good indication of what it is. Makes sense to me, and then you can ask why not allow Object.slice(3) since you can easily infer it, but I think requiring it stops devs from being lazy about it because if you don't use it there's no benefit to those labels.

After watching some of the WWDC stuff it seems pretty clear Apple wants Swift to be easy to adopt for novice users which is rarely a concern in most languages used today especially past the first release. So understanding that as a goal, I think this is perfectly inline.

They also threw out incrementors and decrementors for the same reason, they felt it was less consistent and more confusing to novice users.
 

Koren

Member
Here the labels and the names serve slightly different purposes, an example might be

Code:
func slice(from index: Int){
   ....
}
Object.slice(from: 3)

Where index is meaningful in the function but less meaningful to the outside because the context isn't there. But if you named it "from" is not a very good variable name inside the function because it really doesn't give a good indication of what it is. Makes sense to me, and then you can ask why not allow Object.slice(3) since you can easily infer it, but I think requiring it stops devs from being lazy about it because if you don't use it there's no benefit to those labels.

After watching some of the WWDC stuff it seems pretty clear Apple wants Swift to be easy to adopt for novice users which is rarely a concern in most languages used today especially past the first release.
Most languages designed with beginners in mind failed in the past, though.

I agree that in many cases named parameters are great. I'm just reluctant to see it "forced" by the language (Python is fine for this, as I said). Or if you really want to make a push towards this, allow a decent opt-out. I don't even think that's the first offender with beginners.

But again, it's a matter of taste, I'm not strongly against this, especially since I think named parameters are often nice.
 
If you think this is what happened, then indeed the JS ecosystem must be brittle and chaotic to you. Luckily, this is not what happened at all.

The whole "issue" was about people realizing that NPM allowed deletion of modules, which, weirdly enough, never really came up during all these years of NPM getting more and more popular. The community learned from it, and that is it.

Yet, here we are, people taking away the lesson that "that is all JS is about", which is *very* funny to think about. Especially considering:

1. we are talking about a module repository
2. the module did not break
3. dependency breaking has nothing to do with javascript program breaking.

But alright.
...oh. I guess I didn't know. Thanks.
 

JesseZao

Member
I'm finally coming close to the end of a horrible project at work.

I have to create a 3d object using 3 2d representations of 3 of the faces (2 horizontal ones in the x-z plane and then 1 that overlaps then in the y-z plane). Once each of those 2d faces become 3d I have to calculate where they overlap/intersect and add or subtract them accordingly.

Once that is finished other objects are connected to it, which requires determining if it is actually valid, which is done by extending out the normal vector of the plane created by the connected face to make sure it is happening in a reasonable manner.

If anyone ever tries to tell you will never need calculus in programming kick them for me.

Well I don't know what you expected if you're working with visual objects. It's going to involve math.
 

Gurrry

Member
Im having some trouble with my next project assignment for my intro computer science class. I really wish our professor taught us more instead of just pointing us to his website and telling us to "figure it out". Kinda regret paying for a class when all he does is point us to the internet.

Anyways, the goal is to have the user populate a list of 20 comments. If any of the comments they enter contain a key from a dictionary that they populated earlier in the program, I need to add +1 to their comments.

Im having trouble figuring out how to do this. Im obviously going to use the "in" function that python has, but after that im kind of clueless.

The issues im having are from lines 47 and beyond. I basically just need to find a way to output their total # of comments per each employee.


Any tips?
 

Ahnez

Member
Can anyone tell me how I would iterate through a pointer char in a struct that is const in C?

You mean, there's a struct, and one of the members is a const char * , and you want to iterate through its characters - is this what you meant?

Code:
#include<stdio.h>
#include<string.h>

int main(){
    int len, i;
    struct str{
       const char *string; 
    } b;
    
    b.string = "characters";
    len = strlen(b.string);

    for(i=0; i<len; i++)
        printf("%c", b.string[i]);

    printf("\n");

    return 0;   
}
 

already in use

Neo Member
Im having some trouble with my next project assignment for my intro computer science class. I really wish our professor taught us more instead of just pointing us to his website and telling us to "figure it out". Kinda regret paying for a class when all he does is point us to the internet.

Anyways, the goal is to have the user populate a list of 20 comments. If any of the comments they enter contain a key from a dictionary that they populated earlier in the program, I need to add +1 to their comments.

Im having trouble figuring out how to do this. Im obviously going to use the "in" function that python has, but after that im kind of clueless.

The issues im having are from lines 47 and beyond. I basically just need to find a way to output their total # of comments per each employee.

http://pastebin.com/VPHbTT4i

Any tips?

I'd recommend having the user enter comments as they enter each employee name and then store those comments in a dictionary. So something like this:
Code:
while (userInput == "y"):
    empName = input("Enter the employee's first and last name:")
    empDealership = input("Enter the dealership they work at:")
    commentsList = []
    comments = input("Do you want to enter salesperson comments for {}? (y/n) ".format(empName))
    while comments == 'y':
            commentsList.append(input("Enter comment:"))
            comments = input("More comments to enter? (y/n)")
    empInfo[(empName, empDealership)] = commentsList
    userInput = input("Do you have more names to enter? (y/n)")
Now the number of comments each employee received is just the length of their value in the dictionary.
 

V_Arnold

Member
...oh. I guess I didn't know. Thanks.

Sorry if I came off a bit arrogant or offensive. I understand that Javascript itself is needlessly confusing and has plenty of programming traps for those who have not yet "mastered" the confusing labyrinths of its system.

But there is a difference between THAT and a subgroup of programming community ready to pounce on JS any chance they get. It was very frustrating to read /r/programming, for example, during those weeks.

At the end of the day, the whole NPM debate goes back to a simple question: is a curated, maintained repository better than a "free for all" wild wild west? Both has its pros and cons. However, nothing stops seasoned JS devs from creating a new curated list of "okay to use" JS libraries while allowing the existence of NPM - but if NPM itself were restriicted, tht opposite just would not be possible.
 

Gurrry

Member
I'd recommend having the user enter comments as they enter each employee name and then store those comments in a dictionary. So something like this:
Code:
while (userInput == "y"):
    empName = input("Enter the employee's first and last name:")
    empDealership = input("Enter the dealership they work at:")
    commentsList = []
    comments = input("Do you want to enter salesperson comments for {}? (y/n) ".format(empName))
    while comments == 'y':
            commentsList.append(input("Enter comment:"))
            comments = input("More comments to enter? (y/n)")
    empInfo[(empName, empDealership)] = commentsList
    userInput = input("Do you have more names to enter? (y/n)")
Now the number of comments each employee received is just the length of their value in the dictionary.

I think this is what Im going to do. I was refraining from doing it this way because his requirements and the way they are spelled out seem like he doesnt want us to do it that way... but if it accomplishes the same thing, I dont see why I wouldnt get full credit.

Thanks for the help man, it means alot to me

edit: Actually, now that I read his requirements, I dont think I can do it this way.
 

already in use

Neo Member
I think this is what Im going to do. I was refraining from doing it this way because his requirements and the way they are spelled out seem like he doesnt want us to do it that way... but if it accomplishes the same thing, I dont see why I wouldnt get full credit.

Thanks for the help man, it means alot to me

edit: Actually, now that I read his requirements, I dont think I can do it this way. Here is what he has spelled out for us:

Ok, well that's a little awkward. Try something like this:

Code:
commentDict = {}
for empName in empInfo:
	commentDict[empName] = 0
	for comment in commentList:
		if empName in comment:
			commentDict[empName] += 1

Also since empName has to be in the comment, when you prompt for the comment you may also want to prompt for the employee being commented. Something like this:

Code:
comments = input("Do you want to enter salesperson comments? (y/n) ")
while(comments == "y"):
    name = input("Enter the name of the employee being complimented: ")
    content = input("Enter comment: ")
    commentsList.append("{}: {}".format(name, content))
    comments = input("More comments to enter? (y/n)")
 

Gurrry

Member
Ok, well that's a little awkward. Try something like this:

Code:
commentDict = {}
for empName in empInfo:
	commentDict[empName] = 0
	for comment in commentList:
		if empName in comment:
			commentDict[empName] += 1

Also since empName has to be in the comment, when you prompt for the comment you may also want to prompt for the employee being commented.

Thank you, im gonna try this now. It was giving me a headache trying to figure out how the "in" function works because when I was testing it myself before, it wouldnt work unless the only word in the comment was their name.

Im gonna test this stuff and ill post back with the results.

Thank you again. Youre saving me from having a brutal migraine today, lol.
 

Gurrry

Member
Alright, so ive got all the dictionary to where it recognizes the names and adds to their total, but now I can only get it to print out the # of compliments for 1 person, not the rest.

Is there something wrong with this syntax that is skipping over everyone but one of the employees?

if name == commentDict[empName]:
print("Number of Compliments:" + str(commentDict[empName]))
 

Gurrry

Member
Ahhh shit, im so dumb. "empName" couldnt be defined because it wasnt in that loop. it needed to be "name" not empName.

ughghghghghhghghghghghg

loops and dictionaries can go straight to hell today!

thank you for all the help guys. id be failing this class without input from you all. it really is amazing how helpful everyone here is with everything. you are all seriously life savers.
 
Ahhh shit, im so dumb. "empName" couldnt be defined because it wasnt in that loop. it needed to be "name" not empName.

ughghghghghhghghghghghg

loops and dictionaries can go straight to hell today!

thank you for all the help guys. id be failing this class without input from you all. it really is amazing how helpful everyone here is with everything. you are all seriously life savers.

Haha, come to the static side! It's much warmer over here.
 

MikeRahl

Member
Well I don't know what you expected if you're working with visual objects. It's going to involve math.

I knew what I was getting into when I started the project.The problem was I did but the Project Sponsors really didn't. The plane projection stuff kind of took me by surprise but was by far the best way to do things so that wasn't a big deal once all the math came out.

The fact that the convention for CAD is that all points are CCW also helped immensely

Also doesn't help that ~90% of the projects done in house here are generally reports or data-entry type programs.

Also not helping... the poorly translated from German document that outlines the file format that I am converting, and the non-existent documentation for how the data needs to end up in the end.
 
I feel like I'll have no chance in the marketplace. I'm doing well in my CS courses, but another student linked his github and I've no fucking clue how to half the shit he's done. If the average person is more like him and less like me, I've no chance.
 

Kalnos

Banned
I feel like I'll have no chance in the marketplace. I'm doing well in my CS courses, but another student linked his github and I've no fucking clue how to half the shit he's done. If the average person is more like him and less like me, I've no chance.

Most people don't have some crazy active GitHub, or even a GitHub at all, don't worry. I would just try to be ambitious with your class projects and maybe have one neat pet project before you graduate. I had no GitHub profile when I landed my co-op in 09 or my first job like 5 years ago. I barely have one now.

There's a weird notion in the programming community that you must constantly be doing side projects with your free time and it's bullshit.
 
I feel like I'll have no chance in the marketplace. I'm doing well in my CS courses, but another student linked his github and I've no fucking clue how to half the shit he's done. If the average person is more like him and less like me, I've no chance.
The average programmer is more like you. And hey, there is nothing wrong with going the enterprise route and going for the steady paycheck doing Java or c#. At least that way you can avoid the madness that is web development and JavaScript.
 
Thanks for the reassurance guys.

The average programmer is more like you. And hey, there is nothing wrong with going the enterprise route and going for the steady paycheck doing Java or c#. At least that way you can avoid the madness that is web development and JavaScript.

Speaking of web dev and JS... I need some help with JS right now.

Code:
function makeButtons()
{
	var docbod = document.getElementsByTagName("body");
	var bTypes = ["Up", "Down", "Left", "Right", "Mark Cell"] //button types
	
	for (var i = 0; i < 5; i++) //create buttons
	{
		var bton = document.createElement('button'); //make button
		
		bton.appendChild(document.createTextNode(bTypes[i])); //append type to button as text
		
		if (bTypes[i] != "Mark Cell")
		{
			bton.addEventListener("click", moveCell);
		}
		docbod[0].appendChild(bton);
	}
	
};

function moveCell(direction)
{	
	console.log(direction);
	console.log("Hello World"); 
}

I want to have buttons on my webpage. I'm testing giving them functionality with logging to console.

The problem right now is that when I do bton.addEventListener("click", moveCell), and then press a button, there's no directional information. So console cant log direction.

If I try The problem right now is that when I do bton.addEventListener("click", moveCell(bTypes))

then I don't append "function + desired parameter when you are pressed!" to the button. Instead every time that loop makes a button it simply calls moveCell. So the console log will be Up, Hello World, etc... and then the buttons are non-functional.

How do I accomplish what I want to accomplish here? How do I tell the buttons to do "THIS FUNCTION + THIS PARAMETER" when clicked?

edit:

Code:
bton.addEventListener("click", function(){moveCell(bTypes[i]);});

ALMOST works... but trying to log direction leads to undefined as the result.
 
So idk if this is the "best" way to do it but this worked!

Code:
	for (var i = 0; i < 5; i++) //create buttons
	{
		var bton = document.createElement('button'); //make button
		
		function getDirection(x)
		{var dir = bTypes[x];
		
		bton.appendChild(document.createTextNode(bTypes[i])); //append type to button as text
		
		if (bTypes[i] != "Mark Cell")
		{
			bton.addEventListener("click", function(){moveCell(dir);});
		}
		docbod[0].appendChild(bton);
		};
		
		getDirection(i);
	}
 

D4Danger

Unconfirmed Member
you're not getting any direction information because you're not calling moveCell with any parameters. You can use the .bind() method to do this the way you're doing it.

Code:
bton.addEventListener("click", moveCell.bind(null, bTypes[i]);

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind

you also don't need to use createTextNode you can just do

Code:
bton.textContent = bTypes[i]

https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent

Yeah, I knew that not passing with parameters would make it devoid of directional information. I was also having a problem with trying to pass the direction directly, so I figured I'd cover both cases in my initial inquiry.

Thank you for both of those links. Is there any possible difference between textContent and createTextNode?
 

D4Danger

Unconfirmed Member
Not that I'm aware of. I'm sure somebody will prove me wrong though because there's probably some bug somewhere on some browser.
 
Top Bottom