Or, you know, adhere to a standard.
To me the number of spaces in your tabs is a standard that is up for personal preference.
Or, you know, adhere to a standard.
Becoming a graphics head...... my next question is, are the concepts of matrix's, vectors, linear algebra, and quarternions covered under discrete math, something else, or are they part of their own discipline? I'm interested in going into game programming and possibly specializing in graphics engine programming among other things and heard these concepts were key, as well as a background in discrete math. If I'm aiming for this what else would I need? And is a graphics engine programmer a good field to specialize in if I wanted to go into game programming? Would the concepts required to become adept in the field be easily translatable to other programming disciplines if that job prospect ultimately doesn't follow through?
He means if you use spaces you should have a standard. It's insane to constantly change the number of spaces in the code your coworkers commit. If you use spaces, it's critical that everybody uses the same number, whatever that is.To me the number of spaces in your tabs is a standard that is up for personal preference.
He means if you use spaces you should have a standard. It's insane to constantly change the number of spaces in the code your coworkers commit. If you use spaces, it's critical that everybody uses the same number, whatever that is.
#include<stdio.h>
int main(int argc, char *argv[])
{
int areas[] = {10, 12, 13, 14, 20};
char name[] = "Zed";
char full_name[] = {
'Z', 'e', 'd',
' ', 'A', '.', ' ',
'S', 'h', 'a', 'w', '/0'
};
printf("name=\"%s\" and full_name=\"%s\"\n", name, full_name);
return 0;
}
Erm, so in Learn C the Hard Way, I'm a bit confused. What purpose does the '\0' serve in this? When I compiled and ran it with it in there I got "Zed A. Shaw", but with a bunch of miscellaneous characters included. When I removed the '\0' it came out just fine. Is this one of those UNIX vs Windows oddities?
Code:#include<stdio.h> int main(int argc, char *argv[]) { int areas[] = {10, 12, 13, 14, 20}; char name[] = "Zed"; char full_name[] = { 'Z', 'e', 'd', ' ', 'A', '.', ' ', 'S', 'h', 'a', 'w', '/0' }; printf("name=\"%s\" and full_name=\"%s\"\n", name, full_name); return 0; }
If you're using BigInteger or some other class you'd do myBigInt.multyply(otherBigInt). I don't know if there's a way to do that with normal Integers or why you'd want to.Hey Neogaf, is there a way to multiple two numbers without using the "*" symbol in JAVA?
Hey Neogaf, is there a way to multiple two numbers without using the "*" symbol in JAVA?
I need to learn JAVA well; I learned it before, but I need to strengthen my skills. Does anyone know of a good source for JAVA interview questions, writing some functions and OOP concepts? Sorry for asking, but I am tired of living at home and I want to start my life. If not, then I'll look for myself.
I recommend reading Coding Interviews and Programming Interviews Exposed. I've also read Cracking the Coding Interview, but prefer the other two.I need to learn JAVA well; I learned it before, but I need to strengthen my skills. Does anyone know of a good source for JAVA interview questions, writing some functions and OOP concepts? Sorry for asking, but I am tired of living at home and I want to start my life. If not, then I'll look for myself.
Hey Neogaf, is there a way to multiple two numbers without using the "*" symbol in JAVA?
I recommend reading Coding Interviews and Programming Interviews Exposed. I've also read Cracking the Coding Interview, but prefer the other two.
In other programming-related news for me, I quit my old job last month and am starting a new job in the games industry later this month. So excited!
I'm actually doing more generalized programming; there was a graphics position open but I know I'm not strong enough in that area to perform well.Congrats! How did you prepare? Or were you already working in a field that uses computer graphics?
Guys, please hold me? I'm going to cry.
These getters are changing object state. I don't know if I can handle this.
public class MotionRule
{
public Address Address { get { return this.Address; } }
private Address _address;
[...]
}
}
public class RecordSaver
{
public void Save<T>(T record)
{
Save(new []{ record });
}
public void Save<T>(ICollection<T> records)
{
//save records to disk
}
}
Lots of getters change object state, e.g. getters that cache. You'll have to be more specific for me to feel sorry for you.Guys, please hold me? I'm going to cry.
These getters are changing object state. I don't know if I can handle this.
Couple things: one thread per socket isn't necessarily the most optimal way of doing things, since it results in a bunch of blocking reads. You'd be better off single threading it and using epoll (or whatever the Windows equivalent is). Secondly, absent asynchronous IO (which databases do tend to take advantage of) you may not save as much as you think multithreading the writes.So is anyone in this community good with concurrency? I'm starting to rewrite a large module for our back end software and I think it could be really better optimized for modern processors by parallelizing it, but I am hesitant because of the complexity of concurrency (and, obviously, my deadline).
Basically it's going to read geopositional messages off of a socket (or sockets), parse the messages, write them to a database, and then I have to decide whether I want to do further analysis on them in the database or in the server application itself.
As it is right now it dedicates a thread to each socket to read the messages in, then places all of the messages in a single queue, which a single thread then uses to parse. The messages are very small, less than (82 character maximum per sentence, multi-sentence messages are possible but relatively rare).
Once they are parsed they are placed into a single queue for a single thread to write them to a database. They are persisted in memory and two separate threads perform additional analysis on them.
So it's already sort of a hairy mess, but it's largely producer/consumer relationships. There are several places where I think these relationships can be changed from single threads to multiple threads to improve performance on modern architectures.
The raw messages that are read off of the socket are parsed by a single thread. The current problem I have is that the class used to parse the messages was set up to use a single static member containing the message bits to do the parsing ops on, so I have been rewriting it so that it is actually thread safe. My plan is to use a thread pool to handle parsing tasks, so that multiple messages can be parsed simultaneously. My conflict is that I am not sure the parse task is complex enough that multiple threads are even necessary, but I would imagine I can just reduce the thread pool size if that's an issue, that way it can scale up in the future if necessary.
The next obvious bottleneck as far as I can tell is where it is written to the database. The database writes are done on a single thread that constantly blocks on I/O with each write transaction. I plan to create another thread pool here so that multiple threads are executing the writes to improve throughput, since it won't have issues with writes being blocked on I/O as frequently.
As for the actual geospatial analysis, I think I am going to move the entire thing into the database and use SQL Server 2008R2s built in geography functions for it. I'm assuming the algorithms they have for proximity detection and intersections are probably far better than anything I can write. I just worry about about the database contention it could cause.
Any tips or suggestions for the situation? I have bought and I am reading Java Concurrency in Practice by Brian Goetz as I have basically gathered he is the foremost expert on concurrency. Any pitfalls anyone has experience that I need to look out for?
Are you in Java or .NET? Either way it sounds like you have a pretty good handle on it. In .NET I don't use the older stuff like thread pools anymore, I prefer using the Task Parallel Library.
There are lots of ways to make classes thread safe. Some of them will perform better than others. Any time you can avoid keeping state at all, the better off you'll be. Is it possible you could do your parsing without saving any state at all between calls? Otherwise you'll probably end up with synchronization which is going to slow stuff down (though not necessarily by a lot). Sorry if you know all this already.
Also, it sounds like if you do everything right, then the database will be the bottleneck. Slowing that bottleneck by doing geospatial analysis in the database might not be the way to go. My coworker just finished a project using the geospatial stuff in sql server 2008 r2, but I don't know how much work he left up to sql server and how much he rolled on his own.
Programming interviews are pretty awful as a whole. They are really only good at eliminating false positives in the hiring process, but can create a lot of false negatives.
Whiteboarding is just not representative of the actual process of being a coder, and beyond some conceptual stuff, I am more interested in whether the person can find the right answer in a timely manner rather than caring that they have it memorized - particularly in the case of language or library features.
You're mostly right about the TPL. But it also provides a thread abstraction called Task which uses the thread pool via a scheduler. Instead of manually making threads and trying to tune it to whatever machine you're running on, you just make a bunch of Tasks and the scheduler multiplexes them to threads based on the performance at runtime. They're like tiny lightweight threads. Also they're just easier to use than a thread.
Not so much for the performance gain as for the ease of use.
Couple things: one thread per socket isn't necessarily the most optimal way of doing things, since it results in a bunch of blocking reads. You'd be better off single threading it and using epoll (or whatever the Windows equivalent is). Secondly, absent asynchronous IO (which databases do tend to take advantage of) you may not save as much as you think multithreading the writes.
Exactly--you end up wasting a lot of unnecessary time switching between threads. At a hardware level, information coming through the network generally comes in one message at a time, so it can't really be multithreaded there. Keep in mind that if you're using TCP, receiving a message also involves writing information back to the sender, which is again a blocking operation. As a result, when you do blocking reads in multiple threads reading from multiple sockets, you have a situation where the actual expensive operation (calling out to the kernel to read from the socket) includes several steps that can only happen when nobody else is reading (this can vary based on kernel implementation). That's why single-threaded servers like nginx can usually handle far more simultaneous connections than thread-per-socket ones like Apache; most of the threads are sleeping at any one time. Additionally, since the polling blocking reads do to find out if your socket is used can be OThat actually sounds a lot like ThreadPoolExecutor in java. You create it with a core pool of threads, and a max number of threads, and a queue to hold tasks (basically just a queue of overridden Runnables) and it will dynamically allocate threads to run them based on need and the policy which you set.
As far as the socket goes, it gets something around 50,000 messages per minute, per socket. It's basically constantly reading.
Exactly--you end up wasting a lot of unnecessary time switching between threads. At a hardware level, information coming through the network generally comes in one message at a time, so it can't really be multithreaded there. Keep in mind that if you're using TCP, receiving a message also involves writing information back to the sender, which is again a blocking operation. As a result, when you do blocking reads in multiple threads reading from multiple sockets, you have a situation where the actual expensive operation (calling out to the kernel to read from the socket) includes several steps that can only happen when nobody else is reading (this can vary based on kernel implementation). That's why single-threaded servers like nginx can usually handle far more simultaneous connections than thread-per-socket ones like Apache; most of the threads are sleeping at any one time. Additionally, since the polling blocking reads do to find out if your socket is used can be Oin the number of open sockets, it's more efficient to do it as one call (e.g. to epoll).
(The above is all true of Linux. Windows may work differently but I think it's likely similar).
Long story short is, concurrent programming can be tricky when you're interacting with inherently single-threaded systems.
Surround your code with "code" tags so it shows up correctly. There's a button in the UI for it now.So when I need to add something to a Listbox how do I continue have it being inserted? Say that everytime I click a button I want it to add "Hello" in the Listbox. And everytime I click on the button more and more "hello"s show up. How do I do that? Because with what I currently am doing the "Hello" shows up once and that's it, nothing else gets added.
Here's what I have:
Code:Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Do Until ListBox1.Items.Count = 1 ListBox1.Items.Add("Hello") Loop End Sub End Class
Felt the same way about programming exams (IS, not CS major in school, so I only took one programming class, but still). They don't represent the situation in which you actually code.Programming interviews are pretty awful as a whole. They are really only good at eliminating false positives in the hiring process, but can create a lot of false negatives.
Whiteboarding is just not representative of the actual process of being a coder, and beyond some conceptual stuff, I am more interested in whether the person can find the right answer in a timely manner rather than caring that they have it memorized - particularly in the case of language or library features.
I considered myself a somewhat intelligent person. Not genius, but capable. When I said Coursera was offering a class on linear algebra using Python (Coding the Matrix: Linear Algebra through Computer Science Applications), I thought sure, I did well in math during high school (well, until Calculus) and I know some Python.
This is me watching the first lecture video:![]()
Hi all I've done some work with Java (writing code for some selenium automation) and currently work with PhP daily (modifying existing code) I'm looking to learn C++ just for personal enjoyment because I liked my time spent coding the little bit of Java I did code. This would also give me more options for future jobs which is always good i suppose.
Now that thats all out of the way my question is. Is this book still relevant?
Programming: Principles and Practice Using C++ by Bjarne Stroustrup
I ask because it was published in 2008 and I wouldn't want to study outdated material. I think its cool that I could read a book written by the C++ man himself. Any other recommendations for a beginner are greatly appreciated.
Sorry to interrupt the spaces vs. tabs war but...
I am only taking one class next summer session and really want to become more skilled in C++. I was thinking of taking an old open source project or game like Aleph One and spend five weeks understanding advanced coding practices and large project structure.
Is this a good idea or is there a better way to learn what I'm thinking about (i.e. advance C++ skills, large structure program)?
Anybody? I've read some stuff in the op but I just want to make sure I'm not wasting my time.
That sounds like a good idea to me. Add features to it. Start small and slowly get bigger.Sorry to interrupt the spaces vs. tabs war but...
I am only taking one class next summer session and really want to become more skilled in C++. I was thinking of taking an old open source project or game like Aleph One and spend five weeks understanding advanced coding practices and large project structure.
Is this a good idea or is there a better way to learn what I'm thinking about (i.e. advance C++ skills, large structure program)?
I considered myself a somewhat intelligent person. Not genius, but capable. When I said Coursera was offering a class on linear algebra using Python (Coding the Matrix: Linear Algebra through Computer Science Applications), I thought sure, I did well in math during high school (well, until Calculus) and I know some Python.
This is me watching the first lecture video:![]()
template<class T>
class Interface
{
bool operator==(const T &rhs) = 0;
}
class Entity : Interface<Entity>
{
Entity(int i);
bool operator==(const Entity &rhs);
}
int main()
{
Entity e(23);
Container<Entity> ctr;
int number = 23;
ctr.add(e); // fine, because e is a subclass of Interface
ctr.add(number); // not fine, because number is not a subclass of Interface
}
template<Interface T> // this doesn't work
class Container
{
void add(const T &item);
}
template<template<class> Interface T>
class Container
{
void add(const T &item);
}
Rather than explicitly restricting to subclasses of Interface<T>, have you tried doing it like this?Given a templated C++ class such as
Code:template<class T> class Interface { bool operator==(const T &rhs) = 0; }
I am going to use Interface to enforce a set of operator functions that must be implemented by a subclass of Interface, using:
Code:class Entity : Interface<Entity> { Entity(int i); bool operator==(const Entity &rhs); }
The problem I'm having is that I want to then create a templated Container class with the restriction that Container can only use classes derived from Interface as part of its template, i.e. I want to be able to write the following code
Code:int main() { Entity e(23); Container<Entity> ctr; int number = 23; ctr.add(e); // fine, because e is a subclass of Interface ctr.add(number); // not fine, because number is not a subclass of Interface }
In other words, I want Container to look something like
Code:template<Interface T> // this doesn't work class Container { void add(const T &item); }
But I don't know how to correctly have the argument of a template... be a template, without instantiating its argument. Is this possible?
EDIT:
Code:template<template<class> Interface T> class Container { void add(const T &item); }
Doesn't seem to work. Is there a better way of doing this?
template<class T>
class Container
{
void add(const Interface<T> &item);
}
Rather than explicitly restricting to subclasses of Interface<T>, have you tried doing it like this?
Code:template<class T> class Container { void add(const Interface<T> &item); }
Ah, that's a good solution, thanks, just implemented it. Is there any way of ensuring that inserted objects are of type T in the add function itself? I say this because you could, for instance, create a class Evil : Interface<Good> and add it into a Container<Good>, even though it's not of type Good. There is also the problem of casting to items of type T inside the Container, which could be potentially expensive.
This....doesn't make sense. If Evil : Interface<Good>, then it will be specialized to use type Good. Interface is an abstract class, so the only way you will be able to get any objects that you can put in Container<Good> is to create non-abstract subclasses, like Evil.
Also, just as general advice, if you find yourself doing typecasting of one of the templated types in a template class, you may want to stop to consider whether what you are doing is a good design, because in most cases it probably is not.
Are you sure you need to use templates and an interface class to do what you want to do here? You can make an object with an equality operator without requiring a template. You can also store such objects in a templated container that uses the equality operator.
If you are worried about someone trying to store an object without an equality operator in the container, that will generate a compile-time error.
void drawTexturedShape(int img) {
glColor3f(0.8, 0.8, 0.8);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textures[img]);
glBegin(GL_QUADS);
...
glEnd();
glDisable(GL_TEXTURE_2D);
}
void draw2DShape() {
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_POLYGON);
glVertex2f(-20, -20);
glVertex2f(-20, 20);
glVertex2f(20, 20);
glVertex2f(20, -20);
glEnd();
glFlush();
}
void RenderTheScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
// Draw a 2D shape
draw2DShape();
// Draw a 3D shape
glPushMatrix();
glTranslatef(-7.0, -18.0, 0.0);
glScalef(5.4, 0.8, 3.0);
drawTexturedShape(IMAGE8);
glPopMatrix();
}