freddyscoming4you

Member
  • Content count

    82
  • Joined

  • Last visited

Community Reputation

112 Neutral

About freddyscoming4you

  • Rank
    Member
  1. When To And Not To Use Exceptions?

    Conceptually speaking I see exceptions as something that needs to halt execution of your application and NEEDS your application's attention if you're looking for specific exceptions to handle. Return codes on the other hand are simply ways to do small talk, so to speak, in your code. I find it to be generally useful to use state enums to let your code know where it is since exception throwing in most cases is a very slow event. So... [code] enum ProcessingStatus { Pass, InputIsIncorrectFormat } void DoProcess(string input) { switch(ProcessWork(input)) { case ProcessingStatus.Pass: // proceed, return, do nothing, call NextStep() or w/e break; case ProcessingStatus.InputIsIncorrectFormat: // either report back and ask for new input or try to auto correct and try again break; } } ProcessingStatus ProcessWork(string input) { /// validate code if fail return ProcessingStatus.InputIsIncorrectFormat else carry on and return ProcessingStatus.Pass on success // however on something critical like a memory you may want to throw MemoryLeakException("ProcessWork created a memory leak with the following state at the time of the leak") } [/code] To me that is pretty easy to read, understand and is generally friendly. Granted, that is coming from a C# background but it's generally very clean.
  2. C vs C++ features

    [quote name='VReality' timestamp='1315469061' post='4858950'] Anyway, the only mention of the video game industry (that I heard during the part of the discussion I sat through) was that it's one of the reasons that C++ is still so relevant. I don't think there's any reason to infer a trend in the industry of not living up to her expectations of C++ programers. And if anyone doesn't, I don't think it would be fair to say that it's because an antiquated style is preferred in the industry. [/quote] I wasn't trying to say that antiquated style is preferred or not. I was simply curious if some of the older features are "better" for highly performant systems like a game engine. Regardless, excellent commentary!
  3. C vs C++ features

    So it's like calculus... excellent. LOL
  4. C vs C++ features

    Listening to the dotnetwrocks pod cast here: [url="http://dotnetrocks.com/default.aspx?showNum=695"]http://dotnetrocks.c...spx?showNum=695[/url] Kate talks briefly how people are actually using C rather than C++ with things like using malloc rather than just newing an object or using smart pointers. Is using the older methods for these things preferred for game development or are people just being newbs and not realizing what tools they have at their disposal?
  5. [web] Javascript & PHP

    Javascript is inherently insecure. That said you can implement some schemes to mitigate its insecurities such as having your script make a call for a decryption key that expires very soon (like 5 seconds) or even is only good for one use but that could take some more algorithmic math than you may have. The only way to be able to "secure" your app is to use a browser plug in that incorporates encrypted communication like Java. I'm not sure about Flash but I would think they'd have something like that built in. No matter what though, you should NEVER take input received by the server from the client and pass it directly to your database. The best way to secure your database is to thoroughly scrub and verify the data you pass into your database. I would argue that this single task will take about as long to develop the game mechanics themselves. Best of luck to you.
  6. [.net] Trying to Implement Generic Method

    [quote name='kunos' timestamp='1315041473' post='4857070'] if you dont know about generics... why would you put that into your code? you can easily code it without. if you really want to learn about generics.. buy a C# book, study it.. implement some single examples and, when you feel confident enough with it you'll have your big chance to use it in your producion code. [/quote] I started coding that around 12:30 and I was trying to think of a generic way to use interfaces and generics to create a singular method that I could use to execute API calls since they all follow the same pattern and my mind shouted "GENERICS!" And, so it was, or wasn't. Haha. [quote name='Zipster' timestamp='1315042836' post='4857077'] [font="Arial"] I'm not sure I see the purpose of [/font][font="Arial"][font="Courier New"]ParseResponse[/font] as a factory-like instance method. If you already have an instance of the concrete type you want (i.e. [/font][font="Arial"][font="Courier New"]ServerStatusResponse[/font]), why would you create a clone? As it stands right now, your generic method creates a default-initialized instance of a particular response, and then promptly throws it away by having it return a new instance of that response. I also don't believe the generic method is necessary here since your code doesn't require concrete type information -- it can just use regular inheritence by having the user pass in their own response object: [/font][/quote] Thanks for the suggestion. I stripped out all the generics stuff and simply passed in a IApiResponse object and return it's parse method from that. Subsequently I removed the parsing code out of the constructor and put it in the parse method which returns void. A few hours of sleep and a thought out suggestion will do wonders.
  7. I have implemented an interface to be used by all certain types of a class which represents a response to a WebRequest. I have the interface implement a method whose return type is also the interface so I can get a return value to be the parsed response. The parsing of the response is handled in the interface implementation in each class, naturally. However, I'm having difficulty in implementing this as I don't have hardly any experience writing generic methods and I'm not having much help using Google. Below is my class implementation, or what I have managed to cobble together so far. Can you see what's off? Thanks. First, the interface declarations: [code] using System.Xml; namespace EVE_API.Interfaces { public interface IAPIResponse { IAPIResponse ParseResponse(XmlDocument response); } } [/code] [code] using System.Collections.Generic; using System.Xml; namespace EVE_API.Interfaces { public interface IEveAPI { string ApiName { get; } Dictionary<string,string> Arguments { get; set; } } } [/code] Now, the response class: [code] using System; using System.Xml; using EVE_API.Interfaces; namespace EVE_API.APIs.Miscelleneous { public class ServerStatusResponse : IAPIResponse { private string _version; private DateTime _currentTime; private bool _open; private int _onlinePlayers; private DateTime _cachedUntil; public string Version { get { return _version; } } public DateTime CurrentTime { get { return _currentTime; } } public bool Open { get { return _open; } } public int OnlinePlayers { get { return _onlinePlayers; } } public DateTime CachedUntil { get { return _cachedUntil; } } private ServerStatusResponse(XmlDocument responseDocument) { _version = responseDocument.SelectSingleNode("/eveapi").Attributes["version"].Value; DateTime dtTry = DateTime.MinValue; DateTime.TryParse(responseDocument.SelectSingleNode("/eveapi/currentTime").Value, out dtTry); if (dtTry != DateTime.MinValue) { _currentTime = dtTry; } else { throw new MalformedResponseException("Could not find currentTime in response from SeverStatus API."); } bool boolTry; bool.TryParse(responseDocument.SelectSingleNode("/eveapi/result/open").Value, out boolTry); _open = boolTry; int intTry; int.TryParse(responseDocument.SelectSingleNode("/eveapie/result/onlinePlayers").Value, out intTry); if (intTry > int.MinValue) { _onlinePlayers = intTry; } else { throw new MalformedResponseException("Could not find onlinePlayers in response from SeverStatus API."); } dtTry = DateTime.MinValue; DateTime.TryParse(responseDocument.SelectSingleNode("/eveapi/result/cachedUntil").Value, out dtTry); if (dtTry != DateTime.MinValue) { _cachedUntil = dtTry; } else { throw new MalformedResponseException("Could not find cachedUntil in response from SeverStatus API."); } } public IAPIResponse ParseResponse(XmlDocument response) { return new ServerStatusResponse(response); } } } [/code] And now the class trying to wrap all the above together [code] using System; using System.Collections.Generic; using System.IO; using System.Net; using System.Xml; using EVE_API.Interfaces; namespace EVE_API { public class APICaller<T> where T : IAPIResponse { public APICaller() { } public T ExecuteAPICall<T>(IEveAPI api) { List<string> urlParts = new List<string>(); urlParts.Add(api.ApiName); if (api.Arguments != null) { urlParts.Add("?"); var keys = api.Arguments.Keys; foreach (string key in keys) { urlParts.Add(key); urlParts.Add("="); urlParts.Add(api.Arguments[key]); urlParts.Add("&"); } urlParts.RemoveAt(urlParts.Count - 1); } string completeUrl = urlParts.ToString(); WebRequest request = WebRequest.Create(completeUrl); WebResponse response = request.GetResponse(); XmlDocument document = new XmlDocument(); document.Load(response.GetResponseStream()); IAPIResponse apiResponse = new (IAPIResponse)T(); return apiResponse.ParseResponse(document); } } } [/code]
  8. Unity Opinions on C# dynamic

    [quote name='Serapth' timestamp='1314899384' post='4856389'] Actually, this is exactly my point. Everything you just said is basically no longer true since 4.0. With the inclusion of dynamic, "dynamic" is now a type, but the actual type is determined at runtime. So you can now have a "var of type dynamic" where the type is determined at runtime by inference if possible, or it pukes if not possible. I have no fault with var, its handy and can make code more ( or less) readable, its when you throw dynamic into the mix you present an opportunity for truly typeless code and clueless coders. [/quote] I wasn't aware of the dynamic type. After the reading I've done I don't see why anyone would use it with a purely .NET application. From what I can see the dynamic type itself is for interop purposes only. While you can use it and abuse it I'm guessing if you're on a project where such horrible code can be used then I'd suggest you upgrade to a better place to work.
  9. Unity Opinions on C# dynamic

    The point of var is so you can focus on coding. C# isn't nearly as dynamic as you might think. Once the type is set from the instantiation line then that's the type and it can't be changed later on. You will actually get a compiler error. Also, the "right" way to instantiate a var is to either set it right away or do "default(type)". So if you have a var you want to use as an int you would say "var a = default(int);." To me that's very clear. You would be dumb to declare a var way up in your code and initialize it much later where there could be ambiguity issues. Furthermore, once you set a var Visual Studio will examine the type that you're setting the var to and after the instantiation line if you hover over the variable intellisense will report the correct type in the flyout box that appears.
  10. [.net] DllImport Marshaling Issue

    You should be able to use the same types from VB to C#. It sounds like one of those "if it aint broke don't fix it" situations. One of the reasons the VB code is the way it is may be because that array structures may be different and the DLL you're using parses the incoming and outgoing values in a custom way. I would just use the C# equivalent types that the VB code used.
  11. Unity Opinions on C# dynamic

    Using var is ingenious for LINQ. Whether you're using LINQ to SQL or LINQ to objects it removes a lot of guess work in which type you need to cast to/from. I've never had an issue either supporting or writing new code where var messed me up with LINQ. Granted, that's about the only places I've seen it used heavily but it's treated me pretty swell.
  12. Legalizing my Game

    I seriously got negged for that? Wow... someone needs to lighten up. *preps for another neg on this post. weeeee*
  13. [quote name='Lewis_1986' timestamp='1314782344' post='4855801'] @ApochPiQ, seriously the old addage "if you cannot say anything helpful, be silent!" springs to mind because mocking someone and then telling them what they want to do is trivial helps no-one [/quote] Who pissed in your cheerios? I thought the same thing when I read the OPs question. It sounds very much like an image with text boxes set on top of it.
  14. Legalizing my Game

    [quote name='TTT_Dutch' timestamp='1314762109' post='4855734'] [quote name='Tom Sloper' timestamp='1314761902' post='4855731'] [quote name='TTT_Dutch' timestamp='1314755728' post='4855709']if I can get them to sign a contract that says that the whole game belongs to me and they will recieve a royalty from the sales does that mean its not too late to go back? Because I do believe that they will sign that.[/quote] If they sign it, then you can forget I said it might be too late to expect them to sign it, because, well, because they signed it. [/quote] Alright cool. Now what is the best template contract you think I should use? [/quote] I prefer contracts that use verbiage similar to "I'm in your codes stealin' your rights."
  15. Pretty much. Your only other option besides using a 3rd party library is going the unsafe route and copying frame data directly to memory. Which, you could get some speed boosts using native pointers while getting to switch to and from the managed environment of .Net. It could work.