Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 09 Jun 2000
Offline Last Active Today, 03:21 AM

#5229952 Massive Python Example Script

Posted by ChaosEngine on 19 May 2015 - 08:32 PM

I think I still want them in the same file though.




You're making it harder to edit, harder to read, and on top of everything else, you're teaching bad habits. Think about it, if someone came to you with a decent size program all in one file/function, the first thing you'd say to them would be to break it up into manageable chunks.

#5225987 Steam's compensated modding policy

Posted by ChaosEngine on 27 April 2015 - 09:10 PM

Its 25% for the mod's author, 40% for Bethesda and 35% for Valve. From that 35% Valve gets, 5% can be distributed to "service providers" the mod's author think they helped to create the mod (think NifScope for models, SKSE for scripts, NexusMods for the community, etc).


According to Bethesda, Valve is taking their 30% standard cut. After that, the publisher decides the split of the remaining 70% (in this case, Bethesda chose a 45/25 split).


They've rolled it back anyway. It's a shame really, because I thought there was some merit in the idea. I liked that mod devs could either go fixed price, pay what you want, or free. 25% feels a bit low, but that's not Valves fault and 25% of something is still better than 100% of nothing. 

#5225163 Assess Project Interface Namespace Design

Posted by ChaosEngine on 23 April 2015 - 07:54 PM

I really don't like the idea of a "production" code implementing an IUnitTest interface. The code should have no knowledge of the testing framework.


NonCopyable is not an interface, it's a class (it has implemented members).


Also boost already provides an implementation for it, so no need to reinvent the wheel (also boost::noncopyable is one header, so no added dependencies).


I'm not sure of the utility of IMapKey either. You're forcing the operator< to be virtual for no real reason. Assuming you're using an implementing class in a template, if the template requires an operator<, it will fail to compile without one.


Also, a lot of people don't like the practice of naming interfaces ISomething.


Finally, why are UnitTest, NonCopyable and MapKey in the same file? 



#5219510 Global Consts

Posted by ChaosEngine on 26 March 2015 - 08:37 PM

Namespaces are your friend.

#5218877 c++ count lines in txt file and then read these lines without reopening a file

Posted by ChaosEngine on 24 March 2015 - 01:23 PM

Topic is about loading text files and everybody was asking why i dont want to use std::vector then i got -rep for that i was replying why not, and magically everyone now thinks i am trying to load 3d model text/binary file, which is not true.


Have you considered the possibility that you're wrong about using vector? Seriously, look at washus example. It does pretty much everything you want, at a cost of 1 allocation for the data and another couple for the size offsets (depending on the number of lines in your file, it might even be one).


It also has the benefit of cleaning up after itself; no arrays to delete, no FILEs to close.

#5218331 is this possible to access winform members with static function?

Posted by ChaosEngine on 22 March 2015 - 03:44 PM

SmkViper is correct.

However, if you are updating non-static member fields in a static method, you should be asking yourself why the method is static in the first place.


For a trivial example*:

public class Person
   private string _name;

   public static UpdateName(Person p, string name)
      p._name = name;

The UpdateName method isn't really static at all, you may as well just make it a non static method.


* yes, I know you wouldn't write a method or class like this.

#5216915 C# Interview test "failed"? Why?

Posted by ChaosEngine on 16 March 2015 - 02:29 PM

Is Linq an option?

var result = new [] { 10, 12, 31 }.Sum();
I come from C++ a few years back and quite prefer C#, but to each their own smile.png Just pointing out that there may be some options for things like these.


You're missing the forest for the trees. "Sum" is trivial, but let's say I have a more complicated algorithm that I would like to operate over different numeric types. Right now, I need to overload the algorithm for each type with nearly identical code. Wozs solution with expression trees is clever, but would be difficult to implement for a non-trivial algorithm and would add a non-negligible overhead in a tight loop.

#5215760 Best programming paradigm for noobs?

Posted by ChaosEngine on 10 March 2015 - 08:29 PM

Personally, I feel that it doesn't matter. If you start programming procedurally, you will write bad procedural code. If you start programming in an OO fashion, you will write bad OO code (and probably bad procedural code too :) ). Same with functional.


When you start programming, you will suck. Same as when you start anything. and the only way to get better is to practice. 


As for languages, some are easier than others, but eventually you will have to overcome the same hurdles anyway. Whether that's better done early on or later is a matter for debate.

#5211813 Curious about Save Protection Methods

Posted by ChaosEngine on 19 February 2015 - 09:34 PM

Generally the opinion round here is that you have two options:

  1. Store the save file on a server you control and make the game online only
  2. Don't bother (or at least, don't bother with anything more complex than a binary file format and a checksum)

Anything stored locally is subject to reverse engineering by a skilled cracker. If a binary file format or a really simple encryption puts it into the "not worth the effort" basket for 95% of your users, then that's good enough. 4.9% will then download an editor written by the 0.1% who saw your encryption as a challenge.


But honestly, I doubt I'd even worry about that. If a user wants to cheat and change their save somehow (adding items, health, etc) as long as it's a single player game, they're not really harming anyone.


If it's a multiplayer online game... then the save should be on the server.

#5210374 How to correctly inject and share an object to multiple other objects

Posted by ChaosEngine on 12 February 2015 - 05:02 PM

So B and C just need a reference (possibly const, depending on whether they will modify the A)

Aren't storing references a bad idea? http://stackoverflow.com/questions/892133/should-i-prefer-pointers-or-references-in-member-data . Again I'm only going by what I'm reading online.

Let's examine the objections in the accepted answer:

you are forced to initialise the reference in each constructor's initialiser list: there's no way to factor out this initialisation into another function (until C++0x, anyway)

First, the initialiser list is the correct place to initialise member variables. Second, it's 2015 and almost every major compiler has support for delegating constructors.
Besides, even if you can't use delegating constructors, it's not a massive maintenance burden to initialise your reference.

the reference cannot be rebound or be null. This can be an advantage, but if the code ever needs changing to allow rebinding or for the member to be null, all uses of the member need to change

If the object you are referring to cannot be null, then this is a good thing. If it can be null, then you shouldn't use a reference. In your case, your B class expects an A object to exist for the lifetime of the class.

unlike pointer members, references can't easily be replaced by smart pointers or iterators as refactoring might require

Again, you are expressing your intent through the language features. A reference implicitly tells you that the B class expects an A object to exist for the lifetime of the B object. If you change that intent, you should change the code to reflect that. Changing from a reference to a pointer will cause your code to fail to compile. That is A Good Thingtm. The compiler is now helping you see where your reference/pointer is used and forcing you to examine the usage of it in each context.
Horses for courses. 
If the injected object can be NULL: use a pointer.
If the injected object can be swapped out for a different object: use a pointer
If the injected object is not clearly owned by anyone: use a shared_ptr to create it and a weak_ptr to reference it.

if in the case like this where the injected object cannot be null and must exist for the lifetime of the client object: use a reference.


Note that it's perfectly legitimate to store a raw pointer here to represent the concept of "NO ownership."

I like this approach, even though raw pointers are usually not good. I think if someone was to read my code and saw it, it would clearly convey there is no Ownership of this b2World object. If I take this approach, it would mean that I don't need to delete my a object in the destructor of both B and C. It would need to be handled separately?  Something like this then:
A aObject;
B bObject(&aObject);
C cObject(&aObject);
Then A would be deleted when it goes out of scope along with B and C automatically.

Note that that approach will work equally well with references.

#5209878 Operator Overloading C++

Posted by ChaosEngine on 10 February 2015 - 03:56 PM

You could argue that there is use in defining it const to prevent you from changing the value in the function.


True. Whether that's useful or not depends on the function itself, but in general I'd agree it's good programming practice.


Plus putting const on everything you can is just a good habit to get into.


Agreed. In fact, I'd go further. In some ways, I think variables should be const by default and marked as mutable otherwise, but I understand the historical reasons why C++ couldn't do that.


(And not being able to do it in C# drives me up the wall sometimes...)

Amen brother. Lack of const objects/methods is one of my pet hates in c#.


Though if I'm doing that I usually leave the const off of the function header in the .h file, adding it to the .cpp file only since the caller doesn't really care one way or the other since it's by-value.


Never knew you could do that. Wouldn't it change the function signature and mess up the linker?

#5209672 Clean OOP programming question

Posted by ChaosEngine on 09 February 2015 - 03:04 PM

OP, aside from the code formatting issues, what you're looking for is an event listener system. You could create your own (ala alnites suggestion) or you could use a "signals and slots" library such as Boost.Signals .


The idea behind these is to decouple your event handler from the event source.

#5207509 Modifying a cell value in Excel through an external app

Posted by ChaosEngine on 29 January 2015 - 02:04 PM

Another option is LinqToExcel


Presents a nice interface for query excel sheets. Really easy to use.

#5207326 Some programmers actually hate OOP languages? WHAT?!

Posted by ChaosEngine on 28 January 2015 - 07:20 PM

In Java (and in C#) you see people creating new classes whose only purpose is to be a bucket for static methods. How silly is it that one has to pay penance to the type system to achieve such a simple request as a free-standing function?


Yeah, I do that all the time in C#. 


I do wish they would add support for free functions, but in practice* it's no different from adding a free function to a namespace in C++, and namespaces are a Good Thing IMO.


* as long as you don't do anything stupid like depend on static state, but again you can do the exact same thing with functions and global state in C++.

#5204330 what kind of questions should I expect in a web developer Interview

Posted by ChaosEngine on 14 January 2015 - 04:34 PM

Most interviews are broken into non-technical and technical sections (typically in that order).


The non-technical section is there to learn about you as a person; how you work, will you fit in with the team, attitude... that kinda thing: see cozzie, NiteLordz and especially frobs replies for that.


The technical section varies. Some companies will assume you're good enough from looking at your experience. Others will do anything from a few simple questions to giving you a machine and asking you to implement something. No matter what happens here: don't be afraid to ask questions. Show your thought process. If you're asked about specific technologies (js frameworks, etc), be honest if you're not familiar with them, but try to compare them to something similar you do know. 


If you're given a code sample.... read it several times before answering.