• 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

Thanks a lot guys. Looks like there's some good resources there. I figured it'd be a little tougher, but it's something I want to pursue so thanks for pointing me in the right direction.
 
Is MATLAB discussed here? I'm having trouble trying to write working code to create an iteration.

You can use while, do until, and for. Break and continue are also supported for premature termination of an iteration. You can use the online Octave documentation (via a search engine) for basic language stuff, as both MATLAB and Octave share substantially the same language. There is even online documentation of the differences:

http://en.wikibooks.org/wiki/MATLAB_Programming/Differences_between_Octave_and_MATLAB
 
yes, I realize all this and also that class in a template and class in c++ are in fact two different ideas. It's just that in most use cases typename and class behave the same inside a template. template<class T> describes a primitive like an int just as easily as it does a proper class or struct.

Anyway it's not an issue and now I have the polymorphism I wanted without that blasted vtable pointer adding 4 bytes to every vector.

Edit: If I was using clang I wouldn't even have been an issue as allowing the use of typename in this context is proposed as part of C++1z and it's apparently already implemented in clang.
Ok, sorry. I misread your question as a more newbie one. My bad!

In general the template rules are esoteric (it's part of why I say they're evil -- to be precise, I would say they're unfinished... and yet part of the language standard. Alas.), so I'm never surprised when some seemingly minor difference sends crap sideways. They're slowly refining templates into something sane, but the emphasis is on slowly.

Was the vtable space really hurting you? In general, I've accepted the slightly suboptimal cases (except where the profiler tells me not to) as a sacrifice at the altar of code maintainability. I dream of a day when C++ won't ask me to choose... but that is not this day.
 

squidyj

Member
Ok, sorry. I misread your question as a more newbie one. My bad!

In general the template rules are esoteric (it's part of why I say they're evil -- to be precise, I would say they're unfinished... and yet part of the language standard. Alas.), so I'm never surprised when some seemingly minor difference sends crap sideways. They're slowly refining templates into something sane, but the emphasis is on slowly.

Was the vtable space really hurting you? In general, I've accepted the slightly suboptimal cases (except where the profiler tells me not to) as a sacrifice at the altar of code maintainability. I dream of a day when C++ won't ask me to choose... but that is not this day.

Yeah it's kind of an issue because I'd like everything to be tightly packed when working with graphics libraries like opengl, which loves to work with memory offset and stride, also the overhead of 4 bytes on a 12 byte object or even an 8 byte object is a little high when I'll be using so many of them.

The other major restriction is i have a swizzle type which is like a reordering, of the elements of a given vector. so for a vector v, v.xxx or v.yxz is a member variable of v that is a swizzle, the major issue was making sure that swizzles are subject to the same math as vectors, but that swizzles actually require no storage being made up of reference variables. If the swizzle is a member of a vector and requires storage, the many swizzles I want to have further bloat the vector storage.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Has anyone ever tried one of these programming bootcamps? Scam, legit, or somewhere in between?

Specifically, I'm looking at Bloc, because they keep spamming me with their shit. I've discovered that I have extreme difficulty keeping to some sort of self-study/self-improvement schedule. I work far better when I have some structure imposed on me from an external source, but since I graduated I've been stagnating, if not deteriorating in terms of skills/knowledge.

So, yeah. Any advice, be it programming or career stuff, would be helpful here.
 

danthefan

Member
Very general question, are there any particularly good resources out there for learning SQL? I'm aware of W3Schools and had a look at LSQLTHW but if seems incomplete. Any others out there?
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Just got decimated by a Functional Dependency test.

-__-

Just looked this up. Seems like it's a way to describe a simple concept in a complicated way.

What are it's applications in relation to comp sci?
 
Just looked this up. Seems like it's a way to describe a simple concept in a complicated way.

What are it's applications in relation to comp sci?

From what I've learned about it, it applies to databases and their constraints. Like one table requires a foreign key from another table, and is functionally dependent on that key existing in the other table. Database design confuses the hell out of me, and I have a final on it tomorrow....
 
From what I've learned about it, it applies to databases and their constraints. Like one table requires a foreign key from another table, and is functionally dependent on that key existing in the other table. Database design confuses the hell out of me, and I have a final on it tomorrow....

Database design confuses hell out of everyone and all databases suck equally (though some suck in mysterious ways that might seem that they suck more)
 

Chris R

Member
Has anyone ever tried one of these programming bootcamps? Scam, legit, or somewhere in between?

Specifically, I'm looking at Bloc, because they keep spamming me with their shit. I've discovered that I have extreme difficulty keeping to some sort of self-study/self-improvement schedule. I work far better when I have some structure imposed on me from an external source, but since I graduated I've been stagnating, if not deteriorating in terms of skills/knowledge.

So, yeah. Any advice, be it programming or career stuff, would be helpful here.

It really depends on what your focus is. Bloc looks like it would be for "App" creators, Treehouse looks like it's web design/development focused, ect.

I'd just try one of the free sites though if you are just looking at brushing up on various skills.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
It really depends on what your focus is. Bloc looks like it would be for "App" creators, Treehouse looks like it's web design/development focused, ect.

I'd just try one of the free sites though if you are just looking at brushing up on various skills.
Its more of a motivational problem. Left to my own devices I would just spend all my time playing
DOTA
. I figure I'd apply myself more if I was actually paying a tutor/mentor.
 

Chris R

Member
Its more of a motivational problem. Left to my own devices I would just spend all my time playing
DOTA
. I figure I'd apply myself more if I was actually paying a tutor/mentor.

Just wait for Source 2 to come out and then you can spend time scripting custom games and combine the programming stuff with the dota stuff :p

I know what you mean though, I have a few side projects I'd like to work on, but it's hard to motivate myself to "work" outside of work when I'm not going to be paid (in the short term, a better portfolio is always worth it long term) for them.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
From what I've learned about it, it applies to databases and their constraints. Like one table requires a foreign key from another table, and is functionally dependent on that key existing in the other table. Database design confuses the hell out of me, and I have a final on it tomorrow....

Database design confuses hell out of everyone and all databases suck equally (though some suck in mysterious ways that might seem that they suck more)

Good to know ahead of time for when I eventually take the class.
 

Antiwhippy

the holder of the trombone
Gonna sound like a dumb question, but...

How do I output my HTML into an email ad?

Got asked as a favour to do an email phamplet, but while I know how to format it in an email format I haven't learnt how to send it out as an actual email.
 
Yeah it's kind of an issue because I'd like everything to be tightly packed when working with graphics libraries like opengl, which loves to work with memory offset and stride, also the overhead of 4 bytes on a 12 byte object or even an 8 byte object is a little high when I'll be using so many of them.

The other major restriction is i have a swizzle type which is like a reordering, of the elements of a given vector. so for a vector v, v.xxx or v.yxz is a member variable of v that is a swizzle, the major issue was making sure that swizzles are subject to the same math as vectors, but that swizzles actually require no storage being made up of reference variables. If the swizzle is a member of a vector and requires storage, the many swizzles I want to have further bloat the vector storage.
Ah, I think I'm with you now.
 
Has anyone ever tried one of these programming bootcamps? Scam, legit, or somewhere in between?

Specifically, I'm looking at Bloc, because they keep spamming me with their shit. I've discovered that I have extreme difficulty keeping to some sort of self-study/self-improvement schedule. I work far better when I have some structure imposed on me from an external source, but since I graduated I've been stagnating, if not deteriorating in terms of skills/knowledge.

So, yeah. Any advice, be it programming or career stuff, would be helpful here.

I've read some reviews on Hacker News. Seems like they're okay if you're an intelligent person with an analytical background. They won't make you into a good programmer over night but they can make you dangerous.
 
Gonna sound like a dumb question, but...

How do I output my HTML into an email ad?

Got asked as a favour to do an email phamplet, but while I know how to format it in an email format I haven't learnt how to send it out as an actual email.

First you put on Space Jam OST and then you start rocking out with table elements like it was 1996. I wish I was kidding.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
That's a nice starter template for emails too! Space Jam is the best thing that's ever happened to web development!

Serious? Explain this to me please.
I feel like I'm missing something that everyone else knows.
edit: unless you were joking, it's late
 
Serious? Explain this to me please.
I feel like I'm missing something that everyone else knows.
edit: unless you were joking, it's late

Sort of joking, but really as <table> elements still rule the email world -> The Space Jam page is made with tables like everything else in 96 -> Copy table structure from the Space Jam page -> replace images -> ???? -> email template ready to send out!
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Sort of joking, but really as <table> elements still rule the email world -> The Space Jam page is made with tables like everything else in 96 -> Copy table structure from the Space Jam page -> replace images -> ???? -> email template ready to send out!

That's Jamtastic!
 

nOoblet16

Member
Anyone good with algorithms here?
I'm trying to learn a bit and I have to find the largest matching in an un-directed graph. Pretty simple I guess, just use BFS with backward ordering to number the nodes and then check if the node or its parent is marked, if it is then skip the node...if not then add the node to the list. Works in linear time and pretty straightforward.

But what about a case where I find all the unmatched nodes with the most unmatched children and match it with its unmatched child. Then remove all of them and the adjacent edges and keep repeating until there are none left. Why should this not give me the maximum matching in every case?
 

Pinewood

Member
Need help with virtual destructors on C++

The code goes like this
Code:
class GameCharacter
{
protected:
    string name;
    int hitpoints;
    Weapon *weapon;
public:
    virtual ~GameCharacter() = 0;
    virtual void attack(GameCharacter *opponent) =0;
    string to_string();

};
class Player : public GameCharacter
{
public:
    virtual ~Player() {};
};
class Warrior : public Player
{
public:
    Warrior(string n);
};
I would want to use virtual ~Player() = 0; instead of virtual ~Player() {}; like my professor said i should but it won't let me do that, saying there is an undefined reference to that in Warriors constructor in the .cpp file.
NVM: Figured it out.
 

caffeware

Banned
I would want to use virtual ~Player() = 0; instead of virtual ~Player() {}; like my professor said i should but it won't let me do that, saying there is an undefined reference to that in Warriors constructor in the .cpp file.
NVM: Figured it out.

It's weird that your professor said that because there's no use for a pure virtual destructor.

Look at:

http://stackoverflow.com/questions/630950/pure-virtual-destructor-in-c

http://stackoverflow.com/questions/1219607/why-do-we-need-a-pure-virtual-destructor-in-c
 

Vitanimus

Member
OKAY SO

Basically, we have to recreate the secant method in MATLAB, which I think I've done. For one of the questions, it asks me to find the absolute error after each iteration. However, whenever I get the code, I always get an error when I get to the "err=abs(xi-r)" part because it tells me xi is undefined, even though I define it in my function. I'll just post the code and see if anyone can spot why it won't work.

Code:
%Introduction to Numerical Methods - Coursework 2
%Question 3

clear all
clc

f=@func;

x0=input('First initial guess: ');
x1=input('Second initial guess: ');

nmax=input('Maximum number of iterations: ');
while nmax<=0
    disp('Choose a positive integer: ')
    input('Choose a new value: ')
end

tol=input('Specifiy a tolerance value: ');
while tol<=0
    disp('Choose a tolerance greater than 0: ')
    input('Choose a new tolerance value: ')
end

secant(@func,x0,x1,nmax,tol)

%Question 5, 6 and 7 

r=nthroot(10,10);

[B]err=abs(xi-r);              <--- consistently told that xi is an undefined variable
[/B]
q=(1+sqrt(5))/2;
a=[];
b=[];

for i=1:(iter-1);
    errk=err(:,i);
    errknext=err(:,i+1);
    c=errknext/(errk^q);
    a=[a i];
    b=[b c];
end

disp('Displays the absolute error after each iteration');
disp('b');

and this is my secant function:

Code:
function [x, y, iter] = secant( f, x0, x1, nmax, tol )
%SECANT   Secant method for root finding.
%         [X, XI, ITER] = SECANT( F, X0, X1, NMAX, TOL ) finds a zero, X,
%         of the function F(X) using the secant method. XI is a vector of
%         length ITER that contains all the iterative approximations to X,
%         where ITER is the number of iterations used. X0 and X1 are the
%         initial values required for the secant method, NMAX is the maximum
%         number of iterations allowed, and TOL is the convergence criterion.

%

xi(1)=x0;
xi(2)=x1;
n=2;

    while tol<abs(f(xi(n))*(((xi(n)-xi(n-1))/(f(xi(n))-f(xi(n-1))))))
        xi(n+1) = xi(n)-(f(xi(n))*((xi(n)-xi(n-1))/(f(xi(n))-f(xi(n-1)))));
        n=n+1;
        
        if n==nmax
            break;
        end
    end
    
x=xi(n);
y=xi;
iter=n-2;
disp([x,y,iter]);

end
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Is there any advantage software wise in using MacOS to program?

There's some advantages that people will argue over till the end of time, but in reality it's down to what you are most comfortable with using.

Personally I'm most comfortable with OSX + Windows in Parallels.
 

luoapp

Member
OKAY SO

Basically, we have to recreate the secant method in MATLAB, which I think I've done. For one of the questions, it asks me to find the absolute error after each iteration. However, whenever I get the code, I always get an error when I get to the "err=abs(xi-r)" part because it tells me xi is undefined, even though I define it in my function.

put "global xi" in both the main routine and the function.
 
Tried that and got no errors, although the code doesn't do what I want it to do. Thanks though!

That's...okay. Another solution would be to observe that the function secant places the vector xi into the return value y. So you could remove both of the global statements and replace the references to y in the main program (but not in secant) with xi.

As a working programmer who is accustomed to hitting their head against a brick wall when code doesn't do what it's supposed to, I sometimes try explaining my code, line by line, in normal English, to a patient friend. This forces me to examine my thought processes. That often helps me to spot the problem. Usually my friend is sensible enough to realise that they don't have to say much, only to listen. My most perceptive friend in this respect is a cat. Her debugging powers are so vast that she never needs to say a word.

I'd pay particular attention to your secant call in the main program. Isn't it supposed to have some variables on the left hand side? How else are your secant function's return values going to be transmitted back to your main program?
 

Pinewood

Member
Were doing OOP and since that class is an abstract base for inheritance we would use a pure virtual destructor in it. I have to admit I didn't pay that much attention in that lecture as I should.

Is there any advantage software wise in using MacOS to program?
CodeBlocks (what were using) crashes all the time under OS X for me.



Is there a way to check while loop conditions during the loop in C++ other than a if clause?
 
Is there any advantage software wise in using MacOS to program?

Depends upon what kind of development you want to do. I've found that its a whole lot easier to use Terminal for scripting languages and what not that anything I ever used on Windows. I'm guessing the same advantage would exist on most modern Linux distros as well.

For other types of programming, I guess it really comes down to what you want to do and what your target platform is.
 
I have recently started an internship with a friend of mine that has been working at the place for about two years. He has a fairly large code-base (to me at least) that he's built up over that time, so he really knows it inside and out. Obviously it's a little hard for me to come in and have any idea what I'm doing with his code haha.

Does anyone have any recommendations when it comes to learning somebody elses code? Right now he's having me try to implement small things and ask him questions if I get confused about what something does, where the data is coming from, etc. Just curious as to how I can become more productive more quickly.
 

Leezard

Member
OKAY SO

Basically, we have to recreate the secant method in MATLAB, which I think I've done. For one of the questions, it asks me to find the absolute error after each iteration. However, whenever I get the code, I always get an error when I get to the "err=abs(xi-r)" part because it tells me xi is undefined, even though I define it in my function. I'll just post the code and see if anyone can spot why it won't work.
Just get xi as an output variable from your secant function. In the function, you have it as an output y, so in your main code replace this:
Code:
secant(@func,x0,x1,nmax,tol)
with something like this:
Code:
[~,xi] = secant(@func,x0,x1,nmax,tol)
the ~ just suppresses the first output, since it seems you are not interested in that one.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
I have recently started an internship with a friend of mine that has been working at the place for about two years. He has a fairly large code-base (to me at least) that he's built up over that time, so he really knows it inside and out. Obviously it's a little hard for me to come in and have any idea what I'm doing with his code haha.

Does anyone have any recommendations when it comes to learning somebody elses code? Right now he's having me try to implement small things and ask him questions if I get confused about what something does, where the data is coming from, etc. Just curious as to how I can become more productive more quickly.

Ask a lot of questions. Hopefully he is someone that enjoys explaining his thought processes and problem solving techniques to other people.
If there is a function that you don't quite understand ask him to explain what he was intending for that function to do, and why he gave the function the data he did, etc.

I am in a similar situation. I'm working on a project with a colleague where my portion is <1000 lines of code while his is this 8000+ loc monster. But thankfully he is really interested in explaining his code to others, so we've gone through the program function by function so I understand it fairly well at this point.

Good luck!
 
Ask a lot of questions. Hopefully he is someone that enjoys explaining his thought processes and problem solving techniques to other people.
If there is a function that you don't quite understand ask him to explain what he was intending for that function to do, and why he gave the function the data he did, etc.

I am in a similar situation. I'm working on a project with a colleague where my portion is <1000 lines of code while his is this 8000+ loc monster. But thankfully he is really interested in explaining his code to others, so we've gone through the program function by function so I understand it fairly well at this point.

Good luck!

Thanks for the advice! I will definitely ask more questions. I have quite a bit of time to learn everything I need to but the faster I can become more of a help to him the better.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Thanks for the advice! I will definitely ask more questions. I have quite a bit of time to learn everything I need to but the faster I can become more of a help to him the better.

Be open with him to. If he knows that you are craving for a task to work on to help him out and learn, he will probably be more open to handing something off to you or giving you something from the task list that I'm sure exists.
 
Be open with him to. If he knows that you are craving for a task to work on to help him out and learn, he will probably be more open to handing something off to you or giving you something from the task list that I'm sure exists.

Yeah, right now he has me working on something further down the list while he works on something that's higher priority. So if I end up needing a bit of help with the task, it's not a huge deal as no one is expecting this feature immediately. I'm assuming this is the way that we'll continue working for a while.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Yeah, right now he has me working on something further down the list while he works on something that's higher priority. So if I end up needing a bit of help with the task, it's not a huge deal as no one is expecting this feature immediately. I'm assuming this is the way that we'll continue working for a while.

That's how I started getting myself involved as well.

Have fun learning!
 

Pinewood

Member
So how would I go and remove empty elements from a vector in C++?
To clarify, I know that I can use erase, but how can I conviniently remove all empty cells at the same time?
 

hateradio

The Most Dangerous Yes Man
Top Bottom