Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 248 249 [250] 251 252 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 841068 times)

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3735 on: January 24, 2013, 04:58:20 am »

Glad to know I'm not the only person who gets confused by pointers.


Aye, I tried learning C++ first and got completely confuckfused by pointers. Took up assembly some time later and there pointers are clear as day. But I'm pretty sure that I would get confused again if I were to go back to C++ now.
Logged

Killjoy

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3736 on: January 24, 2013, 05:02:34 am »

You haven't seen the horrors I have seen: http://www.cs.rit.edu/~ark/pj.shtml
This makes me die on the inside each time I see it. http://www.cs.rit.edu/~ark/pj/lib/edu/rit/smp/fractal/MandelbrotSetSmp2.shtml

That is just shitty coding. You will find it everywhere. It means someone is using the language in a stupid way.
Trust me, it is possible to create obfuscated code in any language. There is even competitions to do it in C++.
Logged
Merchants Quest me programming a trading game with roguelike elements.

olemars

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3737 on: January 24, 2013, 07:43:05 am »

Strange inheritances. I have a bad headache and feel I'm missing something blindingly obvious. Why does the below happen?

Code: [Select]
class A
{
public:
    virtual void func(); //virtual, implemented function
    virtual void func2(); //virtual, implemented function
    //other declarations, some pure virtuals
};

class B : public A
{
public:
    void func(); //reimplemented function
    void func2(); //reimplemented function
    //other declarations
};

class C : public B
{
public:
    void func2() { B::func2(); } //reimplement func2() here as well
    //other declarations
};

Code: [Select]

SomeOtherPlace::callFunc()
{
    B *whatever = new C;
    whatever->func();   //A::func() called, B::func() expected
    whatever->B::func(); //properly calls B::func() without issue

    whatever->func2(); //properly calls C::func2()
}

What I'm doing is refactoring some old code written by others, where there are lots of classes (here lumped together as C) inheriting from class A which is in a 3rd party lib, and I'm inserting class B to extract the rather large swathes of code those classes have in common. I reimplemented a function func() from A in B that does not exist in C. I create a C, pointer stored as B* elsewhere and func is called on the B*. I'd expect it to use the function from B's vtable, but it uses the base implementation in A instead.

This is with GCC. I'm pretty sure it would do what I expected in MSVC, which is my usual environment.

Now, if I reimplement func() in C that just forwards the call to B::func(), then it works. Illustrated in the example above as func2(). But means I'll have to add these mock reimplementations in all the C's which is one of the things I was trying to avoid in the first place.

A is abstract, C implements the pure virtuals. B didn't at first, but does now. Same behaviour in either case.

Gah.
« Last Edit: January 24, 2013, 07:49:38 am by olemars »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3738 on: January 24, 2013, 08:44:46 am »

Top of my head, the blindingly obvious you may have overlooked:

B::func2 needs a virtual or C::func2 won't be called (right?).
Are all the parameters and return values exactly the same? (otherwise it's a different function)
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3739 on: January 24, 2013, 09:34:32 am »

Hey guys. I don't want to interrupt, but what was with the hate on Java earlier? You program it, easy graphics, and it runs everywhere no problem, and everyone has java. If I'm making games I use java. Robotics/real programming I used c++ though.

There's a lot of reasons, but many of them have been covered already in this thread. So, I'll toss out a new-ish one:

and it runs everywhere no problem, and everyone has java.

Not even close. Until recently, installing Java on Linux/UNIX platforms was the practical equivalent of running a triathlon through a three-ring circus. Install JRE, install another package that deals with compatibility issues, configure it all, hope it works, and repeat should you ever want to install the JDK.

olemars

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3740 on: January 24, 2013, 09:41:46 am »

Top of my head, the blindingly obvious you may have overlooked:

B::func2 needs a virtual or C::func2 won't be called (right?).
Tried both, though the virtual keyword is implicit in reimplemented functions. And C::func2 does get called. The problem is with B::func.

Quote
Are all the parameters and return values exactly the same? (otherwise it's a different function)

Double and triple checked, to the point of copying the exact formatting of the declaration just to make sure.
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3741 on: January 24, 2013, 09:54:27 am »

I dislike Java, but I at least don't hate it like I do with C#.

Java I dislike because I was forced to use it for many years and I find it clumsy and inelegant. Did you see how I was complaining about C++ syntax? Java blows it out of the water in being silly.

C# I hate because the fact that it exists convinces people to program in it, and C# is a proprietary language that will never run properly on anything but Windows, at least if you're using any of the libraries that actually make it worth using.
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #3742 on: January 24, 2013, 01:02:05 pm »

Well the standard is open for others to implement, it's just the best implementation of it is propriety. This is a great shame since as a language it's one of my favourites. And since they control the best implementation, which inevitably the majority will use since it's the best, they control the standard.

I have my gripes naturally, but if in a situation where I know the product is windows only... I'd find it hard to not recommend C# when it is the best fit for the requirements.

Sure you may want to go cross platform in the future, and if that is highly likely or guaranteed then cross platform becomes a requirement and C# goes right out. But if it's not a known eventuality, I'm of the opinion that developers 'crystal balling' because something may be useful in the future is an inherently bad thing and does more damage to a codebase than anything else.

Also random programming advice: never implement functionality or write code that is not yet needed but you just think might be useful in the future. More often than not it isn't and you are just dirtying your codebase. It isn't worth it.
« Last Edit: January 24, 2013, 01:14:18 pm by MorleyDev »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3743 on: January 24, 2013, 02:44:16 pm »

C# I hate because the fact that it exists convinces people to program in it, and C# is a proprietary language that will never run properly on anything but Windows, at least if you're using any of the libraries that actually make it worth using.
This is the only reason I don't use C#, because the language itself is pretty damn good.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3744 on: January 24, 2013, 02:50:20 pm »

You are 100% correct, MD, and I have no desire to ever go cross platform with my code. Which is why I'll stay the hell away from C# and objective C, because they don't work/dont work well on the one platform I use.
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3745 on: January 24, 2013, 02:54:04 pm »

Well then you now have no reason not to use C#:
http://www.mono-project.com/Main_Page
Mono is a cross platform C# implementation.
Similarly, MonoGame is a cross platform implementation of XNA: http://monogame.codeplex.com/

So yeah; cross platform C#. Which, by the way, is why Microsoft is no longer supporting XNA. It's all switching to Mono/MonoGame.
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3746 on: January 24, 2013, 02:55:54 pm »

Good joke, alway. Good joke. Old joke, but good joke.
Logged

olemars

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3747 on: January 24, 2013, 03:31:10 pm »

Spoiler (click to show/hide)

A couple of clean rebuilds later and the problem disappeared by itself. Kinda wish I'd kept the malfunctioning build so I could have compared the disassembly. Faith in GCC also slightly diminished.

C# I hate because the fact that it exists convinces people to program in it, and C# is a proprietary language that will never run properly on anything but Windows, at least if you're using any of the libraries that actually make it worth using.

I have no strong opinions about C# since I haven't really looked at the language, but I have a moderate dislike for it since I've had to use a mumber of buggy, slow and stacktrace-vomiting business applications made with .NET. It's like it attracts mediocre programming. Perhaps it's actually too easy to cobble together something that works-ish, so that's what companies end up doing.
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #3748 on: January 24, 2013, 03:45:18 pm »

It's a common language for businesses to use, and a lot of businesses don't understand the value of spending time refactoring, streamlining and optimising to make and keep code easy to work with. And a lot of programmers don't understand that either, or are pressured into doing worse jobs by their bosses who just want things done now and to hell with quality so long as it can be described as "working".

Which is a pity. I'm glad where I'm doing my work placement isn't like that. Being cut off from "outside funding", with profits coming from the customers using the service and not outside investors, probably helps. Also probably helps that it is a relatively small company of about 60 employees, about 12 of whom are programmers, with a programmer as a co-founder and the development manager also being a programmer. All of whom put emphasis on being clean and efficient over "just getting it done". On the other hand I fear it may have spoiled me for post-university...
« Last Edit: January 24, 2013, 04:11:42 pm by MorleyDev »
Logged

olemars

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3749 on: January 24, 2013, 05:27:34 pm »

On the other hand I fear it may have spoiled me for post-university...

Meh, I can probably get you a job like that, as long as you're willing to join the dark side.
Logged
Pages: 1 ... 248 249 [250] 251 252 ... 796