• 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

hateradio

The Most Dangerous Yes Man
I have a question about public repos on Github.

Is there a way I can remove/obscure my Google tracking ID, or is that something I don't need to worry about? I suppose anyone could see it when viewing source of my webpage...maybe I just answered my own question.
If you need to obscure something, you can put it in a file within a .gitignore.

Create a JS file for that ID, then put link to that file using a script tag. I'm sure there are other ways of doing it, if you google. :pp
 

poweld

Member
Thanks.

Funny, even with the supplied solution, let alone my version I get issues.

I've been having this issue with nullpointerexceptions.

I even see it when I replaced my code with the solution provided on github here:

https://github.com/udacity/Sunshine...le/android/sunshine/app/ForecastFragment.java

I get an error like this:

Are you using this class in a multithreaded environment? It isn't thread safe. It looks like you're running into a race condition when closing the reader.
 

Skinpop

Member
Since sublime forums are down and I couldn't find anything googling it..

is it possible to have the console in a separate tab or at least vertically aligned in sublime? I don't want it horizontally like the default, especially if it spits out a lot of errors I need the vertical space for both the source file and the console.

Also, I'm using a custom build setting which basically calls a script that executes the build(c++). How would I go about to get the error lines from the output so that sublime will highlight it in the editor for me?

At the moment I'm coding next to a ConEmu(basically an advanced command prompt) window, but it would streamline things for me to do it all in sublime(especially if I could highlight errors). I got building to work properly so far...
 

upandaway

Member
Is there anything simple/straightforward that I can read about how to use malloc/free in C properly? I mean, I understand it, but I want something like a solid design pattern I can fall back on or good/bad practices.

Intuitively I think I would want to have a list of constant pointers that save a copy of every malloc call, then call free on all of them at the end of the program (say this list itself doesn't need dynamic allocation). I'm not sure if that's the best way to go about it.
(wait, I guess they can't be constants, scratch that part)
 

Pinewood

Member
So if I use inheritance and want to derive a class from 2 other classes like this
Code:
class SwimmingFlock : public virtual Flock
{
    SwimmingFlock(string n) : Flock(n){};
};
class FlyingFlock : public virtual Flock
{
    FlyingFlock(string n) : Flock(n){};
};
class BothFlock : public SwimmingFlock, public FlyingFlock
{
    BothFlock(string n): Flock(n){};
};
Why does it give me an error with
Code:
BothFlock(string n): Flock(n){};
And how do I fix it? I know an easy fix would be BothFlock(string n);, but can I do it the other way too?
 

Skinpop

Member
I solved my own sublime issues mostly.
Getting the error message and lines was as easy as writing some regex for capturing the info from the compiler output. Haven't used regex for years so my brain almost exploded trying to relearn it in a night....

Still wondering about possibly containing a terminal/console within a tab, or somehow aligning it vertically since the horizontal configuration kinda ruins my wokrflow.
 

mltplkxr

Member
The first thing I missed in moving from VAX/VMS to SunOS and eventually other Unixes was that the file system had no concept of file revisions. In VMS this was such a ubiquitous concept, and so useful, that I'm still surprised that it was never adopted outside the VMS community.
Microsoft tried to bring it back while developing Vista but dropped it before the release. It's a live in SharePoint. I wonder if it would be a simple concept to grasp for the majority of users.
 

usea

Member
I hate tests that rely upon the database. Slow running tests often enough are never run.

I don't know if you've done the same, but where we could, we used a repository pattern so the business logic wouldn't depend on the EF context directly, and the repository(/ies) the logic relied upon only exposed the minimum needed for that particular piece of code. For example, if the logic only needed to work with the "Bars" table as data, we passed it an IBarRepository* or, often enough, an IRepository<Bar>**. (For logic that required access to multiple tables, we'd bundle together repositories into a unit of work interface.) This allowed us to write unit tests for the business logic and reserve the slower integration tests for the concrete repository classes that were tested independently of any business logic tests.

Of course, that project ended up going off the rails at some point. Large banks, small budgets, what are you going to do.

-----
**IRepository<T> got you CRUD methods "for free" when the concrete Repository<T> class was used. Similarly, substitution for unit tests was also "free" with a StubRepository<T> instance.
*I{T}Repository implementations were reserved for when the free methods above were not required or were insufficient (such as needing specialized queries), as the case may be. These repositories might inherit from the above or go their own different direction, depending upon need.
Thanks for the reply. We used the repository pattern in a project I worked on at another job, but I haven't been able to convince them to move their new project infrastructure to that yet at my new job. EF is everywhere. IDbSet<> dependencies all over the place.

You can supply a mock db set backed by a list, but it would take more time than it's worth to refactor the tests for the project I'm currently on. And I don't think I have the political capital to influence the next one, either.
 
Microsoft tried to bring it back while developing Vista but dropped it before the release. It's a live in SharePoint. I wonder if it would be a simple concept to grasp for the majority of users.

I was a code basher and there was no other form of revision control available to me in the 1980s (whereas SCCS and RCS were easily available to Unixers at that time). The use case has largely been superseded by the demise of VMS and the modern diversity of revision control tools that are supported on POSIX systems.
 

Pinewood

Member
I have a hard time understanding Singleton patterns. I have to use signel ton, to make sure that there is only one instance of an object I add into a class and I cant add it to elsewhere ,but I cant wrap my head around it.

Here's a crude example
Code:
class Bird
{
     string name;
};
class Flock
{
vector <*Bird> birds;

void addBird(Bird *bird)
{
     birds.push_back(bird);
}

};
And I have to make sure that if there is for example 3 Flocks and 7 birds, every bird can only belong into one flock.
 

tokkun

Member
I have a hard time understanding Singleton patterns. I have to use signel ton, to make sure that there is only one instance of an object I add into a class and I cant add it to elsewhere ,but I cant wrap my head around it.

Here's a crude example
Code:
class Bird
{
     string name;
};
class Flock
{
vector <*Bird> birds;

void addBird(Bird *bird)
{
     birds.push_back(bird);
}

};
And I have to make sure that if there is for example 3 Flocks and 7 birds, every bird can only belong into one flock.

What you're describing doesn't sound like an obvious example of a Singleton pattern. The basic concept of the Singleton is to only have one instance of a certain type of object. If you have 3 Flock instances and 7 Bird instances alive in your program at the same time, then it doesn't sound like you want to make either of those classes a Singleton.
 

Pinewood

Member
I misunderstod the assingment. I had to do a BirdController class, that does the sorting stuff and make that with singleton.

E: so if I have a Singleton object, how can I access it's functions in other classes without having to reference it in every function header? As in
Code:
BirdController is a singleton with a function 
bool AddBird(Bird *bird)

And this is how I want to use it

Flock::addBird(Bird *bird)
{
if(BirdController::AddBird(bird))     <--- How do I word this part? I dont want to add it to every function, 
     birds.push_back(bird);

}
 

zbarron

Member
Hello everybody.

I've just been assigned a website to improve and work on. It's wordpress based. I have never worked on websites before and have no training or education in it. It being wordpres though should make it doable. Does anyone here have any resources where I can learn the basics on what I am doing? I'd like to learn as fast as possible.

Thanks.
 
Hello everybody.

I've just been assigned a website to improve and work on. It's wordpress based. I have never worked on websites before and have no training or education in it. It being wordpres though should make it doable. Does anyone here have any resources where I can learn the basics on what I am doing? I'd like to learn as fast as possible.

Thanks.

Although you might find some answers here, the web design and development thread might be able to give you more focused advice.
 

tokkun

Member
I misunderstod the assingment. I had to do a BirdController class, that does the sorting stuff and make that with singleton.

E: so if I have a Singleton object, how can I access it's functions in other classes without having to reference it in every function header? As in
Code:
BirdController is a singleton with a function 
bool AddBird(Bird *bird)

And this is how I want to use it

Flock::addBird(Bird *bird)
{
if(BirdController::AddBird(bird))     <--- How do I word this part? I dont want to add it to every function, 
     birds.push_back(bird);

}

What you have in your code will work if you make BirdController a static class. That may be good enough for your purposes.

If you want a real Singleton, the typical thing to do is create a wrapper class with a static method that returns the instance. Like:

Code:
class BirdControllerSingleton {
 public:
  static BirdController* get() { ... }
 private:
  static BirdController* instance_;
};

To use it you would do something like

Code:
if (BirdControllerSingleton::get()->AddBird(bird)) { ... }

If you want to get fancy, make the wrapper into a template class, and you can reuse it to implement Singletons for other types of object.
 
So I am on Windows but I know Linux is used a lot in the programming world. I don't really want to partition my computer and run Linux on it. I know you can run a virtual box or something? How do I do that?
 

Saprol

Member
So I am on Windows but I know Linux is used a lot in the programming world. I don't really want to partition my computer and run Linux on it. I know you can run a virtual box or something? How do I do that?
VMware Player and VirtualBox both have free options. Then you just grab an ISO of whatever Linux OS you want.
 
VMware Player and VirtualBox both have free options. Then you just grab an ISO of whatever Linux OS you want.

Huh thanks. And then I just basically run the OS within Windows and it shouldn't be any different? Any Linux OS you'd recommend? What would be the most relevant or is Linux Linux no matter the distro?
 

oxrock

Gravity is a myth, the Earth SUCKS!
So I am on Windows but I know Linux is used a lot in the programming world. I don't really want to partition my computer and run Linux on it. I know you can run a virtual box or something? How do I do that?

I am far from a linux expert, I haven't used it in years. But I used to use a version called KNOPPIX. All the files are stored on a cd and it runs straight from that. No install required, you just boot from cd.
 

Mr.Mike

Member
Huh thanks. And then I just basically run the OS within Windows and it shouldn't be any different? Any Linux OS you'd recommend? What would be the most relevant or is Linux Linux no matter the distro?

Yeah, just Ubuntu would be the easiest option. I also recommend VMware's free version since they have an "easy install" thing that will make everything super easy for you if you're installing Ubuntu.
 

-KRS-

Member
If not Ubuntu, then Fedora is another nice distro. But you should probably go with Ubuntu since that is the traditional beginners linux distro.

Edit: v Xubuntu uses the XFCE4 desktop which is a more traditional looking desktop, which might actually be a good thing for a beginner. XFCE is also very lightweight and fast which is more suited for virtual machines, but things aren't as well integrated as in other more advanced desktops like Gnome and KDE. But that won't be a problem for just tinkering around with code a bit. That part will work as well as in any other desktop environment.
 

Atruvius

Member
I recently downloaded Xubuntu to external HDD. I had previously tinkered with Ubuntu and I like Xubuntu better. Though the only difference seems to be the GUI, and Ubuntu apparently has some ads and user tracking stuff.

I tried Ubuntu using Virtual Box and the performance was pretty bad. I couldn't get it to work at my desktop resolution and it was using virtual GPU.
 

Gurrry

Member
Hey guys so im pretty new to Unity and ive been trying to work on an enemy chase script.

Basically, I want the enemy to "spot" the player and when it does, I want it to start chasing after the player.

I would also like for it to stop chasing once its out of range, but I can live without that for now.

The problem is that when I start the game, the enemy just immediately starts moving whether the player is "spotted" or not.

I am programming in C#, here is my script, any help would be greatly appreciated.

using UnityEngine;
using System.Collections;

public class enemyChase : MonoBehaviour {

public Transform sightStart, sightEnd;
public bool spotted = false;


public Transform player;
public float playerDistance;


public Vector2 speed = new Vector2(10, 10);
public Vector2 direction = new Vector2(-1, 0);
private Vector2 movement;


void Start()

{

}

void Update()
{
Raycasting ();
Behaviors ();

}



void Raycasting()

{
Debug.DrawLine(sightStart.position, sightEnd.position, Color.green);
spotted = Physics2D.Linecast (sightStart.position, sightEnd.position, 1 << LayerMask.NameToLayer ("Player"));

if (spotted = true) {

movement = new Vector2 (
speed.x * direction.x,
speed.y * direction.y);

rigidbody2D.velocity = movement;

}

else
{
spotted = false;
}

}


void Behaviors()
{

}

}

Like I said im a newb.. so Im sure this code is laughable. But ive been working at this for awhile now and its driving me to madness. Any help is greatly appreciated!
 
You are assigning "true" to your variable spotted instead of comparing it. Just use

Code:
if (spotted)

(which is shorthand for if (spotted == true))
 

oxrock

Gravity is a myth, the Earth SUCKS!
Hoping you guys can give some insight. I'm currently working on a button module for pygame(python game engine). Right now creating the button objects with parameters passed in works fine, but I need to be able to pass in a function to have the class be properly modular. When the button is pressed, i want to be able to specify the function being called as a result. Obviously i could just program this in as a case by case basic but that's far from ideal, especially if I want to recycle the code as was my intention.

To better illustrate I want to be able to do this:

button1 = Button(size,color,function1)
button2 = Button(size,color,function2)

My Google searches were fruitless but I'm thinking this must be possible. Help appreciated.

Edit: Upon further research, I'm seeing that I should be able to do the following...

def passer():
print "Passing me worked!"

def test(funct):
funct()

And then calling test(passer) should properly work. However, when I try that, I get "NameError: global name 'funct' is not defined"

2nd edit: Been working on this a bit and see that although I passed the function into the class to create the object properly, i neglected to then assign that function to a value within that object. Then when attempting to reference the function that i hadn't properly assigned, it threw an error complaining that it didn't know what the heck I was talking about.
 

poweld

Member
Hoping you guys can give some insight. I'm currently working on a button module for pygame(python game engine). Right now creating the button objects with parameters passed in works fine, but I need to be able to pass in a function to have the class be properly modular. When the button is pressed, i want to be able to specify the function being called as a result. Obviously i could just program this in as a case by case basic but that's far from ideal, especially if I want to recycle the code as was my intention.

To better illustrate I want to be able to do this:

button1 = Button(size,color,function1)
button2 = Button(size,color,function2)

My Google searches were fruitless but I'm thinking this must be possible. Help appreciated.

Edit: Upon further research, I'm seeing that I should be able to do the following...

def passer():
print "Passing me worked!"

def test(funct):
funct()

And then calling test(passer) should properly work. However, when I try that, I get "NameError: global name 'funct' is not defined"

I was going to suggest a lambda, but it seems like the Python community has agreed for some reason that they're a sin... not sure why.

Anyway, looks like functools.partial will fulfill your goal
 
whats wrong with this code?
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
void MakeDeposit(); // new function with no parameters
void MakeWithdrawl(); // new function with no parameters
void GetBalance(); // new function with no parameters
float balance = 0;
float newBalance = 0;
float adjustment = 0;
int _tmain(int argc, _TCHAR* argv[]) {
char response[256];
string moreBankingBusiness;

cout << "Do you want to do some banking? ";
cin >> moreBankingBusiness;


for (int i = 0; i < moreBankingBusiness.length(); i++) {
moreBankingBusiness = toupper(moreBankingBusiness);
}
while (moreBankingBusiness == "YES") {
cout << "What would you like to do? <1 = Deposit, 2 = Withdraw, 3 = Get Balance): ";
cin.getline(response, 256);
if (strlen(response) == 0){
cout << "You must make a selection";
system("pause");
return 1;


the program doesn't run the cin.getline(response, 256) or anything after displaying what would you like to do. I did what the book told me to do
 
So my friend and I are working on the same project, but different parts. We have both made a few new classes as well as some changes to existing classes.

We're not exactly sure how to combine them now.. He has his current version on our Github while mine is still just locally on my machine. Is there an easy way we can combine them or not really? We're both fairly new to source control.

At worst, I should be able to copy my files into his version of the project and edit my bits of code into one of our main files. Not a huge deal but it'll take me a little time.
 

Kalnos

Banned
So my friend and I are working on the same project, but different parts. We have both made a few new classes as well as some changes to existing classes.

We're not exactly sure how to combine them now.. He has his current version on our Github while mine is still just locally on my machine. Is there an easy way we can combine them or not really? We're both fairly new to source control.

At worst, I should be able to copy my files into his version of the project and edit my bits of code into one of our main files. Not a huge deal but it'll take me a little time.

Pull his changes, merge them into yours with kdiff3 or whatever, commit and push.
 
So my friend and I are working on the same project, but different parts. We have both made a few new classes as well as some changes to existing classes.

We're not exactly sure how to combine them now.. He has his current version on our Github while mine is still just locally on my machine. Is there an easy way we can combine them or not really? We're both fairly new to source control.

At worst, I should be able to copy my files into his version of the project and edit my bits of code into one of our main files. Not a huge deal but it'll take me a little time.

Did you have the same starting point? You could just merge his repo with git-merge and solve the conflicts by hand.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Just started using Node.js with MongoDB, Jade, etc.

This is some really, really cool stuff.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
In before someone comes in and says MongoDB something something something SQL superior something something my experience was something something

This is exactly what I expected from typing that dirty word onto the Internet.


MongoDB MongoDB MongoDB MongoDB MongoDB MongoDB MongoDB MongoDB MongoDB MongoDB MongoDB MongoDB MongoDB MongoDB MongoDB MongoDB
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
I'm just going to build a GUI interface in Visual Basic to track the IP address.
 

Joule

Member
whats wrong with this code?


the program doesn't run the cin.getline(response, 256) or anything after displaying what would you like to do. I did what the book told me to do

It looks like you're missing closing brackets for the while loop and the main (also the if statement but since it's only executing a single line of code it's not necessary). Additionally you'll want to have a cin.ignore() before your cin.getline(response, 256) to clear the buffer of the newline from your initial cin.getline otherwise it won't read any inputs because the delimiting character is a newline.

Code:
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
void MakeDeposit(); // new function with no parameters
void MakeWithdrawl(); // new function with no parameters
void GetBalance(); // new function with no parameters
float balance = 0;
float newBalance = 0;
float adjustment = 0;

int main(int argc, char* argv[]) {
  char response[256];
  string moreBankingBusiness;

  cout << "Do you want to do some banking? " << endl;
  cin >> moreBankingBusiness;


  for (int i = 0; i < moreBankingBusiness.length(); i++) {
    moreBankingBusiness[i] = toupper(moreBankingBusiness[i]);
  }

  while (moreBankingBusiness == "YES") {
    cout << "What would you like to do? <1 = Deposit, 2 = Withdraw, 3 = Get Balance): " << endl;
    cin.ignore();
    cin.getline(response, 256);
    if (strlen(response) == 0){
      cout << "You must make a selection" << endl;
    }
    else{
      cout << "Okay it worked" << endl;
    }
  }

system("pause");
return 1;

}
 

Gurrry

Member
You are assigning "true" to your variable spotted instead of comparing it. Just use

Code:
if (spotted)

(which is shorthand for if (spotted == true))

I could kiss you right now.

IT WORKS!!!

Jesus, such a tiny problem that I mislooked. I spent DAYS working on this code. lol.

Thank you so much!!
 
It looks like you're missing closing brackets for the while loop and the main (also the if statement but since it's only executing a single line of code it's not necessary). Additionally you'll want to have a cin.ignore() before your cin.getline(response, 256) to clear the buffer of the newline from your initial cin.getline otherwise it won't read any inputs because the delimiting character is a newline.

Code:
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
void MakeDeposit(); // new function with no parameters
void MakeWithdrawl(); // new function with no parameters
void GetBalance(); // new function with no parameters
float balance = 0;
float newBalance = 0;
float adjustment = 0;

int main(int argc, char* argv[]) {
  char response[256];
  string moreBankingBusiness;

  cout << "Do you want to do some banking? " << endl;
  cin >> moreBankingBusiness;


  for (int i = 0; i < moreBankingBusiness.length(); i++) {
    moreBankingBusiness[i] = toupper(moreBankingBusiness[i]);
  }

  while (moreBankingBusiness == "YES") {
    cout << "What would you like to do? <1 = Deposit, 2 = Withdraw, 3 = Get Balance): " << endl;
    cin.ignore();
    cin.getline(response, 256);
    if (strlen(response) == 0){
      cout << "You must make a selection" << endl;
    }
    else{
      cout << "Okay it worked" << endl;
    }
  }

system("pause");
return 1;

}

thanks for the help, i will check it out right now :)

edit - adding the cin.ignore(); fixed the issue. the book i am going through doesn't even mention it lol

really loving coding though. after i get through this book, i want to get into 3d programming which should be interesting ^_^

How is programming divided btw?

3D programming
software programming
OS programming
what are some other main branches?
 

GK86

Homeland Security Fail
Need help being pointed in the right direction.

I'm starting a programming internship in Jan. From what I have heard, they are big on web development and app development.

I have c++ and java knowledge (still a rookie for both). I barely have any time to really dig and try to learn these different languages since the internship starts fairly soon. But at the very least, I would like to have some idea before starting.

What is the best language for me to get my feet wet (in terms of learning web development)?

As for app development, is there a book that is recommended to learn about the environment and what the process is like? They would be dealing with Android and iOS. I'm more interested in this answer as I hope to get into app development after I graduate from college.

Thanks in advance for any help.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Need help being pointed in the right direction.

I'm starting a programming internship in Jan. From what I have heard, they are big on web development and app development.

I have c++ and java knowledge (still a rookie for both). I barely have any time to really dig and try to learn these different languages since the internship starts fairly soon. But at the very least, I would like to have some idea before starting.

What is the best language for me to get my feet wet (in terms of learning web development)?

As for app development, is there a book that is recommended to learn about the environment and what the process is like? They would be dealing with Android and iOS. I'm more interested in this answer as I hope to get into app development after I graduate from college.

Thanks in advance for any help.

Answer to question 1) JavaScript. Guarentee you will be working with that along with some other languages/frameworks, but starting with JavaScript will be your best bet. "JavaScript: The Good Parts" is a great book.

2) Focus on Android development first since you have a Java background. Better to focus then to try and learn both at once. Google's development resources are fairly good for this.
 

survivor

Banned
Just started using Node.js with MongoDB, Jade, etc.

This is some really, really cool stuff.

Used something similar past few months, it was pretty interesting stuff. Although I didn't use Jade, never liked how it completely transforms HTML, ended up sticking with Handlebars instead.
 
Top Bottom