• 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

sdijoseph

Member
This is super frustrating. There appears to be something wrong with MetalScrollBarUI in java. When I use this code:
Code:
        JScrollBar jsb = jScrollPane1.getVerticalScrollBar();
        ScrollBarUI sbui = new MetalScrollBarUI();
        jsb.setUI(sbui); // this is (NewJFrame.java:35)
I get this error message when I run the program:
Code:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at javax.swing.plaf.metal.MetalScrollBarUI.installDefaults(MetalScrollBarUI.java:90)
	at javax.swing.plaf.basic.BasicScrollBarUI.installUI(BasicScrollBarUI.java:168)
	at javax.swing.JComponent.setUI(JComponent.java:664)
	at javax.swing.JScrollBar.setUI(JScrollBar.java:207)
	at NewJFrame.<init>(NewJFrame.java:35)
	at NewJFrame$3.run(NewJFrame.java:176)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:701)
	at java.awt.EventQueue.access$000(EventQueue.java:102)
	at java.awt.EventQueue$3.run(EventQueue.java:662)
	at java.awt.EventQueue$3.run(EventQueue.java:660)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:671)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)

This person seems to have a similar problem, but when I tried to use his fix it just caused a new set of errors. Does anyone know what is going wrong here?

Edit: Never mind, to fix this I had to create a custom JForm template that used the "Metal" look and feel instead of "Nimbus".
 

Onemic

Member
C++ question:

Can someone explain what the significance of a pointer to a function/ function object is? My schools textbook makes it seem as though its main purpose is that you can call a function in another functions parameter list, but you could already do that anyway, without having to do a pointer to a function.
 

OceanBlue

Member
C++ question:

Can someone explain what the significance of a pointer to a function/ function object is? My schools textbook makes it seem as though its main purpose is that you can call a function in another functions parameter list, but you could already do that anyway, without having to do a pointer to a function.

I imagine that the main differences are that you can parameterize the object or have the object hold internal state. The function object can hold method parameters itself instead of needing everything to be supplied to it.
 

Husker86

Member
I have to do a small university project in JavaScript/Node.js, which I'm not that familiar with. I need to loop through an array of files and folders, find a folder with a specific name and return its id (= supplying it to the callback function). If no such folder exists, it should be created. Here's the relevant snippet:

This sucks. There's no need to keep iterating through the array when the folder has already been found. I tried the following:
Code:
function(..., fn) {
  items.forEach(function(item) {
    if(item.name === folderName) {
      fn(item.id);
      return;
    }
  });
    
  createFolder(folderName, fn);
}

Much more concise. But for some reason, createFolder is always called, even when a folder is found. Had I simply called the callback function, I would understand that - but there's a return afterwards. Could someone give me a hint, please?

Create folder will always be called in that case because the call to createFolder is outside the loop block and will always be called after the loop is finished.

Now, I'm very much a beginner so if the following violates some best practices, I apologize.

How about something like this:
Code:
function(..., fn) {
  var match = false;
  items.forEach(function(item) {
    if(item.name === folderName) {
      fn(item.id);
      match = true;
      return;
    }
  });

  if(!match){
    createFolder(folderName, fn);
  }  
  
}
 

Water

Member
C++ question:

Can someone explain what the significance of a pointer to a function/ function object is? My schools textbook makes it seem as though its main purpose is that you can call a function in another functions parameter list, but you could already do that anyway, without having to do a pointer to a function.
What's fundamentally happening is that we're giving a function A as a parameter to another function B. Function pointers/objects are just language detail; more civilized languages let you pass any function at any time without this obscure stuff.

Doing it allows us to use different "A" functions to customize some aspect of what function B is doing, instead of having to hardcode that logic variation into B1, B2, B3, ... Consider the problem of sorting objects in some order. Do you want to write billions of implementations of a sorting algorithm to cover every imaginable criteria to sort every kind of object with? Or do you write one sort implementation, and let the caller of the sort specify the desired sorting criteria by passing in a function which determines the correct order of two objects of type being sorted?
Code:
// sorting in standard C++
auto v = vector<int>{3, 2, 5, 7, 8};
sort(begin(v), end(v)); // sorts in ascending order by default
sort(begin(v), end(v), [](int a, int b){return a>b;}); // sort in descending order
sort(begin(v), end(v), [](int a, int b){return abs(a)<abs(b);}); // sort by absolute value
 

Ambitious

Member
In your second version, your "return" only exits the forEach-function, not the fn()-function it's wrapped in.

you could use Array.some instead of Array.forEach

the return is only returning from the current forEach iteration. It will finish doing those then call createFolder regardless. Your first example is closer to what you want.

Create folder will always be called in that case because the call to createFolder is outside the loop block and will always be called after the loop is finished.

Now, I'm very much a beginner so if the following violates some best practices, I apologize.

How about something like this:
Code:
function(..., fn) {
  var match = false;
  items.forEach(function(item) {
    if(item.name === folderName) {
      fn(item.id);
      match = true;
      return;
    }
  });

  if(!match){
    createFolder(folderName, fn);
  }  
  
}

Ah, yes. I totally missed that. Thanks!
 

Onemic

Member
What's fundamentally happening is that we're giving a function A as a parameter to another function B. Function pointers/objects are just language detail; more civilized languages let you pass any function at any time without this obscure stuff.

Doing it allows us to use different "A" functions to customize some aspect of what function B is doing, instead of having to hardcode that logic variation into B1, B2, B3, ... Consider the problem of sorting objects in some order. Do you want to write billions of implementations of a sorting algorithm to cover every imaginable criteria to sort every kind of object with? Or do you write one sort implementation, and let the caller of the sort specify the desired sorting criteria by passing in a function which determines the correct order of two objects of type being sorted?
Code:
// sorting in standard C++
auto v = vector<int>{3, 2, 5, 7, 8};
sort(begin(v), end(v)); // sorts in ascending order by default
sort(begin(v), end(v), [](int a, int b){return a>b;}); // sort in descending order
sort(begin(v), end(v), [](int a, int b){return abs(a)<abs(b);}); // sort by absolute value

Thanks for the explanation


And with that I have a little problem with regards to a function object I'm making. The compiler keeps telling me theres no suitable constructor to convert a float to a float* and I'm unsure as to why. If anyone can give me any tips on this it would be appreciated:

Code:
#include <iostream>
#include <iomanip>
#include <cstdlib>

[B]template<typename T>
class weighted {
public:
    double operator()(T a, T b, float wa, float wb) {return (a * wa) + (b * wb)};
};[/B]

[B]
template <typename T>
void transform(const T* a, const T* b, T* c, unsigned n,
    float wa, float wb, const weighted<T>& weight
    ) {
    for (unsigned i = 0; i < n; i++)
        c[i] = f(a[i], b[i]);
}[/B]



int main(int argc, char* argv[]) {
    std::cout << "\nCommand Line : ";
    for (int i = 0; i < argc; i++) {
        std::cout << argv[i] << ' ';
    }
    std::cout << std::endl;
    if (argc != 4) {
        std::cerr << "\n***Incorrect number of arguments***\n";
        return 1;
    }
    unsigned n = std::atoi(argv[1]);
    float wa = std::atof(argv[2]);
    float wb = std::atof(argv[3]);

    // initialize
    float* a = new float[n];
    float* b = new float[n];
    float* c = new float[n];
    for (unsigned i = 0; i < n; i++) {
        a[i] = b[i] = (float)i * 0.1f;


   [B]     transform(a, b, c, n, wa, wb, weighted<float>(a, b, wa, wb));[/B]
        // output results
        std::cout << std::fixed << std::setprecision(2);
        for (unsigned i = 0; i < n; i++)
            std::cout << a[i] << " + " << b[i] << " = "
            << c[i] << std::endl;

        // clean up
        delete[] a;
        delete[] b;
        delete[] c;

        std::cout << "Press any key to continue ... ";
        std::cin.get();
    }
 
Thanks for the explanation
And with that I have a little problem with regards to a function object I'm making. The compiler keeps telling me theres no suitable constructor to convert a float to a float* and I'm unsure as to why. If anyone can give me any tips on this it would be appreciated:

Your call to transform is not right. You need to initialized weighed first, as a const object and then pass it to the function, like this:
Code:
const weighed<float> w;
transform(a, b, c, n, wa, wb, w);

The definition of your transform function is also not quite right, you need to do c = weighed(...);, the f variable doesn't exist.
 

Onemic

Member
Your call to transform is not right. You need to initialized weighed first, as a const object and then pass it to the function, like this:
Code:
const weighed<float> w;
transform(a, b, c, n, wa, wb, w);

The definition of your transform function is also not quite right, you need to do c = weighed(...);, the f variable doesn't exist.


Thanks, this makes so much more sense. The lone example my class textbook gave me on class functions the class is never initialized in the main.
 

survivor

Banned
So Javascript callbacks sorta giving me a trouble. Not sure if there is a simple solution to this issue cause it's getting late and I'm not thinking hard enough or it's just the way it should be done but if I have following code
Code:
if (condition) {
    writeToFile(function() {
        database.save(function() {
            render();
        });
    });
}
database.save(function()
    render()
});
Is there a way to avoid having to write the database.save() stuff twice or is there no way around how these callbacks work with writing to files and saving to database?
 

Slavik81

Member
Thanks for the explanation


And with that I have a little problem with regards to a function object I'm making. The compiler keeps telling me theres no suitable constructor to convert a float to a float* and I'm unsure as to why. If anyone can give me any tips on this it would be appreciated:

Code:
    // initialize
    float* a = new float[n];
    float* b = new float[n];
    float* c = new float[n];
    for (unsigned i = 0; i < n; i++) {
        a[i] = b[i] = (float)i * 0.1f;


   [B]     transform(a, b, c, n, wa, wb, weighted<float>(a, b, wa, wb));[/B]
        // output results
        std::cout << std::fixed << std::setprecision(2);
        for (unsigned i = 0; i < n; i++)
            std::cout << a[i] << " + " << b[i] << " = "
            << c[i] << std::endl;

        // clean up
        delete[] a;
        delete[] b;
        delete[] c;

        std::cout << "Press any key to continue ... ";
        std::cin.get();
    }
This is unrelated, but your calls to new[] are outside the loop, while the calls to delete[] inside loop. That's a recipe for 'a double free' error.

EDIT: Actually, I initially assumed the missing bracket cut-off when you copy/pasted, but I think you just forgot to close the first for loop.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Are any of you here familiar with the difference in web touch events between iOS 7 and iOS 8?

I have an odd bug in my whiteboard drawing web app where it works on everything except an iOS 8 device. The program is using Javascript and the drawing is handled through paperscript (paper.js).
My research has led to the change in how scroll events are handled, but my page doesn't have any scrolling.
 
I'm looking for some projects to do outside of work for fun/build skills. Anyone here involved in any cool open source projects?

I think this post from last page is good advice for that sort of thing:
No offense, but "please throw this dog a bone" is a pretty bad way to approach this situation. I understand that you are frustrated, but it's very unlikely that a simplish GitHub project falls from the sky and on to your lap.

Did you know that GitHub has a section called Explore (https://github.com/explore), which lists all kinds of types of projects, listed by categories, trending topics and so on? What I'd suggest is:

1) Go to GitHub Explore
2) Sort by your programming language(s) of choice
3) Look at the projects
4) Find the ones that interest you personally. If any of them don't,
sorry you might be on the wrong field :p
5) Look if they accept contributions (which they often do)
6) Sort the issues for pick-me-ups, beginner tasks and so on.
7) Pick one and start working on it.
 

hateradio

The Most Dangerous Yes Man
So Javascript callbacks sorta giving me a trouble. Not sure if there is a simple solution to this issue cause it's getting late and I'm not thinking hard enough or it's just the way it should be done but if I have following code
Code:
if (condition) {
    writeToFile(function() {
        database.save(function() {
            render();
        });
    });
}
database.save(function()
    render()
});
Is there a way to avoid having to write the database.save() stuff twice or is there no way around how these callbacks work with writing to files and saving to database?
You could store it in a variable if the save method returns an instance/callback or you can wrap it in a new function.

Code:
// only works if save returns a callback
var renderOnSave = database.save(function()
    render()
});

// create a generic callback for later use
var renderOnSave = function() {
	database.save(function() {
		render();
	}
};

// special note
// if render() is a generic callback you can actually supply it directly

var renderOnSave = function() {
	database.save(render);
};


// use it now

if (condition) {
    writeToFile(renderOnSave);
}

renderOnSave();
 

GaimeGuy

Volunteer Deputy Campaign Director, Obama for America '16
So, I'm trying to figure out how to track what kind of event a code thread is currently processing without having to pass this information along from function to function within the thread, in C++

Consider a system where two mirrors publish information to a common listener.

Code:
class MirrorA
{
  void one(int a) {  m_mirrrorListener.three(a); }
};

class MirrorB
{
  void two(int b) {  m_mirrrorListener.three(b); }
};

class MirrorListener
{
  void three(int c) { std::cout << c << std::endl; }
};

Now, let's say the listener needs to know if it was triggered by MirrorA, or by MirrorB

We can pass along this information as such:

Code:
enum mirrorSource_t
{
  FROM_ONE = 1,
  FROM_TWO = 2
}

class MirrorA
{
  void one(int a) {  m_mirrrorListener.three(a, FROM_ONE); }
};

class MirrorB
{
  void two(int b) {  m_mirrrorListener.three(b, FROM_TWO); }
};

class MirrorListener
{
  void three(int c, mirrorSource_t source) { std::cout << c << " From " << source << std::endl; }
};

But then we have to update the signature of three and its invocation whenever it needs new information.

So, what if we had a singleton message tracking class, that could track an arbitrary number of messages?
Code:
class MirrorMessage
{
  public:
    MirrorMessage(mirrrorSource_t t) :  source(t)  {}
    get() { return source; }

  private:
    mirrorSource_t  source;
};

class MirrorMessageTracker
{
  public:
      boost::shared_ptr<MirrorMessage>&    MirrorMessageTracker::trackEvent(mirrorSource_t value)
      {
        trackedMessages.push_back(MirrorMessage(value));
        return trackedMessages.back();
      }

       boost::shared_ptr<MirrorMessage>&  MirrorMesssageTracker::getCurrentEvent()
      {
        return trackedMessages.back();
      }

      static MirrorMessageTracker& getInstance()
      { 
        if(!m_pTracker)
        {
           m_pTracker = new MirrorMessageTracker();
        }
        return *m_pTracker; 
      }

  private:
      MirrorMessageTracker() { };
      MirrorMessageTracker(const MirrorMessageTracker&); 
      MirrorMessageTracker& operator=(const MirrorMessageTracker&);
      static MirrorMessageTracker* m_pTracker;
      std::vector<boost::shared_ptr<MirrorMessage> > trackedMessages;
};

The problem is vector::push_back would create a copy and place it into the tracker, right? So how can I ensure that in this code:

Code:
class MirrorA
{
  void one(int a)
  {
    MirrorMessage createdMessage = m_MirrorMessageTracker.trackMessage(FROM_ONE);
    m_mirrrorListener.three(a);
  }
};

class MirrorB
{
  void two(int b)
  {
    MirrorMessage createdMessage = m_MirrorMessageTracker.trackMessage(FROM_TWO);
    m_mirrrorListener.three(b);
  }
};

class MirrorListener
{
  void three(int c) 
  {
    MirrorMessage& message = m_MirrorMessageTracker.getCurrentMessage();
    if (message.get() == FROM_ONE)
    {
      std::cout << c << std::endl;
    }
    else if (message.get() == FROM_TWO)
    {
      std::cout << c << c << std::endl;
    }
    else
    {
      std::cout << c << c << c << std::endl;
    }
  }
};

the tracked message is removed from the tracker when either one() or two() goes out of scope?

Feels like I need some kind of a factory somewhere.
 

maeh2k

Member
So, I'm trying to figure out how to track what kind of event a code thread is currently processing without having to pass this information along from function to function within the thread, in C++

To me it feels like you were on the right track the first try. Why not just put the necessary information into the listener, when you call it? Makes it really simple to understand what's happening.
If you have lots of internal methods where you'd need to pass through that information, you might be able to use a Method Object, that stored that information in a field every internal method has access to.
 

Water

Member
The problem is vector::push_back would create a copy and place it into the tracker, right? So how can I ensure that in this code:
...
the tracked message is removed from the tracker when either one() or two() goes out of scope?

Feels like I need some kind of a factory somewhere.
I'm not totally convinced the thing you're trying to fix is an actual problem, and that the second form of the code is actually better. With the changes, you have more code than before even in MirrorA, MirrorB and MirrorListener, never mind the extra machinery outside them.

So what is your exact motivation for not simply giving a function the data it needs as arguments? Some kind of code maintainability? (What kind of future extensions are realistically possible?) Performance?

As an answer to the specific question you posed (how to get the message removed from tracker automatically): instead of a MirrorMessage, can't you just return a holder object from MirrorMessageTracker that keeps a pointer/ref to the Tracker and removes the message when the holder goes out of scope? Alternatively, at the call site you could create a ScopeGuard which does the removal, then you wouldn't need a custom class.
 

GaimeGuy

Volunteer Deputy Campaign Director, Obama for America '16
What do you mean by a holder? Like something which upon construction tells the tracker to generate the tracked message, and on destructure to remove it? A trigger class for the tracker to add or remove a message, in other words? I guess that would work.
And yeah, maintainability is a concern.
 

Onemic

Member
I need to use a vector to store each line of code. How would I go about doing this? I need to read:

Code:
 10012 34.56
 10023 45.67 H
 10234 12.32 P
 10056 67.54
 10029 54.12 H
 10034 96.30

So I would assume that I'd need to create a float vector, but how do I also read in these random characters at the end of some of the records?

This is unrelated, but your calls to new[] are outside the loop, while the calls to delete[] inside loop. That's a recipe for 'a double free' error.

EDIT: Actually, I initially assumed the missing bracket cut-off when you copy/pasted, but I think you just forgot to close the first for loop.

Yup, that brace wasn't necessary
 
I need to use a vector to store each line of code. How would I go about doing this? I need to read:

Code:
 10012 34.56
 10023 45.67 H
 10234 12.32 P
 10056 67.54
 10029 54.12 H
 10034 96.30

So I would assume that I'd need to create a float vector, but how do I also read in these random characters at the end of some of the records?

Well, it looks like you have three values in each line. An int, a double, and a char. So you wouldn't want a vector of a primitive type, you would want a vector of a struct that contains fields for all three values.

You can store the blank chars using a space or a null.
 

2SeeKU

Member
Just thought l'd mention the following if any of you in the thread are confident in C# but would like to dabble in iOS programming:

I've just completed a game l've been working on for the last few weeks/months. It's a Find-a-word game with a twist. Once you select a word, the letters above fall into it's place, completely changing the board. If you're interested, check it out here: App Store - LetterMASH Homepage.

Anyway, l programmed this in the Xamarin/Monotouch environment:
http://xamarin.com/

To get started was a breeze with all their example apps, and once you get familiar with the iOS frameworks, it's a breeze to code in.

They have a free tier, but you may come into their size limit sooner or later (the free tier only lets you build apps up to a certain size limit).

Anyway, if you're interested, I suggest you give it a go!
 

Water

Member
What do you mean by a holder? Like something which upon construction tells the tracker to generate the tracked message, and on destructure to remove it?
No, an object which the tracker builds, and which upon its own destruction removes a particular message from the tracker.
And yeah, maintainability is a concern.
I have no idea why you think this setup would lead to better maintainability. Looks like less to me, in fact. More code, more complicated code, even has a singleton which are generally bad for maintainability, testing, etc.

The very fact the first version of the code is minuscule means there's no harm in starting from it, and only switching to something more complicated if and only if it's clearly visible that a more complicated setup is becoming necessary.
 

survivor

Banned
You could store it in a variable if the save method returns an instance/callback or you can wrap it in a new function.

Code:
// only works if save returns a callback
var renderOnSave = database.save(function()
    render()
});

// create a generic callback for later use
var renderOnSave = function() {
	database.save(function() {
		render();
	}
};

// special note
// if render() is a generic callback you can actually supply it directly

var renderOnSave = function() {
	database.save(render);
};


// use it now

if (condition) {
    writeToFile(renderOnSave);
}

renderOnSave();

Thanks, that can probably clean up the code better, just gotta refactor through all the callbacks mess I created.
 

Slavik81

Member
And yeah, maintainability is a concern.
Having two paths that data travels along between threads makes it very complex, especially because they need to be synchronized. I've seen that sort of getSender function before, but it don't think I could justify the complexity as a part of a single component. Maybe in a messaging library, but I'm still not sure it's a great solution.

If you don't want to ever have to change the signature, you could stuff whatever origin data you care about into a struct. Add fields to the struct as needed, and use constructors or factory functions appropriately.
 

Ashes

Banned
My progress has been abysmal. I had just too many things going on, so I had to drop this this month.
Hopefully, I shall come back with a vengeance next month.
 

squidyj

Member
I'm curious if there's a way to predict or automatically generate a variable name in c++
I have a swizzle class that uses reference variables to allow my swizzles to be member variables of vectors but actually creating and initializing more than a small handful is an awkward block of code.

Also I know that unrestricted unions are a feature of C++ 11 but one that is not supported by any visual studio compiler that I am aware of. Is there any way to work around that limitation for anonymous unions involving structs that have constructors. Or can I work around the visual studio compiler and use gcc or clang which has support?
 
Are any of you here familiar with the difference in web touch events between iOS 7 and iOS 8?

I have an odd bug in my whiteboard drawing web app where it works on everything except an iOS 8 device. The program is using Javascript and the drawing is handled through paperscript (paper.js).
My research has led to the change in how scroll events are handled, but my page doesn't have any scrolling.

I did some of this on ios7 last year and I vaguely remember it being a css issue. Dunno what they changed in ios8 to make it not work.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
I did some of this on ios7 last year and I vaguely remember it being a css issue. Dunno what they changed in ios8 to make it not work.

Do you have any more details?

The only CSS I'm using is basic Bootstrap. I don't believe paper.js is leveraging CSS at all, but I could be wrong.
 

w3bba

Member
Actually finished a programming assignment not an hour before a deadline. What do I do with all this time Gaf.

I-dont-believe-you.gif
 

Pinewood

Member
Cant figure out how to fix this programming issue I'm having.
So basically I have to remove items from a vector if they are present in the other vector. Problem is, If I actually delete anything, the program goes bonkers and stops working. I know this is most likely caused by me deleting an item from the vector thats size is tied to a for loop. Unfortunately I cant figure out a way to make this work.
Code:
void dispatch(Order *disp)
    {
        bool mistake = true;
        for(int j = 0; j < disp->getSize(); j++)
        {

            for(int k = 0; k<stocked.size(); k++)
            {
                if(disp->getOrderName(j).compare(stocked[k]->giveName()) == 0)
                {
                    stocked[k] = NULL;
                    //mistake = false;
                    return;
                }
            }
         
            if(mistake)
                {
                    cout<<"An Error occured.\n";
                    return;
                }
        }
    }
Nevermind the mistake part in the code.

Edit: Apparently adding k=stocked.size(); before deleting an element did the job. Also tried break after deleting but that didn't help. Not sure if this is the best courese of action, but it works...
Double Edit: Well that actually did not work as intended. I still need advice.
Threes the charm: Got a solution. Apparently had to check if an element was NULL before comparing it to something. Otherwise it went bonkers.
 

hitsugi

Member
C++ is the GOAT of programming languages.

My school started us off with C++.. I took nearly 2 years of C++ classes and ended up with a job where I have to learn Java and it feels so damn wordy to me.
 
C++ is the GOAT of programming languages.

My school started us off with C++.. I took nearly 2 years of C++ classes and ended up with a job where I have to learn Java and it feels so damn wordy to me.

If you had to do a lot of work in C++ I'm not sure if your opinion would be the same.
 

Sharp

Member
C++ is the GOAT of programming languages.

My school started us off with C++.. I took nearly 2 years of C++ classes and ended up with a job where I have to learn Java and it feels so damn wordy to me.
There are more languages in the world than Java and C++ :)
 
Do you have any more details?

The only CSS I'm using is basic Bootstrap. I don't believe paper.js is leveraging CSS at all, but I could be wrong.

I found this in my bookmarks from the project:

http://www.kylejlarson.com/blog/2011/fixed-elements-and-scrolling-divs-in-ios-5/

The project was a bit of an odd thing, it used an iPad hooked up to a monitor and the iPad was viewing a webpage in a UI webview, and clicks and scrolls that the user did on the iPad would be reflected on the monitor. I had to write bridging code that would go from JavaScript to Objective-C for some stuff.

In the end it didn't work as well as the client wanted because UIWebview performance was poop on iOS7.

Cant figure out how to fix this programming issue I'm having.
So basically I have to remove items from a vector if they are present in the other vector. Problem is, If I actually delete anything, the program goes bonkers and stops working. I know this is most likely caused by me deleting an item from the vector thats size is tied to a for loop. Unfortunately I cant figure out a way to make this work.
Code:
void dispatch(Order *disp)
    {
        bool mistake = true;
        for(int j = 0; j < disp->getSize(); j++)
        {

            for(int k = 0; k<stocked.size(); k++)
            {
                if(disp->getOrderName(j).compare(stocked[k]->giveName()) == 0)
                {
                    stocked[k] = NULL;
                    //mistake = false;
                    return;
                }
            }
         
            if(mistake)
                {
                    cout<<"An Error occured.\n";
                    return;
                }
        }
    }
Nevermind the mistake part in the code.

Edit: Apparently adding k=stocked.size(); before deleting an element did the job. Also tried break after deleting but that didn't help. Not sure if this is the best courese of action, but it works...
Double Edit: Well that actually did not work as intended. I still need advice.
Threes the charm: Got a solution. Apparently had to check if an element was NULL before comparing it to something. Otherwise it went bonkers.

Glad to hear you figured it out, but yes, in general if you use the size of a dynamic container as a condition on an array and you change the size of the container during the execution of that loop things can go a bit haywire. At least with for loops.
 
C++ is the GOAT of programming languages.

My school started us off with C++.. I took nearly 2 years of C++ classes and ended up with a job where I have to learn Java and it feels so damn wordy to me.
C++ gets syntactically hairy fast though. Never mind good code practices; it's difficult to get consistent code between people if there's no, or lax, code style guides.
 

hitsugi

Member
There are more languages in the world than Java and C++ :)

Of course, I'm just coming to appreciate C++ a lot more.. when I was new to it (and I'm sure compared to many people, I still am), I felt it was too wordy compared to Python. It's all highly subjective :D
 
Top Bottom