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!


ChaosEngine

Member Since 09 Jun 2000
Offline Last Active Today, 03:27 PM

#5236491 what really get and set do?

Posted by ChaosEngine on 23 June 2015 - 10:14 PM


Get/Set is just a quick 'macro'. It basically points to a data type in a class/struct.

 

I'd be wary of using the terms "macro" and "points to". I understand what you're trying to say, but those terms have a very specific meaning and properties are neither macros nor pointers.




#5236476 what really get and set do?

Posted by ChaosEngine on 23 June 2015 - 06:56 PM

Fields are really not properties.

 

They look similar, but under the hood a field is a piece of data and a property is really a collection of functions.

public class Thing
{
    public int x;
}

really is exactly what it says on the tin, but

public class Thing
{
    public int X {get;set;}
}

is more like 

public class Thing
{
    private int _x;
    public int get_X() { return _x; }
    public void set_X(int value) { _x = value; }
}

in fact, if you fire up Reflector*, that's exactly what you'll see.

.property instance int X
{
    .get instance int MyNamespace.Thing::get_X()
    .set instance void MyNamespace.Thing::set_X(int)
}

*you do have reflector, right? I mean, you'd be insane to do .net development without it.




#5236436 Do you comment Above or Below your code?

Posted by ChaosEngine on 23 June 2015 - 03:17 PM

 

 One case where I used below is to clarify what a part of a statement "means." Comment below sorta serves as my post-script. 

area=width * height
print("The area of the triangle is %.2f" %area)
#.2f sets a float with two decimal places

I'd still put that beside the line, even if I had to break up the line.

print("The area of the triangle is %.2f" # .2f print to 2 decimal places
   % area)



#5236096 Do you comment Above or Below your code?

Posted by ChaosEngine on 21 June 2015 - 09:40 PM

I'd love for IDEs to allow me to embed images into the comments of code. Just typing a filepath like IMG="./localFile.png"  would be awesome, if the IDE actually displayed the image within the code. Occasionally I want to embed a graph or table to demonstrate what a comment is describing.

you mean like this?




#5234992 Engineering vs Programming?

Posted by ChaosEngine on 15 June 2015 - 08:14 PM

 

As for arranged marriages and kids, that's up to you, but this is 2015... if you don't want to get married or have kids, tell your family to get stuffed.

 

There's benefits to clan-like cultures and even arranged marriages. This may be harder to understand if we're coming from a typical american family structure, or in the Disney culture of choosing a mate based on emotions that wax and wane. Arranged marriages can also end up being bad, but we shouldn't assume that that's always the case. Plus, we already have evidence that Ovi's parents aren't forcing him do what they want in terms of occupation, only giving their 'recommendation' and 'suggestion' (in Ovi's wording), not a hard command for what career to take.

 

While, yes, Ovi definitely does have free will to make his own decisions, we shouldn't bash his culture or advise him to give his culture and family the finger just because we're unfamiliar with it. Not everything "modern" is necessarily better - we shouldn't use unfounded claims of enlightenment (which I'm inferring from the "this is 2015" statement) as excuses to act impulsively.

 

Giving cross-cultural advice is risky business. smile.png

 

 

See bolded parts. I'm not saying he shouldn't have an arranged marriage or have kids, simply that he doesn't have to. 

I'm not bashing his culture either; if one is happy to have an arranged marriage and it works out, great.

 

But no-one in any culture should be forced into a lifelong partnership against their will. That is literally in the UN declaration on human rights.




#5234146 Which path is good for learning C# today ?

Posted by ChaosEngine on 10 June 2015 - 03:49 PM

Before I answer your questions, I have a few for you:

 

  • What is your goal?

Learn C#, yes, but to what end? What do you want to do with it? Game programming? Business apps?

 

  • How much programming experience do you have?

You said you did C++ 12 years ago, but you didn't say how much or if you've done anything since. If you're a reasonably competent programmer, (i.e. you've done at least one decent sized project), 2 years at 10 hours a day is complete overkill to learn C#. You should really be able to pick up most of the basics in under a month, especially if you're familiar with C++ or java.

 

So to answer your questions:

  1. Winforms is still very popular and it can be useful for putting together quick UIs. If you know any Win32, it's very easy to use, but unless you plan to make Windows specific UIs, you don't need to know it. 
  2. If you plan to do any business related work in C#, you need to know how to query and update a database. The latest mechanism is the Entity Framework, so you should definitely learn that.
  3. WPF is a dead horse IMO. Microsoft have all but abandoned it. I would definitely choose HTML5 over it for a LOB app. 
  4. ASP.net is an ok solution. IMHO, it's not great for frontend, so I would go the angular/ember/react route instead, but it's very nice for developing RESTful web APIs.

Technology (particularly business UIs) change all the time. C# is still a valid option, but at some point (maybe 5 years, maybe 20) you will have to abandon it and move on to something else. Never be afraid to learn something new.




#5230929 1 (interface) header with 2 cpp (implementation) files?

Posted by ChaosEngine on 25 May 2015 - 04:45 PM

Technically, there's nothing stopping you from spreading the implementation of a class across as many files as you like.

 

However, if you're splittng a class into two files because it does two distinct things, then you're clearly violating the single responsibility principle. 

 

You already know this is a code smell, and you know that separation of concerns is the Right Thing To Do, but you're looking for an excuse to be lazy.

 

Search your feelings, you know it to be true :D




#5230925 Reusing VS (2010) project?

Posted by ChaosEngine on 25 May 2015 - 04:40 PM

What are you trying to achieve? 

 

There are basically two ways to reuse code:  binary and source

 

If you're going down the binary route, setup up your original project to create a lib or a dll and export the relevant header files to an "include" dir. Do a versioned build, and use that lib/headers until you need to make an update to the original project. This works best if the original project is stable and updated infrequently. 

 

If you're using source, then you can checkout the code from source control (you are using source control, right?) into whatever directory you want. 




#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.

 

Why? 

 

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.






PARTNERS