Open Side Menu Go to the Top
Register
Programming homework and newbie help thread Programming homework and newbie help thread

08-11-2016 , 02:35 PM
Quote:
Originally Posted by daveT
Well sure, classes are a property of the global space, and it makes sense that they can be defined anywhere.
i meant methods within classes. which are, essentially, functions in their own namespace. most likely you take hoisting for granted as a feature in this context...

Quote:
Also, JS doesn't have namespaced files yet, right?
if you use node it does. and you can still use node and this feature when building for the web, you just have a build step to create your final file through something like browserify or webpack. i actually much prefer this method of namespacing even over ruby.


Quote:
Would you still put the one-off functions at the bottom if you could push all that to an external file?
yes, assuming the functions were context-specific helpers that wouldn't be re-used, rather than generic utility functions which could be re-used. It's really a nice feature. You can even use within functions themselves, if *they* need a little helper function.

here's a random example from something i wrote yesterday:

Code:
function restrictMenu() {
    return m('div', {class: 'fade-in'}, [
      m('h2', 'Restrict what items guests can order?'),
      radioBtn('Yes, restrict what guests can order', 'restrict', ctrl.restrictMenu),
      radioBtn('No, guests can order anything', 'norestrict', ctrl.restrictMenu),
      ctrl.restrictMenu() == 'restrict' ? restrictMsg() : null
    ]);
    
    function restrictMsg() {
      return m('div', {class: 'fade-in'}, 
        "* You'll be able to enter your restrictions on the next page");
    }
  }
Programming homework and newbie help thread Quote
08-12-2016 , 01:35 AM
Working on this: http://cs.boisestate.edu/~jhyeh/cs42...mer16/lab3.pdf
(due in 24.5 hrs, lol)

So far I have this:


From here, I was planning on iterating through the vertices in my graph and turning those with more than one incoming edge into a "dummy vertex" that then lead into the real vertex.

But now I just re-read the instructions and I'm freaking out a little bit. I'm not sure if I did this right so far. My output is more of a "real graph" than this event graph thing.
Programming homework and newbie help thread Quote
08-12-2016 , 03:12 AM
Thanks for your answer gaming_mouse.

***

There is more to add about Zed Shaw. I respect the guy and his passion, but I don't agree with the approach of the Learn the Hard Way series. The problems are, as I recall, sort of "how do you break this?" while I think it is better to "build this from scratch." It isn't like your first programs, although simple, won't be bug-ridden so much you won't need time to fix your own mistakes, plus you get the bonus of figuring out how to approach building a program (no matter how bad it is).

Watching him defend his evisceration of K&R is... sigh, and I'll leave the research to those who are interested.

That's an ad hominem, but just pointing out that he isn't the end-all be-all of programming opinions, which absolutely includes his statements on Python3 (even back then, IMO), vim, emacs, etc. I just think there are many better sources out there to learn Python and programming in general.

I guess this should show Zed's interesting advice, at times:

An IDE, or "Integrated Development Environment" will turn you stupid. They are the worst tools if you want to be a good programmer because they hide what's going on from you, and your job is to know what's going on. They are useful if you're trying to get something done and the platform is designed around a particular IDE, but for learning to code C (and many other languages) they are pointless.

... to justify his opinion further, he goes on into playing guitar...

Many people do it this way, but if you want to know what you're playing, then tablature is pointless....

IDEs are like tablature. Sure, you can code pretty quickly, but you can only code in that one language on that one platform. This is why companies love selling them to you. They know you're lazy, and since it only works on their platform they've got you locked in because you are lazy.

The way you break the cycle is you suck it up and finally learn to code without an IDE. A plain editor, or a programmer's editor like Vim or Emacs, makes you work with the code. It's a little harder, but the end result is you can work with any code, on any computer, in any language, and you know what's going on.


http://c.learncodethehardway.org/book/ex0.html

I guess his biker boy writing style works for a lot of people, but at the end of the day, you have to think for yourself. There isn't any good reason to inject this sort of opinion on people, especially those who are using this material to start out in programming.

What he doesn't tell you is that a lot of guitar music is created by guitarists who don't know how to read music at all, and their music is actually transcribed by pianists, lol.
Programming homework and newbie help thread Quote
08-12-2016 , 04:01 AM
Quote:
Originally Posted by Ryanb9
Working on this: http://cs.boisestate.edu/~jhyeh/cs42...mer16/lab3.pdf
(due in 24.5 hrs, lol)

So far I have this:


From here, I was planning on iterating through the vertices in my graph and turning those with more than one incoming edge into a "dummy vertex" that then lead into the real vertex.

But now I just re-read the instructions and I'm freaking out a little bit. I'm not sure if I did this right so far. My output is more of a "real graph" than this event graph thing.
What is getGraphFromGraphData supposed to do? Is it supposed to convert a int[][] to an activity node graph or to an event node graph? Because when you say: "From here, I was planning on iterating through the vertices in my graph and turning those with more than one incoming edge into a "dummy vertex" that then lead into the real vertex." It sounds like you're still going to transform it event node, but when you say: "My output is more of a "real graph" than this event graph thing." It sounds like you already expect it to be event node.
Programming homework and newbie help thread Quote
08-12-2016 , 04:57 AM
Quote:
Originally Posted by Mr.mmmKay
What is getGraphFromGraphData supposed to do? Is it supposed to convert a int[][] to an activity node graph or to an event node graph? Because when you say: "From here, I was planning on iterating through the vertices in my graph and turning those with more than one incoming edge into a "dummy vertex" that then lead into the real vertex." It sounds like you're still going to transform it event node, but when you say: "My output is more of a "real graph" than this event graph thing." It sounds like you already expect it to be event node.
All it does is turn the 2d array into an object-oriented implementation of the same thing:



At the time I posted the picture you are talking about, the only class for edges was the "Edge" class. Since then (in the last 2 min) I decided to split this class into 2: outgoing edges and incoming edges so that each vertex can know what edges it has going to another vertex as well as what edges it has incoming from another vertex.

I think that once I implement incoming/outgoing edges I should be able to make the "dummy vertex's" that are described in the documentation / handout for this assignment.

Not sure though.
Programming homework and newbie help thread Quote
08-12-2016 , 05:24 AM
Yeah, you should be able to create a dummy vertex for every vertex in the activity-node graph which has more than one incoming vertex
Programming homework and newbie help thread Quote
08-12-2016 , 05:39 AM
Quote:
Originally Posted by Mr.mmmKay
Yeah, you should be able to create a dummy vertex for every vertex in the activity-node graph which has more than one incoming vertex
Nice. Okay thanks, I'll finish it in the morning then.
Programming homework and newbie help thread Quote
08-12-2016 , 11:14 AM
Quote:
Originally Posted by daveT
Thanks for your answer gaming_mouse.

***

There is more to add about Zed Shaw. I respect the guy and his passion, but I don't agree with the approach of the Learn the Hard Way series. The problems are, as I recall, sort of "how do you break this?" while I think it is better to "build this from scratch." It isn't like your first programs, although simple, won't be bug-ridden so much you won't need time to fix your own mistakes, plus you get the bonus of figuring out how to approach building a program (no matter how bad it is).

Watching him defend his evisceration of K&R is... sigh, and I'll leave the research to those who are interested.

That's an ad hominem, but just pointing out that he isn't the end-all be-all of programming opinions, which absolutely includes his statements on Python3 (even back then, IMO), vim, emacs, etc. I just think there are many better sources out there to learn Python and programming in general.

I guess this should show Zed's interesting advice, at times:

An IDE, or "Integrated Development Environment" will turn you stupid. They are the worst tools if you want to be a good programmer because they hide what's going on from you, and your job is to know what's going on. They are useful if you're trying to get something done and the platform is designed around a particular IDE, but for learning to code C (and many other languages) they are pointless.

... to justify his opinion further, he goes on into playing guitar...

Many people do it this way, but if you want to know what you're playing, then tablature is pointless....

IDEs are like tablature. Sure, you can code pretty quickly, but you can only code in that one language on that one platform. This is why companies love selling them to you. They know you're lazy, and since it only works on their platform they've got you locked in because you are lazy.

The way you break the cycle is you suck it up and finally learn to code without an IDE. A plain editor, or a programmer's editor like Vim or Emacs, makes you work with the code. It's a little harder, but the end result is you can work with any code, on any computer, in any language, and you know what's going on.


http://c.learncodethehardway.org/book/ex0.html

I guess his biker boy writing style works for a lot of people, but at the end of the day, you have to think for yourself. There isn't any good reason to inject this sort of opinion on people, especially those who are using this material to start out in programming.

What he doesn't tell you is that a lot of guitar music is created by guitarists who don't know how to read music at all, and their music is actually transcribed by pianists, lol.
I was thinking about this the other day and IDEs are pretty much a part of the programming language. not sure that is a bad thing. I'm not sure that he is correct you can use an IDE "without knowing what is going on."
Programming homework and newbie help thread Quote
08-12-2016 , 11:43 AM
I'm not knowledgeable enough to have a conversation on IDEs, but I don't agree that the IDE is part of the language. The IDE is interchangeable with other IDEs and, usually, a basic text editor, but the language is not interchangeable.

In fairness, Shaw is talking about C, which is a low level language. He's saying that you may as well go as close the metal as possible, and suggesting that you don't use an IDE so that you have to put in the effort to get all the details.
Programming homework and newbie help thread Quote
08-12-2016 , 11:57 AM
It's a huge generalisation to talk about IDEs with and without languages. Writing C without an IDE is presumably fine. Writing a .NET language without Visual Studio is a huge handicap.
Programming homework and newbie help thread Quote
08-12-2016 , 11:59 AM
In all honesty the correct opening chapter to "Learn C the hard way" should be "Hi, I know you came here wanting to learn C, but you should learn a modern language instead. Kthxbye".
Programming homework and newbie help thread Quote
08-12-2016 , 02:46 PM
^^^

Bah, C is still used extensively in embedded programming. Although I much prefer C++ even for that.
Programming homework and newbie help thread Quote
08-12-2016 , 02:56 PM
Quote:
Originally Posted by daveT
I'm not knowledgeable enough to have a conversation on IDEs, but I don't agree that the IDE is part of the language. The IDE is interchangeable with other IDEs and, usually, a basic text editor, but the language is not interchangeable.

In fairness, Shaw is talking about C, which is a low level language. He's saying that you may as well go as close the metal as possible, and suggesting that you don't use an IDE so that you have to put in the effort to get all the details.
ya, I guess I should say that for some languages, like C# and Java, understanding how to use the IDE are fundamental aspects of using the language. So much so that, imo, they are simply a part of the language.

I mean, if you want to write a program with C#, you gotta know how to use Visual Studio.
Programming homework and newbie help thread Quote
08-12-2016 , 03:12 PM
Quote:
Originally Posted by ChrisV
In all honesty the correct opening chapter to "Learn C the hard way" should be "Hi, I know you came here wanting to learn C, but you should learn a modern language instead. Kthxbye".
I put C up there as one of the most fun and mind-expanding languages you can ever learn, even a notch above Lisp, but to each their own.
Programming homework and newbie help thread Quote
08-12-2016 , 10:10 PM
Quote:
Originally Posted by daveT
I put C up there as one of the most fun and mind-expanding languages you can ever learn, even a notch above Lisp, but to each their own.
i wonder if this has to do with the order in which you learned them.

i think C can be mind expanding for people who don't know about hardware and implementation -- "oh, so that's how this works under the hood" type of aha moments.

lisp (and other good high level languages) are mind expanding from the other direction: "oh, all this nonsense about machines and registers is just an arbitrary fact of history, programming is really about expressing human thought"

the latter is far more interesting to me, but i can appreciate both.
Programming homework and newbie help thread Quote
08-12-2016 , 10:42 PM
Quote:
Originally Posted by gaming_mouse
i wonder if this has to do with the order in which you learned them.
It probably is. C was the first language I learned seriously and there were lots of "a ha" moments in there, I loved it (particularly due to the context in which I learned it - there was this MUD I used to play in high school that was written in C, that I spent hundreds of hours in, and then they released the source code and it was like I finally got to figure out how everything worked). I remember studying Lisp in a Programming Languages course in college and struggling with it a bit and not enjoying it all that much. Then we studied Prolog and I wanted to kill myself.
Programming homework and newbie help thread Quote
08-13-2016 , 03:23 AM
Prolog confirmed the nut low.
Programming homework and newbie help thread Quote
08-13-2016 , 02:45 PM
Quote:
Originally Posted by gaming_mouse
i wonder if this has to do with the order in which you learned them.

i think C can be mind expanding for people who don't know about hardware and implementation -- "oh, so that's how this works under the hood" type of aha moments.

lisp (and other good high level languages) are mind expanding from the other direction: "oh, all this nonsense about machines and registers is just an arbitrary fact of history, programming is really about expressing human thought"

the latter is far more interesting to me, but i can appreciate both.
I don't know if the order mattered much at all. They are both interesting in their own right because they are both very small and simple languages, but they aren't easy languages to learn. You can't take someone who is using either Lisp or C and for 3 years and pretend that someone who started 6 months prior are equivalent in understanding and ability. You have a small collection of stuff and that's about all you get, so they are both very focused, but they are shockingly powerful once you start to get it.

This perspective shouldn't be surprising coming from me, as I tend to attract to languages that are very small (SQL).
Programming homework and newbie help thread Quote
08-18-2016 , 08:12 PM
Quote:
Originally Posted by goofyballer
Then we studied Prolog and I wanted to kill myself.
I studied Prolog too. If nothing else it left me with one of my favourite programming jokes:

How many Prolog programmers does it take to screw in a lightbulb?

Yes.
Programming homework and newbie help thread Quote
08-19-2016 , 07:45 PM
Quote:
Originally Posted by gaming_mouse
i think C can be mind expanding for people who don't know about hardware and implementation -- "oh, so that's how this works under the hood" type of aha moments.
My first C looked like this. Can you spot the error?

Code:
typedef struct { int x; int y; } point;

	point *p = points;
	do
	{
		// do something with *p
		p += sizeof(point);
	} while (--count);
Programming homework and newbie help thread Quote
08-19-2016 , 08:12 PM
That's an easy mistake to make, incrementing your pointer more than you intend.
Programming homework and newbie help thread Quote
08-20-2016 , 09:26 AM
Quote:
Originally Posted by skario
My first C looked like this. Can you spot the error?

Code:
typedef struct { int x; int y; } point;

	point *p = points;
	do
	{
		// do something with *p
		p += sizeof(point);
	} while (--count);
I haven't coded in c in over a decade but I'm guessing you lose your data cause you don't store a reference to head before iterating?

Oh, and in pointer arithmetic you use the type size implicitly. So you're jumping sizeof(point) times in each iteration.

Last edited by Wolfram; 08-20-2016 at 09:31 AM.
Programming homework and newbie help thread Quote
08-20-2016 , 11:17 AM
Quote:
Originally Posted by Wolfram
ter arithmetic you use the type size implicitly. So you're jumping sizeof(point) times in each iteration.
Yeah I came from x86 assembly so I didn't know C had smart pointers.
Programming homework and newbie help thread Quote
09-06-2016 , 07:47 PM
I'm getting a strange error while using Visual Studio 2015 for C++ that I have never seen before. I'm further baffled because my program was working fine before this, I might have made some extremely minor changes the exact nature of which I can't recall, and now I'm getting this error. The error says "Debug Assertion Failed!" and says Expression: (L" Buffer too small" &&0), and directs me to line 50. Here is some of the code in question:

Code:
void getData(charArray_t emp, doubleArray_t empData, int rows)
{
	ifstream infile;
	infile.open("Assignment1Data.txt");
	char tempArray[20];

	if (!infile)
	{
	    cout << "There was an error opening the file. The program will terminate." << endl;
	}

	while (!infile.eof())
	{
		for (int z = 0; z < rows; z++)
		{
			infile.getline(emp[z], 15, ' ');
			strcat_s(emp[z], ", ");
			infile.getline(tempArray, 15, ' ');
			strcat_s(emp[z], tempArray);
		}
	    //for (int x = 0; x < 2; x++)
	   // {
			//infile >> empData[z][x];
		//}
			
		infile.ignore(9, '\n');
	}
}
Line 50 corresponds to the beginning of the for loop that IS NOT commented out. Any idea what is going on here? I have no idea what's going on here and like I said it worked fine a very short time ago.
Programming homework and newbie help thread Quote
09-06-2016 , 08:08 PM
First off, your program doesn't make much sense. If there are only $rows records in the file, then there's no point in the outer while loop. If there's more than that, then you're going to be throwing away all the data except the last set.

My guess is that you have either passed in a null value for "emp" or that one of emp's values is null. The error is coming from strcat_s - I don't know which one but since tempArray looks OK, probably not that one.
Programming homework and newbie help thread Quote

      
m