Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 13 Oct 2003
Offline Last Active Apr 23 2016 04:13 PM

#5086761 Reference to a Reference?

Posted by on 17 August 2013 - 07:38 AM

Is this possible without venturing into unmanned code land?



In general, the C# idiom is to make RefToRefCow a Func<RefCow>

var RefCow = Cow1;
var RefToRefCow = ()=>RefCow;
RefToRefCow().HowMuchWeight();  // 5

RefCow = Cow2;
RefToRefCow().HowMuchWeight(); // 10

#5078671 Programming the right way?

Posted by on 18 July 2013 - 04:59 AM

Can anyone point me in the right direction to coding the right way with less bugs and more reliability?


First things first, there's no "right" way - there are a bunch of ways that will get the job done well.


Beyond that, I would look at the code you have written, and figure out why there are bugs. Did you use certain patterns that made the code fragile? Did you name things poorly so they got misused? Did the functions have too many side effects? Did you not have a good process to prevent typos/merge errors/etc?


Books and even good programmers can only bring you so far. Eventually you have to internalize the knowledge so that you can get the feel of what things are troublesome and why; what things are usually good and why. Then you can better apply those things to the problems at hand.

#5073567 Basic Concepts of Programming

Posted by on 28 June 2013 - 05:56 AM

I concur with Khaiy. Even if you know the syntax (and you don't), watching videos does not teach you how to program - writing progressively more difficult programs does. I think that focusing on C++ is a mistake, and thinking that C# or Java are more difficult is a clear cut sign that you have no actual experience making programs.

Slow down. *Practice*. Show that you can take the knowledge you've gained and apply it to solving problems.

#5072251 Basic Concepts of Programming

Posted by on 23 June 2013 - 10:29 AM

As a dissenting view, I'd just like to say that how computer architecture works, or what high level languages compile down to is largely orthogonal to being able to use them effectively.


Knowing all of that stuff won't help the OP understand bad tutorials better, it just provides more terms they don't understand and relationships that aren't clear.

#5072014 How exactly are video games made?

Posted by on 22 June 2013 - 07:43 AM

Can I ask, though, why has nobody mentioned Direct X? To my knowledge, that's a very big one, unless I've missed something.


In general, Direct X (or OpenGL) is more low level than people need to accomplish their goals. It's there, you can use it, but for the majority of games (and all For Beginner's first games), SDL and SFML will do what you need with 80% less headache.

#5072013 Basic Concepts of Programming

Posted by on 22 June 2013 - 07:37 AM

Can anyone please relate to me and see why I'm struggling?


I can't really. I mean I never really encountered these problems, but let me see if I can explain my understanding.


1. Computers are "computation machines". Thus all of the things they do boil down to math. Do you know what a function is? Do you know how to generate functions to solve word problems? Do you know how to combine functions to achieve more complex results? That is all programming is, and all computers do when you boil it down.


2. All these things are tools you use to solve problems. Why would you return void? Because your problem doesn't require a result. Many things are like this. The tutorial can't say when you would use them because they don't know the problems you face.


Now on to the specifics:


"If I return 0 in another function, what would happen? Why would it cause an error?"


If you return 0 in another function, the caller would get 0 as a result. It would only be an error if you were really supposed to get 1 or 42 or whatever as a result. And even then your program would run, just incorrectly.


They say this differs from traditional programming methods but I have no idea what traditional methods were and how different they were.


Traditionally, programs were very function oriented. They said "do this, then do that, if x=y then this other thing". Object oriented programs are designed more like "make a dog and a cat. make the dog chase the cat". Instead of focusing on the operations/recipe to do something, it focuses on modeling the parts of the problem as objects.


I don't know the difference between my "code" and the "data".


Data is variables.

Code is operations performed on variables.


I know that it's more effective to use a single instead of a double when you're working with a smaller number, but why?


That's the thing, it isn't always true. singles are 4 bytes (in most languages) doubles are 8 bytes (in most languages). So if you don't need the range (larger min/max values) or precision (more decimal point accuracy) of a double then you can use 4 less bytes to store that variable. Since you have less bytes to work with, operations should be faster too.


Unfortunately, on some machines, working with 8 bytes at a time "fits" better with how the processor works, so is actually faster.


That said, the performance difference is negligible and saving 4 bytes here and there is also usually meaningless these days.

#5070659 How do I implement a new rendering engine?

Posted by on 17 June 2013 - 08:16 PM

Your modeling app is only rendering that model, and it's doing it in not real time. Rendering engines need to render a bunch of models at high frame rates, all while doing all of the other logic involved in games.

Frankly, the odds of your game making any profit are nil. Just use cryengine.

#5064823 Optimizing code statements into expressions?

Posted by on 25 May 2013 - 01:10 PM

There is no design flaw.


How naive...


You know enough to say that there will always be boxing/unboxing in non-trivial code but fail to realize that any non-trivial code will have design flaws or at the very least, sub-optimal design trade-offs.


Of all the possible performance improvements in C#, boxing is like 10th in modern codebases. Have you curtailed your allocations? Have you chosen the right collections/algorithms? Have you pre-allocated your collections? Have you looked into pre-JITing to your target platform? Have you looked to parallelize/memoize your common algorithms?


Have you actually compiled in release mode and benchmarked the differences?


Look OP: you may be right, but understand that we see literally hundreds of people coming in here complaining of performance issues or claiming they NEED to do these things that the best of the best universally see as frivolous. We're just playing the odds that you're not the sub-one percent that really do need to do these things...

#5059981 Alternatives to singletons for data manager?

Posted by on 07 May 2013 - 05:25 AM

2. If you are the only coder on the project, do not over-engineer for the sake of some higher principle / book / pattern / <insert random bullsh*t reason>. Refactor, so that you, as a coder, have to spend minimum (preferably zero) time on that class you wrote 18 months ago.


3. Prefer "Ugly" code [that works] to a "Beautiful" code that hides/obfuscates dependencies [and suddenly stops working].


There's a reason that good programmers advocate the use of 'best practices', it's because worse practices cause actual, real life problems. KISS, and YAGNI matter of course, but "just slap it together" cannot be universally employed to produce quality software. Refactoring is important, but cannot be your only route to good design.


There needs to be a balance, and doing some simple things like not using singletons in your design will make the code significantly better and save you time - regardless of how many developers are on the project.

#5046833 Is it bad to use an IDE when you're just starting out with programming in...

Posted by on 26 March 2013 - 05:47 AM

I feel it is garbage. An IDE in modern programming is nearly as influential as the language itself. Why spend so much time fighting your non-IDE? I find it hard to believe you learn better/faster with so much overhead.

#5036871 Programming languages characteristics and behaviors

Posted by on 26 February 2013 - 04:17 PM

Any language that has has the ability to execute an arbitrary string as code needs to have an interpreter, and those are the languages that use interpreters as the primary launch point.

You can always ship a compiler and linker with your software, and exec() can invoke the compiler and linker, and load the resulting executable into the current process image...


It's not pretty, but it's been done more than a few times, and I wouldn't really call it an "interpreter".

Quoting for emphasis. .NET has one as part of the standard install (though you need elevated privledges to use it of course). Wrapping that into a simple exec()call is dead simple.


The categorization between compiled and interpreted isn't nearly as useful as it was 15 years ago.

#5035991 Can I use reflection to do this?

Posted by on 23 February 2013 - 09:42 PM

Sure, but providing an indexer (or simple method) to make the textures look like an array would probably be clearer and faster.

#5035373 Javascript Closures vs. Prototyped Objects

Posted by on 22 February 2013 - 06:24 AM

Not exactly. The outer scope only lets you use things as constants if those things are actually constant. If the other scope's variables change, then the closure will see them change.

This is what I meant about closing over _variables_ rather than values or references.

#5034279 Javascript Closures vs. Prototyped Objects

Posted by on 19 February 2013 - 03:17 PM

In practical usage, though, it looks like you end up making a thing that has data members and functions that interact with those data members.


This is not exactly correct, at least not in most languages. The thing you make refers to the same variables as are being closed over; not just the same data or the same references. You're not actually making any new data members. Closures can be made to look like objects (and vice versa due to computational equivalence) but are different beasts. This is more important in a language like C# where concurrency can cause weird (and/or awesome) effects with closures. Javascript does not have that concern.

#5034149 C# Reference Types

Posted by on 19 February 2013 - 07:41 AM

They are a reference type, a reference to the (shared) value - not a reference to the variable.