The Big Programming Thread - Page 191
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
vrmr
21 Posts
| ||
tec27
United States3690 Posts
On November 12 2012 06:08 chrisolo wrote: I hope this belongs into this. I have a problem in PHP. I am reading out a directory and want to sort it. So I defined and array and try to sort it by sort(), but I cannot bring it to work. My PHP time is quite some time ago, so this might be obvious. Here is the relevant code-snippet: + Show Spoiler + $dir = array(); Can anyone help me please? Would be REALLY nice if you could just fix it (I guess it is just a matter of ten seconds or something), but if you do not want to fix it directly please tell me what I am doing wrong Use code tags next time That's a pretty bad way of writing PHP. Its a templating language, you should use it as one. Instead of echoing out HTML, you simply put the HTML outside of the PHP tags. IE: <?php This even works with control structures, like: <?php Anyway, the problem looks to be around this: $dir[] = $file; That should be $File, $file isn't initialized at that point. You may want to consider setting your PHP error logging settings to E_ALL so that it will warn you of things like that (*only* for development though, you shouldn't set that in production). | ||
MisterD
Germany1338 Posts
| ||
AcTiVillain
Australia81 Posts
| ||
Abductedonut
United States324 Posts
On November 11 2012 10:49 RayzorFlash wrote: Thanks. The clarifications I received after I admitted that I was stumped did imply that this is what they were looking for. They suggested to have a pre-allocated space, which could be a linked-list itself, from which the nodes would be removed as required, have data changed to what was needed, and then inserted to the actual linked list. However, I didn't quite understand how one would go about allocating that space or creating the "unused nodes" linked list without using new. I just couldn't wrap my head around any way to CREATE the heap itself without using new. How would I go about doing this? Also, constraints clarification: memory usage was not a constraint for the problem, but minimizing runtime was a primary concern This may be way beyond the score of the interview since they probably want more primitive things, but if you want to "CREATE" the heap - the "REAL" way to do that is by using calls to sbrk() and brk(). That's basically how malloc works in the background. The problem is that calls to brk() are expensive. So the way that most compilers/C handles that is that it uses an initial call to brk() which allocates a big chuck of memory. Then when you call malloc(), it doesn't call brk() (again, this would be expensive/timeconsuming) but it takes smaller slices of the initial brk() and gives it to you. You could use HeapAlloc() if you're on windows, but it's the same idea. You can also use mmap but I don't want to get into that. | ||
Craton
United States17217 Posts
On November 12 2012 09:23 AcTiVillain wrote: Proprietary software anyone? My employer requires me to learn proprietary software - (web dev skill set). I just wonder how many other devs also have to learn proprietary software as part of their jobs (and do any of the skills translate out of the job?) That's way too vague of a question. Just about every job uses some amount of proprietary or custom-made software. What translates depends on what you use and where you go / end up using next. | ||
AcTiVillain
Australia81 Posts
On November 12 2012 11:12 Craton wrote: That's way too vague of a question. Just about every job uses some amount of proprietary or custom-made software. What translates depends on what you use and where you go / end up using next. Thanks. I'm a recent grad, now working as a front end dev on contract. I'm thinking of going full time but wondering what sort of Salary can I expect as a graduate front end dev? | ||
phar
United States1080 Posts
On November 12 2012 11:12 Craton wrote: That's way too vague of a question. Just about every job uses some amount of proprietary or custom-made software. What translates depends on what you use and where you go / end up using next. Agree completely with this. Almost any job you have is going to require you to learn how to use internal tools and code which is kept secret from the outside. On November 12 2012 12:39 AcTiVillain wrote:Thanks. I'm a recent grad, now working as a front end dev on contract. I'm thinking of going full time but wondering what sort of Salary can I expect as a graduate front end dev? That depends entirely on what degree & work experience you have, and where and who your employer is. I know guys making anywhere between 40k on the low end to >120k on the high end straight-out-of-undergrad. But that's in the US. | ||
Craton
United States17217 Posts
| ||
ninjamyst
United States1903 Posts
For those of you in college now, the best way to impress is to be involved in side projects outside of school. Most schools don't even teach C# or PHP or Ruby; they only teach Java or C++. When we look at college resumes, everyone takes the same classes, do the same senior projects, and etc. We look for people that wrote their own mobile app, engaged in engineering competitions, did side projects for fun, learned a language outside of class, and etc. Most importantly, we look for people with strong communication skills. Too often, we get people obsessed with technical stuff only, and they lack social skills. In a team environment, you need to be able to express your ideas to your peers. In design sessions, you need to be able to clearly explain your logic and your reasoning. If we can't understand you, we can't hire you even if you can create the fastest algorithm. | ||
Nausea
Sweden807 Posts
I got an Entity class and a Projectile class which inherits the entity class. The Entity class has a Load function which takes a filename and loads what picture the entity should use. Now, Projectile needs to have its image loaded at the start of the program so every time i create a new projectile during run time it uses the same image and does not need to load a new image every time. I tried making the Load function inside of Projectile a static method but that did not work, so then i tried to rename it and that worked but then it complained that i try to use Entity::Load inside of it and complains that I need an object. I guess I have to solve this since it wont be very good to have a new image loaded for every single shot my character shoots. If anyone can help with this problem I would be very happy. | ||
Uberrated
Norway9 Posts
On November 13 2012 04:15 Nausea wrote: (c++) I got an Entity class and a Projectile class which inherits the entity class. The Entity class has a Load function which takes a filename and loads what picture the entity should use. Now, Projectile needs to have its image loaded at the start of the program so every time i create a new projectile during run time it uses the same image and does not need to load a new image every time. I tried making the Load function inside of Projectile a static method but that did not work, so then i tried to rename it and that worked but then it complained that i try to use Entity::Load inside of it and complains that I need an object. I guess I have to solve this since it wont be very good to have a new image loaded for every single shot my character shoots. If anyone can help with this problem I would be very happy. For games, you will need an assetmanager sooner, rather than later. So, create a class which contains a dictionary/map, which maps filename (string) as key, and the loaded image as value. Than your (pseudo)code looks something along the lines of:
| ||
Nausea
Sweden807 Posts
On November 13 2012 04:39 Uberrated wrote: For games, you will need an assetmanager sooner, rather than later. So, create a class which contains a dictionary/map, which maps filename (string) as key, and the loaded image as value. Than your (pseudo)code looks something along the lines of:
Well that´s great, but it does not really help with the problem at hand? Or if it does then feel free to clarify how. Someone told me I should use "Lazy Initialization" which I cant figure out how to do. | ||
Deleted User 101379
4849 Posts
On November 13 2012 05:36 Nausea wrote: Well that´s great, but it does not really help with the problem at hand? Or if it does then feel free to clarify how. Someone told me I should use "Lazy Initialization" which I cant figure out how to do. Lazy initialization is basically:
You check if the image is already loaded and if it is, you just return that image. If it isn't, you load the image, store it for future reference and then use that whenever you need the same image again. You can also pre-fill the dictionary at the start of the game and any time you call load, it will just use the pre-loaded images. | ||
fabiano
Brazil4644 Posts
| ||
Uberrated
Norway9 Posts
On November 13 2012 06:24 fabiano wrote: Yeah you really need to have an AssetManager class, and I believe you should implement it as a Singleton. At the start of every level make the AssetManager load all the images you will be using for that specific level and retrieve them whenever you need. Using a singleton is fine starting out, as it is really, really convenient, but if you start writing tests, they are best avoided. I think singletons are turning out to be somewhat of a antipattern. | ||
Nausea
Sweden807 Posts
Help! :/ NVM I solved it, I tried doing it->second, and instead I now did ImagesList.find(filename)->second that did the trick. Thank you all for your help | ||
Alryk
United States2718 Posts
I have a function (for example f = cos(x)) and I'm trying to print out when it's 0 from 0 - 2pi, but solve(f) will only return pi/2. It SHOULD return pi/2 and 3pi/2, so I'm not sure why I'm only getting one value. It works fine for a polynomial like x^2 + 2x. I assume it has something to do with the fact that it's a periodic function or whatever, but google/my brain have failed to find the answer. | ||
KaiserJohan
Sweden1808 Posts
On November 13 2012 08:37 Nausea wrote: Okay so I started writing this assetmanager singleton class, with a map storing a string and an image. The problem is that the image is stored as a pointer in the map and adding it to the map is going fine, however when i try to get the function to return the pointer the compiler does not complain but the program shuts down when the pointer is returned as NULL. Help! :/ NVM I solved it, I tried doing it->second, and instead I now did ImagesList.find(filename)->second that did the trick. Thank you all for your help Now I'm mainly speaking from a C++ perspective but: Drop the singleton design, instead build your system in such a way as to avoid globals as much as absolutely possible. It forces you to think and create healthy software design, because sooner or later the singleton and stuff like it will bite you. Your object should have a clear purpose and their scope and visibility as limited as possible and also avoid coupling between systems. | ||
meatpudding
Australia520 Posts
On November 14 2012 07:52 KaiserJohan wrote: Now I'm mainly speaking from a C++ perspective but: Drop the singleton design, instead build your system in such a way as to avoid globals as much as absolutely possible. It forces you to think and create healthy software design, because sooner or later the singleton and stuff like it will bite you. Your object should have a clear purpose and their scope and visibility as limited as possible and also avoid coupling between systems. I would like to ask how you suggest doing this? Imagine different Entity types need access to the AssetManager. With globals or singleton you can do something like this (Assume myImage is inherit from Entity and myImageResourceName identifies the unique resource)
How would you avoid AssetManager being global in this case? | ||
| ||