• 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

r1chard

Member
Unit testing is like a functional, self-contained bit of code right?
Basically yeah. It exercises a bit of code directly to ensure that bit of code does what it says on the box. Typically unit tests are independent, idempotent, exercise small units of source, and are clear to understand - because if you break one you want to know how and why :) [this is my gripe with Javascript testing - it's very often a magical mix of implicit and unstated behaviors just to get a test working]

The place I work runs using scrum methods. A component of that is all code is tested (ie coverage is over 100%). I also apply the same test regime to all of my recent open source projects.
 
I'm studying Unity right now. I'm messing around with how 2D overheat shooters work. I've got experience making 2D games on Flash and I'm trying to translate it into Unity. So far it's going fine. Some things I'm pondering, but it's more of software design.

1. How do people handle "globals"? Like, it's where I dump game state (top score) or some constants. I don't like the idea of making the HUD itself keep track of the score. I googled around and saw people just putting an invisible object on the scene then put the script there, but that feels pretty dirty. Is there not a cleaner way?

2. How do people handle bullets? Right now, I'll most likely put the script on the bullet prefab to make itself move indefinitely and remove itself after some time. Where would I want to keep track of bullets? I can keep track of bullets in the script attached to the player right now. Should I put it on the "global script" instead?
 

Water

Member
I'm studying Unity right now. I'm messing around with how 2D overheat shooters work. I've got experience making 2D games on Flash and I'm trying to translate it into Unity. So far it's going fine. Some things I'm pondering, but it's more of software design.

1. How do people handle "globals"? Like, it's where I dump game state (top score) or some constants. I don't like the idea of making the HUD itself keep track of the score. I googled around and saw people just putting an invisible object on the scene then put the script there, but that feels pretty dirty. Is there not a cleaner way?
It is dirty, but normal in Unity. Another option would be to put that global state in a singleton class (also dirty, but in a different way) that effectively exists outside the Unity scene.
2. How do people handle bullets? Right now, I'll most likely put the script on the bullet prefab to make itself move indefinitely and remove itself after some time. Where would I want to keep track of bullets? I can keep track of bullets in the script attached to the player right now. Should I put it on the "global script" instead?
Why do you need to keep track of the bullets?
 

iapetus

Scary Euro Man
Unfortunate.

You can also use Scala, but I haven't really done that yet. Would be a lot nicer.

Java really isn't that bad. I've worked in far worse, and it's a perfectly acceptable language even if it isn't the flavour of the day (I find myself disliking some of the languages that are...)
 
Java really isn't that bad. I've worked in far worse, and it's a perfectly acceptable language even if it isn't the flavour of the day (I find myself disliking some of the languages that are...)
And what is fotm/fotd language then?
I have a solid understanding of java, system integration (web services in all flavour and security concerns), a REALLY WIDE knowledge of ecm (documentum, but i have some solid knowledge on backend alfresco)..
Personally any enterprise application ends up either being java based (with spring/hibernate and usually i add thymeleaf) or c# based..
I've seen some stuff in ruby, but never something on EA level..
Even html5 while fine and dandy is something that at least in Italy is REALLY far away from enterprise application since i could name countless of big clients of our (h3g Italy ecm was rebuilt from scratches from my company and i joined first as senior dev, then as lead dev, Vodafone platform where i was an analyst, Mediaset where i developed StuffIt the backend for their alfresco, etc) and they ALL want to be able to use the system with their extremely old master image with ie6 or at most 7...

Anyway, your comment intrigues me, so indulge me..
What should i nosedive into if i want to learn something new as far as programming language//technology stacks go?
 
It is dirty, but normal in Unity. Another option would be to put that global state in a singleton class (also dirty, but in a different way) that effectively exists outside the Unity scene.
I see. It just reminded me of the ancient Flash tutorials which had a lot of bad advice. I thought it was the same in Unity.

Why do you need to keep track of the bullets?
Various reasons, but not really just for bullets. For example, I may need to spawn enemy prefabs and might need some variable from them. There may also be an event in my game which would require calling a method on all the prefabs I instantiated.
 

moka

Member
anyone ever done any basic natural language processing in prolog? i've designed a little crappy text based game and want to allow the user to enter basic commands like 'go to bank', 'goto bank',' move to bank' etc.

on a slightly unrelated note, i'm very disappointed gaf. i recently failed my interview at GCHQ but hopefully i'll still find a placement ha
 

Water

Member
In C++/C how would you be able to check if a null terminated string a user input only contains digits?
Code:
bool check(const std::string& s) {
    return std::all_of(begin(s), end(s),
        [](char c){ return '0' < c && c < '9'; });
}
edit: note that you can pass the null terminated string directly to this function; std::string has a constructor that takes a null terminated string, so the std::string will be automatically constructed.
 

hateradio

The Most Dangerous Yes Man
Java really isn't that bad. I've worked in far worse, and it's a perfectly acceptable language even if it isn't the flavour of the day (I find myself disliking some of the languages that are...)
I wouldn't say Scala is the flavor of now, but it is getting into its groove. I do imagine that its popularity will grow more the next few years. I think it's biggest gain was when Twitter switched to it from Ruby.

However, the language is great. It blends functional and OO elements very well, and it's refreshing compared to Ruby or Java -- even Java 8 seems like a misstep when you compare it to the way Scala handles things, but that's probably due to Java's general crotchetiness.

There's a lot of right in Scala, while there are a lot of questionable aspects in Java. As you said it "isn't that bad" but there is something better. (imo)
 

Slavik81

Member
Code:
bool check(const std::string& s) {
    return std::all_of(begin(s), end(s),
        [](char c){ return '0' < c && c < '9'; });
}
edit: note that you can pass the null terminated string directly to this function; std::string has a constructor that takes a null terminated string, so the std::string will be automatically constructed.

If you include <cctype> you can use std::isdigit rather than that custom lambda. Speaking of which, you're excluding '0' and '9' as digits.

In C++/C how would you be able to check if a null terminated string a user input only contains digits?
For C, you'd want something sort of like this.
Code:
#include <ctype>
bool isonlydigits(const char* s) {
  for (const char* c = s; c != '\0'; ++c) {
    if (!isdigit(c)) {
      return false;
    }
  }
  return true;
}
(disclaimer: code has not been compiled or tested)
 

Water

Member
If you include <cctype> you can use std::isdigit rather than that custom lambda. Speaking of which, you're excluding '0' and '9' as digits.
Thanks. That's what I get for posting late at night. :p So the fixed C++ code is just:
Code:
bool all_digits(const std::string& s) {
    return std::all_of(begin(s), end(s), isdigit)
}
This time I compiled and tested to be sure.
 
I wouldn't say Scala is the flavor of now, but it is getting into its groove. I do imagine that its popularity will grow more the next few years. I think it's biggest gain was when Twitter switched to it from Ruby.

However, the language is great. It blends functional and OO elements very well, and it's refreshing compared to Ruby or Java -- even Java 8 seems like a misstep when you compare it to the way Scala handles things, but that's probably due to Java's general crotchetiness.

There's a lot of right in Scala, while there are a lot of questionable aspects in Java. As you said it "isn't that bad" but there is something better. (imo)

Scala really is cool, however it does have questionable aspects too. I think the collection library, while it is very powerful, is very complex as well. Just look at the inheritance chain for List[A]:
LinearSeqOptimized[A, List[A]], Product, LinearSeq[A], collection.LinearSeq[A], LinearSeqLike[A, List[A]], Seq[A], Iterable[A], Traversable[A], Immutable, AbstractSeq[A], collection.Seq[A], SeqLike[A, List[A]], GenSeq[A], GenSeqLike[A, List[A]], PartialFunction[Int, A], (Int) &#8658; A, AbstractIterable[A], collection.Iterable[A], IterableLike[A, List[A]], Equals, GenIterable[A], GenIterableLike[A, List[A]], AbstractTraversable[A], collection.Traversable[A], GenTraversable[A], GenericTraversableTemplate[A, List], TraversableLike[A, List[A]], GenTraversableLike[A, List[A]], Parallelizable[A, ParSeq[A]], TraversableOnce[A], GenTraversableOnce[A], FilterMonadic[A, List[A]], HasNewBuilder[A, List[A] @scala.annotation.unchecked.uncheckedVariance], AnyRef, Any
I know that this doesn't matter to someone who's just using the libraries, but if that's best practice for Scala development, ugh.

Secondly, the language is extremely powerful. As always, that is both good and bad. I think libraries sometimes go overboard with the "let's make a DSL!" or "Let's make weird custom operators for everything!". (see ScalaTest or Specs2) At first it's really neat that you write a test almost like a specification (example here) but it can be a pain in the ass to debug (compiler errors for DSL-ish code tend to be pretty arcane).

Implicits are similar, they allow you to write really concise code, but I've very often had to look up what weird package to import to get the right implicit conversions in scope. (ScalaFX, I'm looking at you) Also, while the documentation for the Scala libraries that I've used (mostly Akka, ScalaFX, Play 2 and ScalaTest) is generally quite good, I often had very little success with StackOverflow/Google when I ran into a problem because they are not that popular yet.

I guess my complaints are mostly with the libraries. I hope this will get better over time as more people start using it.
 

usea

Member
There is a lot of negative sentiment out there about Scala, and a lot of it is deserved I think. It tries to do everything, be everything and enable a programmer to do anything. There's a lot to be said about simplicity, but Scala eschews simplicity for feature bloat, much like C++.
 

hateradio

The Most Dangerous Yes Man
Scala really is cool, however it does have questionable aspects too. I think the collection library, while it is very powerful, is very complex as well. Just look at the inheritance chain for List[A]:
I know that this doesn't matter to someone who's just using the libraries, but if that's best practice for Scala development, ugh.
That is probably more than triple the number of classes that a Java collection would inherit. It's a very complex hierarchy, and a lot of throught went into that layering.

I guess my complaints are mostly with the libraries. I hope this will get better over time as more people start using it.
I hope so, too.

There is a lot of negative sentiment out there about Scala, and a lot of it is deserved I think. It tries to do everything, be everything and enable a programmer to do anything. There's a lot to be said about simplicity, but Scala eschews simplicity for feature bloat, much like C++.
That seems like an unfair assertion on the language. I don't think it tries to do everything -- at its core it converges functional and OO paradigms. Functional languages aren't the easiest to work with at first. Same with OO languages. It might be difficult (eschewing simplicity) in that respect; by merging two worlds, it is "doing too much." However, once you understand the fundamentals of Scala, I don't think you can really believe that it tries to do everything or that it's bloated or that it lets the developer do everything (that last one is a little odd).

There is a learning curve to it, more than a typical language, but those willing to learn it tend to have a high regard for it.
 
which would you guys recommend to a generalist software developer? an i5 or i7 desktop cpu?
Hardly matters to be honest, unless you're doing stuff that's very CPU intensive, like things you might see in higher level undergraduate degrees. You probably wouldn't even encounter them.

I would prioritize an SSD and 8GB RAM over a beefy processor. SSD because it's SSD, and RAM because I hate it when Windows has to resort to virtual memory. I only have 4GB at work which doesn't feel enough for me.
 

leroidys

Member
which would you guys recommend to a generalist software developer? an i5 or i7 desktop cpu?

Hardly matters to be honest, unless you're doing stuff that's very CPU intensive, like things you might see in higher level undergraduate degrees. You probably wouldn't even encounter them.

I would prioritize an SSD and 8GB RAM over a beefy processor. SSD because it's SSD, and RAM because I hate it when Windows has to resort to virtual memory. I only have 4GB at work which doesn't feel enough for me.

.
 

Water

Member
However, once you understand the fundamentals of Scala, I don't think you can really believe that it tries to do everything or that it's bloated or that it lets the developer do everything (that last one is a little odd).

There is a learning curve to it, more than a typical language, but those willing to learn it tend to have a high regard for it.
A friend whose judgment I trust gave up on Scala because he couldn't make it compile his project reasonably fast no matter what he tried. I have only learned Scala in a vacuum, haven't used it on actual projects, and it's nice on the surface but everywhere I look, things just feel a bit off and not consistent. I figure some of that is due to the capabilities of JVM, some due to how Scala tries to keep syntax somewhat close to Java instead of being a clean slate, and some due to deliberately under-defined behavior reserving room for language changes (!). Scala does seem nicer than Java in general, but if I had to work on JVM, I think I'd start learning Clojure.
 

Ydahs

Member
Just thought I'd drop in and say that C#'s deserialization library is amazing with the use of DataContract and DataMember. Always found JSON deserialization to be an extremely tedious task in Java and C# but these attributes make it so bloody easy.
 

usea

Member
Here's a talk by a guy who worked at Typesafe on the Scala compiler, who complains about the language and its implementation for 50 minutes. Although to be fair he loves it, he just has a lot of complaints, too. https://www.youtube.com/watch?v=TS1lpKBMkgg

Here's a talk by Rich Hickey (Clojure creator) about simplicity in programming, and how constraints make a better experience. Basically why languages like Scala and C++ give you too many tools. http://www.infoq.com/presentations/Design-Composition-Performance

I'm not trying to say Scala sucks or whatever (on the contrary). I just found these talks really interesting. I like thinking about the design philosophies in programming languages. The idea of how "opinionated" a language should be, how much rope they should give the programmer, is one I've gone back and forth on over the past few years.

Just thought I'd drop in and say that C#'s deserialization library is amazing with the use of DataContract and DataMember. Always found JSON deserialization to be an extremely tedious task in Java and C# but these attributes make it so bloody easy.
You should give json.net a try. If you're using visual studio, you can add it via NuGet. It's even better than the built in serialization.
 

-COOLIO-

The Everyman
Hardly matters to be honest, unless you're doing stuff that's very CPU intensive, like things you might see in higher level undergraduate degrees. You probably wouldn't even encounter them.

I would prioritize an SSD and 8GB RAM over a beefy processor. SSD because it's SSD, and RAM because I hate it when Windows has to resort to virtual memory. I only have 4GB at work which doesn't feel enough for me.

thank you, sir.
 
I'm studying Unity right now. I'm messing around with how 2D overheat shooters work. I've got experience making 2D games on Flash and I'm trying to translate it into Unity. So far it's going fine. Some things I'm pondering, but it's more of software design.

1. How do people handle "globals"? Like, it's where I dump game state (top score) or some constants. I don't like the idea of making the HUD itself keep track of the score. I googled around and saw people just putting an invisible object on the scene then put the script there, but that feels pretty dirty. Is there not a cleaner way?

2. How do people handle bullets? Right now, I'll most likely put the script on the bullet prefab to make itself move indefinitely and remove itself after some time. Where would I want to keep track of bullets? I can keep track of bullets in the script attached to the player right now. Should I put it on the "global script" instead?

I usually make a class specifically for handling globals.

I think the preferred Unity way is to use the playerprefs file.

Or scriptable objects used solely as data containers.
 

Aim_Ed

Member
"(3 points) Prompt the user to enter coordinates of 4 points. Your program should then
a) print the midpoint of the line segment between the &#64257;rst two points.
b) print the intersection point of the line through the &#64257;rst two points and the line through the
last two points.
c) If the two lines do not cross, i.e., if they are parallel, your program should print word &#8220;true&#8221;,
and otherwise word &#8220;false&#8221;.
Recall, that you are not allowed to use if statement."

GAF, what do?

I'm a garbage-level programmer.
 
"(3 points) Prompt the user to enter coordinates of 4 points. Your program should then
a) print the midpoint of the line segment between the &#64257;rst two points.
b) print the intersection point of the line through the &#64257;rst two points and the line through the
last two points.
c) If the two lines do not cross, i.e., if they are parallel, your program should print word &#8220;true&#8221;,
and otherwise word &#8220;false&#8221;.
Recall, that you are not allowed to use if statement."

GAF, what do?

I'm a garbage-level programmer.

What have you tried? What language are you using? The language is going to have a big impact on how you do it without if statements...but it should be simple to just have the method that determines if they are parallel return a boolean. Then you just print the boolean. No need for an if statement.

What part of the problem are you having trouble with? It's really hard to help if you don't give more details.
 

Aim_Ed

Member
What have you tried? What language are you using? The language is going to have a big impact on how you do it without if statements...but it should be simple to just have the method that determines if they are parallel return a boolean. Then you just print the boolean. No need for an if statement.

What part of the problem are you having trouble with? It's really hard to help if you don't give more details.

Sorry, wrote it in a hurry.

I'm working in Java, I'll add more info in a couple hours.
 

Rapstah

Member
If the limitation is just that you can not use the if statement and all other statements are allowed, you should just write something without that restriction, get it working, and then figure out some way to replace all of the if statements with switch statements (the easiest way) and to some extent ": ?" statements if they're appropriate.

There are places where a switch statement is appropriate in a well-written program but the "? :" statement generally just makes simple code harder to read, so try to avoid getting used to that one.
 

Aim_Ed

Member
Alright, I shouldn't have even posted that. Got the issue fixed already.

I haven't programmed and 2-3 years and I just started again because of school, if I have more issues I'll be sure to consult you guys.
 
Are there any excel gurus in here? I'm trying to teach myself to build financial models and I'm having trouble. I've got one model someone wrote up for me except the only thing I can't figure out is how to zero out everything if they reach their credit limit. Basically the model is that if they reach their $10,000 credit limit then all debt is called in and so for remaining periods they are bankrupt. When I try to do an IF statement for the condition it gives me a circular reference error but I can't figure out how to fix it for the life of me. Below are pictures of the formulas and the circular reference. The if statement giving the circular reference is for Cell D2 but would be copied across naturally:
Code:
=IF(C15<10000,(C2+OFFSET($B$22,MATCH($B$19,$A$23:$A$33,0),0)),0)



v9NFZPk.png

aqiD2OI.png
 
Anyone here do Objective C? I've been doing more and more lately and since previously I was more of a C++ game programmer I'm wondering about a few convention things.

The one that I'm trying to understand right now, is it better to use self.someVariable or _someVariable for member variables of a class?

I've generally been declaring all my member variables as properties in my header files, and I'm not even sure if this is the best way of doing things. I also don't really ever use synthesize (I think I read this is largely optional since XCode 4.5?).

Also I'm not really sure what the point in having something like

@interface MyClassName()
{
}

In my .m file when I already have:

@interface MyClassName : MyParentClass
@end

in the header file.

And another thing I'm unclear on, do I need to declare things strong/weak, atomic/nonatomic if I'm using ARC? It seems like the compiler doesn't care as I've been kind of mix and matching with no real rhyme or reason.

Thanks!
 

Nelo Ice

Banned
So for C++ is Starting Out With C++ From Control Structures Through Objects, 7th Edition by Tony Gaddis a good book? It's technically the one I should get for the class I'm taking but my professor said it wasn't needed and alot of his stuff is not in the book at all. Apparently he posts everything we'd need on Blackboard. Was thinking about getting that C++ primer after reading the C++ thread in OT. Figure it might be better than the class book and just in general it seems nice to have.
 

Exuro

Member
What is considered a line in a text file? Originally I thought it was just each row but a window sizing can change that so I'm a little confused and ned clarification. The program will need to read in lines from a file and output the lines in a reverse order.
 

-COOLIO-

The Everyman
is two O(n) operations run back to back O(n)? I think it is because in my mind that's 2n steps, but im just making sure. I think if you ran an O(n) operation n times then it would be O(n^2). Right?
 

arit

Member
What is considered a line in a text file? Originally I thought it was just each row but a window sizing can change that so I'm a little confused and ned clarification. The program will need to read in lines from a file and output the lines in a reverse order.

Depending on the OS it could be '\r', '\n' or a combination of both.

EDIT: To be more precise and programming language agnostic, it could be a single LineFeed/CarriageReturn control symbol, or a combination.
 

Slavik81

Member
What is considered a line in a text file? Originally I thought it was just each row but a window sizing can change that so I'm a little confused and ned clarification. The program will need to read in lines from a file and output the lines in a reverse order.
There's two sorts of line breaks in an editor like Notepad: line wrapping done in the editor window, and newlines specified in the file itself.

The wrapping is not a part of the file. Hence why if you open a file and change the window size to cause wrapping, you don't see an asterisk indicating there are unsaved changes.

If you want to see the file with only the newlines that are actually in the file, you can disable line wrapping in your editor. Notepad has am option for that.


The end of each line in the file is marked by a formatting character. Like the space character, it has no symbol; it just controls how other symbols are spaced. Typically that symbol is represented by '\n' in code.

It's worth noting that Windows, OSX and Linux all use different binary values for marking the end of a line. They're not even all the same length.

Depending on the OS it could be '\r', '\n' or a combination of both.

EDIT: To be more precise and programming language agnostic, it could be a single LineFeed/CarriageReturn control symbol, or a combination.
If you open the file in text mode (rather than binary), it will be automatically converted to '\n' when you're reading, and from '\n' to whatever the platform uses to be when writing. Usually, code like his wouldn't need to think about anything beyond "Open text files as text files and use '\n'"
 
Alright, possibly a dumb question, but in struggling to think of a way to do this.

Basically, I have a small library of classes: 1 holds data and performs some basic functions related to that data, and another uses that class to do stuff. It's the driver.

I would ideally love to have some way of having the driver class report what it's doing to whatever application uses it, but everything feels kludgey. I could create a list of messages I return for every method, but that just seems super stupid.

Is there a better way to get feedback from the driver class?

In this case, the interface is a console app, so having status messages logged and displayed of what its doing would be super useful. But it's be nice to have it work well if the interface is a GUI as well.

Thoughts?
 
Alright, possibly a dumb question, but in struggling to think of a way to do this.

Basically, I have a small library of classes: 1 holds data and performs some basic functions related to that data, and another uses that class to do stuff. It's the driver.

I would ideally love to have some way of having the driver class report what it's doing to whatever application uses it, but everything feels kludgey. I could create a list of messages I return for every method, but that just seems super stupid.

Is there a better way to get feedback from the driver class?

In this case, the interface is a console app, so having status messages logged and displayed of what its doing would be super useful. But it's be nice to have it work well if the interface is a GUI as well.

Thoughts?
The easiest approach would be to use a logger that just logs to stdout. In case you want something more sophisticated, you could try writing a ProgressReporter class that realizes callback-like methods that you call after something interesting happens in your driver class. Something like this:
Code:
this.DoSomethingInteresting();
progressReporter.somethingInterestingHappened();
I'm reading Physically Based Rendering at the moment and the renderer that it's describing is using a similar method, as far as I can tell, to report progress to the command line interface. (in C++) If you just want to print something to stdout, I'd just use a logger.
 
The easiest approach would be to use a logger that just logs to stdout. In case you want something more sophisticated, you could try writing a ProgressReporter class that realizes callback-like methods that you call after something interesting happens in your driver class. Something like this:
Code:
this.DoSomethingInteresting();
progressReporter.somethingInterestingHappened();
I'm reading Physically Based Rendering at the moment and the renderer that it's describing is using a similar method, as far as I can tell, to report progress to the command line interface. (in C++) If you just want to print something to stdout, I'd just use a logger.
Ah bugger, thought I'd put it in my post. I'm using VB.Net. I don't know C++ from nothing. But the idea of a ProgressReporter class is interesting, I'll have to take a look at that.

As you speak of callbacks, is there anything remotely like Javascript-style callbacks in .Net?
 

usea

Member
Ah bugger, thought I'd put it in my post. I'm using VB.Net. I don't know C++ from nothing. But the idea of a ProgressReporter class is interesting, I'll have to take a look at that.

As you speak of callbacks, is there anything remotely like Javascript-style callbacks in .Net?
Yes, Func<> and Action<> are callbacks. I don't know the VB.NET syntax, but I'm sure it's easy to find. For example if you wanted to take a callback that was a function that took a string argument, you'd take an Action<string>. The difference between Func and Action is that Func<A,B,C> takes an A and B parameter, but returns a C. While Action<A,B,C> takes 3 parameters (A,B,C) and returns nothing.

In general the patterns for what you're trying to do are:
1) Return an object that contains the result and also an optional error. This could be a Tuple or a custom Result class.
2) Have the user pass a callback as an argument, that takes a message. Action<string> for example.
3) When constructing your driver, allow the user to pass in a logging object that will be used to log messages. Basically anything that conforms to some ILogger interface you publish. You can also provide a default implementation of ILogger that takes a callback.
 
Yes, Func<> and Action<> are callbacks. I don't know the VB.NET syntax, but I'm sure it's easy to find. For example if you wanted to take a callback that was a function that took a string argument, you'd take an Action<string>. The difference between Func and Action is that Func<A,B,C> takes an A and B parameter, but returns a C. While Action<A,B,C> takes 3 parameters (A,B,C) and returns nothing.

In general the patterns for what you're trying to do are:
1) Return an object that contains the result and also an optional error. This could be a Tuple or a custom Result class.
2) Have the user pass a callback as an argument, that takes a message. Action<string> for example.
3) When constructing your driver, allow the user to pass in a logging object that will be used to log messages. Basically anything that conforms to some ILogger interface you publish. You can also provide a default implementation of ILogger that takes a callback.
Nice! I had no idea similar functionality existed in .Net. The number of times I pined for an ability to do something like a callback, and it existed this whole time! C'est la vie.

I'll start digging into some research for it tomorrow then. Cheers for the info.

Man, whenever I read technical explanations, I feel a little overwhelmed. I guess it's a hazard of falling into this field by complete accident, haha.
 
Alright, possibly a dumb question, but in struggling to think of a way to do this.

Basically, I have a small library of classes: 1 holds data and performs some basic functions related to that data, and another uses that class to do stuff. It's the driver.

I would ideally love to have some way of having the driver class report what it's doing to whatever application uses it, but everything feels kludgey. I could create a list of messages I return for every method, but that just seems super stupid.

Is there a better way to get feedback from the driver class?

In this case, the interface is a console app, so having status messages logged and displayed of what its doing would be super useful. But it's be nice to have it work well if the interface is a GUI as well.

Thoughts?

not entirely sure what you want to do but depending on the language you could use a callback function in the calling app that the driver passes messages back through, or you could use something like a static logging class that any other class can pass messages to which get stored in a list or logfile.

or you could set a variable in the driver that indicates it's current status and read that from the main app. lots of things really, depending on exactly what you're trying to accomplish. do the messages need to be persistent or do you just want to print to the console, etc. ?

edit: i see we're on the way already, lovely.
 
I fucking hate Java. It's me not language but still fuck you Java. I can't wait until I'm done with programming. Props to anyone that can stick with it, it's just not for me.
 
I fucking hate Java. It's me not language but still fuck you Java. I can't wait until I'm done with programming. Props to anyone that can stick with it, it's just not for me.

Java is what they taught when I went to college and I absolutely hated it, too, and my programming experience up to that point in time was just C. Don't give up on programming, though. There are far, far more enjoyable languages to work with.
 

hateradio

The Most Dangerous Yes Man
Alright, possibly a dumb question, but in struggling to think of a way to do this.

Basically, I have a small library of classes: 1 holds data and performs some basic functions related to that data, and another uses that class to do stuff. It's the driver.

I would ideally love to have some way of having the driver class report what it's doing to whatever application uses it, but everything feels kludgey. I could create a list of messages I return for every method, but that just seems super stupid.

Is there a better way to get feedback from the driver class?

In this case, the interface is a console app, so having status messages logged and displayed of what its doing would be super useful. But it's be nice to have it work well if the interface is a GUI as well.

Thoughts?
https://en.wikipedia.org/wiki/Observer_pattern

Similarly, you can use a Monad. Look for the "The Writer monad." The example is written in JS.
 
Top Bottom