• 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

pompidu

Member
gonna try to look for database jobs when im done with school. besides sql and php what other languages or skills should I be teaching myself?
 
Here in Philadelphia the job market is on fire. I have my resume on my LinkedIn and on Dice.com, and despite it saying "Not currently seeking new employment" on my profile on recruiters from both places people won't stop calling me trying to get me go on interviews. From one recruiter alone I get an email a week with no less than 5 job openings. Now, I have some good bullet points on my resume (J2EE, Spring, SQL Server, UI and Architecture experience, etc), but I don't think it's solely that. People are calling me about jobs based on an old Monster.com resume I posted when I was right out of college, trying to get me entry level stuff.

I haven't been paying close attention like I probably should have whilst I shored up my resume, but this is excellent news. I graduate this year and I can easily commute into philly on account of the fact that I live near a patco station, so to hear there are a lot of employers seeking entry level is alleviating some stress I had about this whole job thing.
 
Frankly, I think Java is painful no matter what you compare it to.
I don't deal much with OOP but clearly Scala is one of the better languages to do that in. I also agree that it manages to mix OOP and FP quite nicely.
I kind of disagree. A beginner who starts with a functional language, like with the legendary SICP course, has no problem doing non-trivial things with it because they have no bad imperative instincts to fight. Arguably, allowing mutable state makes a lot of things harder because you must keep track of how the computation proceeds over time.

The thing I like the least about Scala is its lack of functional purity. Frankly, purity should be the default, and deviations from it explicitly requested by the programmer. Scala does not do this, and it doesn't even have a mechanism to mark functions as pure and have the compiler verify it. As far as I know, the only reason for this shortcoming is to not scare away bad programmers.

Despite being low level and very high performance, D verifies purity for functions marked as such. And it's smart about it: you can use mutable local state inside pure functions to run some algorithm that is best implemented with mutable state, and the function stays pure.
Grafting Functional Support on Top of an Imperative Language: How D 2.0 implements immutability and functional purity
Agh, shit. I had a nice reply in my browser window but then my PC decided to crash.

As for beginners and functional programming, I meant beginners to functional programming, not so much to programming in general. Most of the time people start with an imperative language that at best has some support for functional features (Python for instance) but that is usually not beginner material anyways. So for someone who starts with Python or Java and goes to Haskell, it's almost like learning programming from scratch and it can be very daunting because you feel you're at least somewhat productive in your original language but once you switch over, you're back to writing trivial programs for the first few weeks at least.

A "pure" keyword or something of that sort would be nice to have, yes. C++ has something similar, if you declare a method as const, it promises not to change the object it belongs to. I haven't used D yet but it seems neat. Sadly it seems to lack widespread adoption (but that's the case for any of the new languages that try to replace C/C++ like Go and Rust, but they are also much newer)
 

Water

Member
A "pure" keyword or something of that sort would be nice to have, yes. C++ has something similar, if you declare a method as const, it promises not to change the object it belongs to.
C++ "const" has next to nothing to do with purity. Pure functions are characterized by that their return value is the same every time when given the same inputs. The closest C++ equivalent of that is "constexpr" but it is so ridiculously restrictive that most actual code can't possibly be written as constexprs.
 

Sharp

Member
gonna try to look for database jobs when im done with school. besides sql and php what other languages or skills should I be teaching myself?
To be totally honest with you, if you're looking to become a DBA you don't need to know much about any language but your SQL flavor of choice. But you'd better be an absolute expert in that.
I haven't been paying close attention like I probably should have whilst I shored up my resume, but this is excellent news. I graduate this year and I can easily commute into philly on account of the fact that I live near a patco station, so to hear there are a lot of employers seeking entry level is alleviating some stress I had about this whole job thing.
The job market is insane right now, especially for qualified applicants--do not be afraid to walk away if you don't think the offer is fair.
 
I'm having a bit of a problem here. See I'm trying to make a program that when I click the button "New Game" it randomly selects a number 1 to 10. The user is suppose to guess which number it is. If they guess it correct, then they can play the game again. If they guess too high or too low then a text displays whether or not they were too high or low and they are able to try again. The problem I have are two things. The first is transferring the variable found in button 2 to button 1. I could put Dim num 1 as Integer = random Object.Next(1,11) but then if the user guesses wrong on their first guess the game will reset instead of giving the user more guesses to guess the original random number selected.

JpVjL1V.png


Code:
Public Class Form1
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim randomObject As New Random()
        Dim num1 As Integer = randomObject.Next(1, 11)
        Button1.Enabled = True
        Button2.Enabled = False
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim num1 As Integer
        If TextBox1.Text = num1 Then
            Label4.Text = "Correct!"
            Button2.Enabled = True
        ElseIf TextBox1.Text > num1 Then
            Label4.Text = "Too High!"
        ElseIf TextBox1.Text < num1 Then
            Label4.Text = "Too Low!"
        End If
    End Sub
End Class
 
The job market is insane right now, especially for qualified applicants--do not be afraid to walk away if you don't think the offer is fair.

My main issue is me not feeling like I'm "qualified". I figure if I have a decent knowledge of this stuff and the ability and drive to learn, I should be ok?

At any rate I have a class on multithreading/multiprocessing and another one specifically on software engineering so I think come late fall I should definitely feel a lot better about my skills and abilities.
 

Chris R

Member
I'm having a bit of a problem here. See I'm trying to make a program that when I click the button "New Game" it randomly selects a number 1 to 10. The user is suppose to guess which number it is. If they guess it correct, then they can play the game again. If they guess too high or too low then a text displays whether or not they were too high or low and they are able to try again. The problem I have are two things. The first is transferring the variable found in button 2 to button 1. I could put Dim num 1 as Integer = random Object.Next(1,11) but then if the user guesses wrong on their first guess the game will reset instead of giving the user more guesses to guess the original random number selected.

JpVjL1V.png


Code:
Public Class Form1
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim randomObject As New Random()
        Dim num1 As Integer = randomObject.Next(1, 11)
        Button1.Enabled = True
        Button2.Enabled = False
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim num1 As Integer
        If TextBox1.Text = num1 Then
            Label4.Text = "Correct!"
            Button2.Enabled = True
        ElseIf TextBox1.Text > num1 Then
            Label4.Text = "Too High!"
        ElseIf TextBox1.Text < num1 Then
            Label4.Text = "Too Low!"
        End If
    End Sub
End Class

The problem is the number you are generating is only available in the "New Game" button's click event. After you leave that the variable is no longer in scope and the value is lost.

Add a form variable (IE a variable that belongs to the form and isn't declared inside of any of the functions) and set the random value to that. Then you can use it to compare to the text you enter in the textbox.

And it isn't a big deal now, but I'd suggest naming your form elements sooner rather than later, it will prevent major headaches down the road. People might hate on Hungarian Notation, but for form elements I think it makes sense. buttonNewGame is a whole lot easier to read than Button2.

The job market is insane right now, especially for qualified applicants--do not be afraid to walk away if you don't think the offer is fair.

I guess I just need to put myself out there and start applying to various positions. I really love my current position and company, but the pay leaves something to be desired (it sucks seeing everyone else posting their salaries).
 
Add a form variable (IE a variable that belongs to the form and isn't declared inside of any of the functions) and set the random value to that. Then you can use it to compare to the text you enter in the textbox.

This is a bit too confusing. I've been looking online and can't figure out how to do a form variable.

I found something called "Public Variable" and assumed it was similar.

I did this but now the answer is always "10":
Code:
Public Class Form1
    Public randomObject As New Random()
    Public num1 As Integer = randomObject.Next(1, 11)
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Button1.Enabled = True
        Button2.Enabled = False
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = num1 Then
            Label4.Text = "Correct!"
            Button2.Enabled = True
        ElseIf TextBox1.Text > num1 Then
            Label4.Text = "Too High!"
        ElseIf TextBox1.Text < num1 Then
            Label4.Text = "Too Low!"
        End If
    End Sub
End Class

It doesn't reset.
 

Chris R

Member
This is a bit too confusing. I've been looking online and can't figure out how to do a form variable.

I found something called "Public Variable" and assumed it was similar.

I did this but now the answer is always "10":
Code:
Public Class Form1
    Public randomObject As New Random()
    Public num1 As Integer = randomObject.Next(1, 11)
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Button1.Enabled = True
        Button2.Enabled = False
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = num1 Then
            Label4.Text = "Correct!"
            Button2.Enabled = True
        ElseIf TextBox1.Text > num1 Then
            Label4.Text = "Too High!"
        ElseIf TextBox1.Text < num1 Then
            Label4.Text = "Too Low!"
        End If
    End Sub
End Class

It doesn't reset.

So close!

Do this instead.

Code:
    Public num1 As Integer
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Public randomObject As New Random()
        num1 = randomObject.Next(1, 11)
        Button1.Enabled = True
        Button2.Enabled = False
    End Sub

edit: and by "Form Variable" I was just meaning a variable of the form, just like you had setup.
 
So close!

Do this instead.

Code:
    Public num1 As Integer
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Public randomObject As New Random()
        num1 = randomObject.Next(1, 11)
        Button1.Enabled = True
        Button2.Enabled = False
    End Sub

edit: and by "Form Variable" I was just meaning a variable of the form, just like you had setup.
I can't put "Public" inside Sub Button 2 because it states it is not a valid local variable declaration. It has to be Dim. Otherwise it works! Thanks!
 

Chris R

Member
I can't put "Public" inside Sub Button 2 because it states it is not a valid local variable declaration. I also have to put Dim in front of the second "num1".

Yup, sorry I missed that (just copied pasted your code on my iPad) Try replacing BOTH publics with just Dim and see if that works since you don't really need to create a property for this program.

edit: And I just checked, can't create VB forms in VS2012 Express Web :( That's all I have on my home PC when it comes to VS, otherwise I'd throw your form together and make sure it works properly.
 

pompidu

Member
To be totally honest with you, if you're looking to become a DBA you don't need to know much about any language but your SQL flavor of choice. But you'd better be an absolute expert in that.

The job market is insane right now, especially for qualified applicants--do not be afraid to walk away if you don't think the offer is fair.

Thanks, pretty much gonna study nothing but sql and just practice on as many examples as I can.
 
How many years of experience do you have? I'm 2 years out of college, expect to make about 75 this year. Like you, I work about 35 hours. Also in the Midwest, the money goes further. Have a good 401k in a large growing company. Wonder if I should just appreciate my job. I could always move to another position and work on more current technology, but they work the developers hard there.

Five years. I got out of college in Dec 2007, landed a job in early 2008 as a Junior Engineer. I was promoted to Senior in two years. Now I am basically the Lead Architect in all but name, since it basically comes down to not wanting to have new business cards printed up.

I haven't been paying close attention like I probably should have whilst I shored up my resume, but this is excellent news. I graduate this year and I can easily commute into philly on account of the fact that I live near a patco station, so to hear there are a lot of employers seeking entry level is alleviating some stress I had about this whole job thing.

My main issue is me not feeling like I'm "qualified". I figure if I have a decent knowledge of this stuff and the ability and drive to learn, I should be ok?

At any rate I have a class on multithreading/multiprocessing and another one specifically on software engineering so I think come late fall I should definitely feel a lot better about my skills and abilities.

Where are you going to school? If possible do an internship this year, even if it's only short and not for school credit. It will go a long way. Familiarize yourself pretty deeply with either Java (Spring is a huge perk) or .NET and make sure you emphasize SQL knowledge on your resume/cover letter. I think you'll get snapped up quick.
 

Kinitari

Black Canada Mafia
Has anyone tried webstorm? I've been watching a lot of videos on Angular.js and generally, webstorm is what they are using - I use sublime, and I'm happy with it - but webstorm looks pretty awesome in the videos. What's GAF's take?
 

usea

Member
Has anyone tried webstorm? I've been watching a lot of videos on Angular.js and generally, webstorm is what they are using - I use sublime, and I'm happy with it - but webstorm looks pretty awesome in the videos. What's GAF's take?
I've never used it. If you give it a shot, let us know what you think. I use sublime, too (when I'm not using visual studio)
 
Where are you going to school? If possible do an internship this year, even if it's only short and not for school credit. It will go a long way. Familiarize yourself pretty deeply with either Java (Spring is a huge perk) or .NET and make sure you emphasize SQL knowledge on your resume/cover letter. I think you'll get snapped up quick.

Rutgers Camden. Java/.NET are the big stuff? I can do that.

Thanks.
 
Rutgers Camden. Java/.NET are the big stuff? I can do that.

Thanks.

Ahh, nice. My work is in Camden. If we seek an intern I'll drop you a PM. But yeah, around here those are the things I tend to see commonly asked for. I see java more often cause it's what I do, but I am pretty sure .NET is just as popular.
 

Kinitari

Black Canada Mafia
I've never used it. If you give it a shot, let us know what you think. I use sublime, too (when I'm not using visual studio)

Well from using it for a few hours, holy crap. I didn't really get into a lot of the extensibility of sublime, but I don't even feel like I have to bother with that with webstorm. I found a good theme for colours, I tied it into my github account in like, a minute, and it's prediction is out of this world.

Also, it plays nice with angular. After using it for a few minutes, I think after the trial runs out I am definitely going to be paying for it. I'll give a more in depth review later!
 
May I ask a stupid question? It seems a lot of people use Hashmaps(is it like hashtables? that's what I'm getting from reading oracle's page) when implementing a graph. Why is that? What benefits does it have compared to using a generic list?
Just wondering since I'm trying to do an assignment on graphs.
 

Water

Member
May I ask a stupid question? It seems a lot of people use Hashmaps(is it like hashtables? that's what I'm getting from reading oracle's page)
Rather than being like a hashtable, it is a hashtable. (Or conceptually, a map data structure that happens to be implemented with a hashtable.) The other common way to implement maps is with balanced trees.
when implementing a graph. Why is that? What benefits does it have compared to using a generic list?
Just wondering since I'm trying to do an assignment on graphs.
What is a "generic list"?

Different data structures have different worst performance guarantees, different average performance and different memory consumption. If performance doesn't matter, which it likely doesn't for your assignment, you can use whatever gives you the cleanest code. Otherwise the optimal choice depends on the details of the task; the amount of graph nodes you have, the shape and branching factor of the graph, the ways you want to use / iterate the graph, and so on.
 
Rather than being like a hashtable, it is a hashtable. (Or conceptually, a map data structure that happens to be implemented with a hashtable.) The other common way to implement maps is with balanced trees.
What is a "generic list"?

Different data structures have different worst performance guarantees, different average performance and different memory consumption. If performance doesn't matter, which it likely doesn't for your assignment, you can use whatever gives you the cleanest code. Otherwise the optimal choice depends on the details of the task; the amount of graph nodes you have, the shape and branching factor of the graph, the ways you want to use / iterate the graph, and so on.
Ah, that's poor wording. A meant a list, bag, or even an arraylist. But since performance does matter(but won't really affect the grading), they're probably a bad option.

As for the performance part, that's fundamental, isn't it? Well, I guess I'll give hashmaps a try. Learn a new structure while building something I don't really know. If it goes bad, I'll just switch to a simple structure like the bag instead of a hasmap or something. Thanks.
 

Sharp

Member
I guess I just need to put myself out there and start applying to various positions. I really love my current position and company, but the pay leaves something to be desired (it sucks seeing everyone else posting their salaries).
Just do it. I only looked a few weeks and I got an offer around 50% higher than my current salary (would have put me well into six figures). I ended up opting for a slightly less lucrative job in order to be in SF and work on more interesting stuff, but those jobs are out there and there are a lot of them, especially if you don't mind working in a less "sexy" location or framework. Remember, good programmers are scarce and you hold all the cards. Let companies, including your own, know that you know what you're worth in the open market, and don't accept the first offer unless you get the sense that you aren't their first choice.
 

tokkun

Member
Ah, that's poor wording. A meant a list, bag, or even an arraylist. But since performance does matter(but won't really affect the grading), they're probably a bad option.

As for the performance part, that's fundamental, isn't it? Well, I guess I'll give hashmaps a try. Learn a new structure while building something I don't really know. If it goes bad, I'll just switch to a simple structure like the bag instead of a hasmap or something. Thanks.

It really depends on whether you need random access into your graph. A map will provide faster random accesses than a list. If all you need to do is traversal based on the structure of the graph, then a multi-linked list is the superior data structure in some cases.

However in many cases there is a very simple and very high performance 'hash map' implementation that is not a hash map at all:
Simply assign IDs to your nodes in order starting from zero.
Your hashing function does nothing, i.e. hash(a) = a
The hash table is simply an array/vector with size equal to the maximum number of nodes.

Advantages:
O(1) random access average (better than O(log n) for tree-based map, O(n) for list).
O(1) random access worst-case (same as above and better than O(n) for arbitrary hash map)
Fastest possible hashing function.
Smaller memory footprint than tree-based map and much smaller than arbitrary hash map.

Disadvantages:
Some special operations, like merging two independently created graphs, are slow.
Although random deletes are fast, reclaiming the memory from random deletes is slow.

Lastly, you may notice that this implementation is not really any different from using a multi-linked list as the base data structure and separately storing the addresses of the nodes seperately in order to use them for random accesses. This approach eliminates the disadvantages of the array-backed approach, but adds a new disadvantage, which is that making copies of the graph is more difficult (and potentially an icrease in memory footprint).
 
It really depends on whether you need random access into your graph. A map will provide faster random accesses than a list. If all you need to do is traversal based on the structure of the graph, then a multi-linked list is the superior data structure in some cases.

However in many cases there is a very simple and very high performance 'hash map' implementation that is not a hash map at all:
Simply assign IDs to your nodes in order starting from zero.
Your hashing function does nothing, i.e. hash(a) = a
The hash table is simply an array/vector with size equal to the maximum number of nodes.

Advantages:
O(1) random access average (better than O(log n) for tree-based map, O(n) for list).
O(1) random access worst-case (same as above and better than O(n) for arbitrary hash map)
Fastest possible hashing function.
Smaller memory footprint than tree-based map and much smaller than arbitrary hash map.

Disadvantages:
Some special operations, like merging two independently created graphs, are slow.
Although random deletes are fast, reclaiming the memory from random deletes is slow.

Lastly, you may notice that this implementation is not really any different from using a multi-linked list as the base data structure and separately storing the addresses of the nodes seperately in order to use them for random accesses. This approach eliminates the disadvantages of the array-backed approach, but adds a new disadvantage, which is that making copies of the graph is more difficult (and potentially an icrease in memory footprint).
Edit: actually, I think I finally get what to do. Thanks so much for this post. Helped move to the right direction.
 

Ra1den

Member
This fall I am taking a course called "Introduction to C++ for scientists and engineers."

I am new to programming and have a rather difficult fall semester with Calc 2 and a stats class(and an easy history class).

I am having second thoughts about taking this C++ course at the same time as these others, because I don't know what to expect.

How are these classes typically graded? I need to get an A. If it is just based on stuff you do in class then its no big deal, but if there are gonna be tough tests and lots of studying required then I'd rather take it during an easier semester.

Anybody have any idea on what to expect here?
 

Slavik81

Member
This fall I am taking a course called "Introduction to C++ for scientists and engineers."

I am new to programming and have a rather difficult fall semester with Calc 2 and a stats class(and an easy history class).

I am having second thoughts about taking this C++ course at the same time as these others, because I don't know what to expect.

How are these classes typically graded? I need to get an A. If it is just based on stuff you do in class then its no big deal, but if there are gonna be tough tests and lots of studying required then I'd rather take it during an easier semester.

Anybody have any idea on what to expect here?

I think the answers to those sorts of questions are pretty specific to that class at that school with that professor. Ask upper-year students and/or check the internet.
 
Guys what do I need to know to be able to fool around with older games (both PC and roms (NES-DS era)? Like change stats/text/colors/textures and so on.

My programming knowledge is very limited but wanted to try and fool around with something that actually interest me :)

Other thing I would like to understand is some basic exploits. Just to see how they work. Again what do I need to know before I can understand this?

Thank you for your time!
 

Milchjon

Member
Anyone got a clue about graph theory?

When traversing a digraph, we're supposed to give the pre- and postorder for the nodes.

Now, I think I got what the preorder is. But I can't for the life of me figure out what the postorder is supposed to be.

Can anyone explain this as simple as possible? Or does anyone have a link?
 
edit: Hmm, let me search more...

but if preorder/postorder have similar meanings to tree searching, then maybe it means when you're doing a traversal, instead of putting a node first, than what it leads to (preorder), you'd put what the node leads to before the node (postorder). And you'd do that recursively based on whatever algorithm you're using to generate that order.
 
Guys what do I need to know to be able to fool around with older games (both PC and roms (NES-DS era)? Like change stats/text/colors/textures and so on.

My programming knowledge is very limited but wanted to try and fool around with something that actually interest me :)

Other thing I would like to understand is some basic exploits. Just to see how they work. Again what do I need to know before I can understand this?

Thank you for your time!

Games for the (S)NES were written in assembly language, so you're going to be very close to the metal (the hardware). I'd suggest you start looking at how a simple CPU works (the NES CPU is based on the Motorola 6502), how it interacts with RAM and what assembly language looks like and how, for example, a loop in a C program is translated into assembly language. If you know that much, you can start looking at how a ROM is made and where you can mess around to change the sprites, for example.

http://wiki.nesdev.com/w/index.php/Nesdev_Wiki
This is a great NES-specific resource.

I don't have any (English and freely-available) material to learn Assembly and the basics of CPU architecture. The little that I know about that subject, I learned in a university course where the course material was all in German. I would appreciate any hints to where I might find something, because it's an area where I feel like I don't know enough.

edit: Found this cool video on Reddit:
http://youtu.be/kPRA0W1kECg
 
I'm definitely getting frustrated with the job market here in my country. Opportunities for freshers wanting to write code are really slim. Most companies want to hire you as a tester or for some other boring position.

If you apply for a Junior position you're most likely gonna be rejected, even if you ace the interviews. Companies only care about the number of years of experience.

I don't think I suck THAT much at programming, so it's definitely frustrating.

/rant.
 
Is it necessarily kosher to throw all the important header files into one header file?

Code:
//standard library stuff
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <ctime>
#include <cstdlib>

//OpenGL
#include <GL/glew.h>
#ifdef __APPLE__
#   include <GLUT/glut.h>
#else
#   include <GL/glut.h>
#endif

//External dependencies
#include "DisplayFunc.h"
#include "DrawBoardClass.h"
#include "CharacterClass.h"

is in one 'global' file and i just include that where i need. Mainly just tired of tracking dependencies through the class header files I have going on.
 
Games for the (S)NES were written in assembly language, so you're going to be very close to the metal (the hardware). I'd suggest you start looking at how a simple CPU works (the NES CPU is based on the Motorola 6502), how it interacts with RAM and what assembly language looks like and how, for example, a loop in a C program is translated into assembly language. If you know that much, you can start looking at how a ROM is made and where you can mess around to change the sprites, for example.

http://wiki.nesdev.com/w/index.php/Nesdev_Wiki
This is a great NES-specific resource.

I don't have any (English and freely-available) material to learn Assembly and the basics of CPU architecture. The little that I know about that subject, I learned in a university course where the course material was all in German. I would appreciate any hints to where I might find something, because it's an area where I feel like I don't know enough.

edit: Found this cool video on Reddit:
http://youtu.be/kPRA0W1kECg


In my country we have a saying... "You don't build a house from a roof" and that shows here. Like I said my knowledge is really limited and mostly pseudo :) Last time I made a program was like 10 years ago or something.

But I was always put off by boring programming examples and lost interest. Are there any books/resources out there that give "fun" exercises? I know it is subjective but calculators and quiz stuff are kinda boring :)
 

tokkun

Member
Is it necessarily kosher to throw all the important header files into one header file?
<snip>

is in one 'global' file and i just include that where i need. Mainly just tired of tracking dependencies through the class header files I have going on.

There are two things to be concerned about with this practice:

1. Creating false dependencies can increase the size of your binaries and compile time.

2. The global header can be helpful for external code that wants to interface with your library. However if you start including the global header in your own internal files, you run a big chance of getting caught in cyclic dependency hell.

Ex:
Say global.h includes a.h, b.h, and c.h.
Now you want to add a new method to a.h that requires a class defined in c.h. If you try to include global.h in a.h you will get a compile error (probably a confusing one too, depending on your compiler).

It works alright if you only include global.h in .cc files and not in other .h files. But now you're back to manually managing dependencies in .h files, so you really haven't gained all that much.
 

Milchjon

Member
Quick quicksort question:

Older versions of the test I'm taking ask us to use the middle element as the pivot.

Now the critical part: We're supposed to first swap the pivot to the very end of the array, and asked why that step makes sense.

Any ideas as to why? Google has turned up nothing.
 

phoenixyz

Member
Quick quicksort question:

Older versions of the test I'm taking ask us to use the middle element as the pivot.

Now the critical part: We're supposed to first swap the pivot to the very end of the array, and asked why that step makes sense.

Any ideas as to why? Google has turned up nothing.
Not 100% sure but I think that way the pivot only has to be moved twice (to the back, and to the "new middle" after the loop is finished). Otherwise you might have to move it multiple times.
 
I am a newbie and I'm trying to compile a simple C++ program using OSX's terminal. I drag the file into the terminal, type "g++ code.cpp -o Code" and every time it just says "Permission denied." I have the developer tools installed. Any ideas what the problem might be?
 

Water

Member
I am a newbie and I'm trying to compile a simple C++ program using OSX's terminal. I drag the file into the terminal, type "g++ code.cpp -o Code" and every time it just says "Permission denied." I have the developer tools installed. Any ideas what the problem might be?
Try running "g++ --version; ls -la" and post the output.
 

Slavik81

Member
Is it necessarily kosher to throw all the important header files into one header file?

Code:
//standard library stuff
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <ctime>
#include <cstdlib>

//OpenGL
#include <GL/glew.h>
#ifdef __APPLE__
#   include <GLUT/glut.h>
#else
#   include <GL/glut.h>
#endif

//External dependencies
#include "DisplayFunc.h"
#include "DrawBoardClass.h"
#include "CharacterClass.h"

is in one 'global' file and i just include that where i need. Mainly just tired of tracking dependencies through the class header files I have going on.
This is a bad idea. It doesn't take a very large project before you're looking at >30 second compile times when you do this.

Standard library headers are thousands of lines of code, and you're compiling a half-dozen of them for each file in your project, every time any header in your project changes.

Basically, by the time you reach a dozen of your own files, you're compiling hundreds of thousands of lines of code each time you modify a header and hit build.

This technique is sometimes used with precompiled headers, but you could probably get away with it for a small project even without that. Either way, just keep your own headers out of it. They change too often.

(I did what you're doing back when I was first learning C++. The slow build was painful, but at the time I didn't realise it was avoidable.)
 
Top Bottom