Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 7 developers from Canada and 18 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


ChaosEngine

Member Since 09 Jun 2000
Offline Last Active Today, 04:17 PM

#5249792 lame question how to delete something from vector

Posted by ChaosEngine on 30 August 2015 - 06:08 PM

 

If only there were a website built entirely around answering simple programming questions and only if there were a place you could go to ask questions and have the entire Internet scoured for answers in a matter of milliseconds. smile.png

1) Google: how to delete from vector by index c++

2) Very first result: (stackoverflow.com) How to erase element from std::vector<> by index?

 

Granted this question should be in the Beginner forum, but that said often beginners don't even know what to search for.

 

 

Seriously? The OP was able to write a thread asking the question... surely he could have googled that?

I mean googling the thread title (minus the "lame question") gives you Seans stack overflow result.




#5238104 Python Immutable member variables?

Posted by ChaosEngine on 02 July 2015 - 08:19 PM

Yep, the closest thing to immutability in Python is a property member with a setter that does nothing.

 
Well, in version 3 you don't even need a setter

>>> class Test:
	def __init__(self, x):
		self.__x = x
	@property
	def X(self):
		return self.__x

>>> t = Test(2)
>>> t.X
2
>>> t.X = 4
Traceback (most recent call last):
  File "<pyshell#14>", line 1, in <module>
    t.X = 4
AttributeError: can't set attribute

Note that even access control doesn't really exist in Python; you can always introspect the object to determine all of its members. The double leading underscore just excludes it from default name resolution, but dumping the object dictionary shows it plain as day.

yep, and you can modify it too

>>> t.__dict__
{'_Test__x': 2}
>>> t._Test__x = 3
>>> t.X
3



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






PARTNERS