Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 345 346 [347] 348 349 ... 796

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

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5190 on: November 10, 2013, 03:32:24 am »

Huh, that's interesting to know. I have a feeling this didn't work when I tried before, but I'll try it one more time... after this one other largish bug that I'm trying to fix. >_<

edit: welp, apparently sometime somewhere along my coding today and yesterday, I broke something and I can't fix it. I feel pretty despairing now.
« Last Edit: November 10, 2013, 03:44:33 am by Skyrunner »
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5191 on: November 10, 2013, 07:18:59 pm »

As an aside, this is pretty cool: Koding.

Okay, that is pretty cool. It's not entirely reliable yet, though - the first time loading up my machine was pretty quick. The second time, it took ages.

Enjoy your 250MB.
Logged

olemars

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5192 on: November 11, 2013, 09:20:27 am »

Agree on the pretty cool. Tried to use the referral but seems like it failed, so you get 250MB in spirit.

Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5193 on: November 12, 2013, 07:38:34 am »

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))

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5194 on: November 12, 2013, 07:56:43 am »

To take advantage of polymorphism in vectors, I need to make them vector<MyClass*>. The problem is if I iterate over them with an iterator, I can only dereference them like thus: (*it)->myFunction(). But if I'm adding or subtracting to the iterators, it becomes (*(it-1))->myFunction(). How do I not do this? Q_Q It makes my code look so dirty and cluttered...
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5195 on: November 12, 2013, 08:08:32 am »

To take advantage of polymorphism in vectors, I need to make them vector<MyClass*>. The problem is if I iterate over them with an iterator, I can only dereference them like thus: (*it)->myFunction(). But if I'm adding or subtracting to the iterators, it becomes (*(it-1))->myFunction(). How do I not do this? Q_Q It makes my code look so dirty and cluttered...
It's not that bad, is it?
You could do it in stages I suppose. That's probably even preferred. Lest you want things like:
Code: [Select]
char *(*(*a[N])())()For a java programmer who recently started doing C/C++ code, reading that is like staring into the soul of an eldritch abomination.
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

Maklak

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5196 on: November 12, 2013, 08:32:06 am »

> (*(it-1))->myFunction()
I don't really see a problem here. Did you mean
(*(--it))->myFunction();
Or maybe
class::iterator tmp = it-1;
*tmp->myFunction();

> char *(*(*a[N])())()
I've seen worse. Just start from the middle and expand.
a[N] : a is an array of size N...
(* a[N])()  : of pointers to functions...
(*(*a[N])())()  : returning pointers to functions...
char *(*(*a[N])())() : returning char *
I guess it would be better broken up into an array of functions returning char * with a just keeping functions returning indexes to select functions from that second array for simplicity, but hey, whatever works is fair game.

Java, on the other hand, sucks big time for me. What does public static void main even mean? Why does it have to be inside a class? How come main can't return an int to use return value in shell script? Why does everything have to be inside a class? Why can't I just free() or delete pointers myself? It's bad enough that I don't get a realloc() and alocal() in C++. Why do I always need a reference to an class created with new and can't just declare it on the stack? How do I even do anything without learning half the standard library... and the list goes on. To each their own, I guess.
Logged
Quote from: Omnicega
Since you seem to criticize most things harsher than concentrated acid, I'll take that as a compliment.
On mining Organics
Military guide for FoE mod.
Research: Crossbow with axe and shield.
Dropbox referral

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #5197 on: November 12, 2013, 08:32:51 am »

A general rule is if combining statements looks ugly, split the statements. Type deduction via the auto keyword is pretty nice for this.

So you could split it like in these ways:
Code: [Select]
auto prev = it-1;
(*prev)->myFunction();

Code: [Select]
auto prev = *(it-1);
prev->myFunction();

Code: [Select]
auto& prev = **(it-1);
prev.myFunction();

So long as you're using the latest version of g++ or MSVC10 (2010) or higher this should work. Although g++ may need the -std=c++11 flag.
« Last Edit: November 12, 2013, 08:39:36 am by MorleyDev »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5198 on: November 12, 2013, 08:45:18 am »

I decided to screw pretty OOP and go with the traditional, new-to-programming way (if (isAquifer) do STUFF, else do OTHER STUFF ). Of course I run into a problem where Mercurial won't let me discard the changes to the working directory. :/
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #5199 on: November 12, 2013, 10:36:14 am »

All languages have the potential for nesting nightmares. For example, many of Java's come from the standard libraries. It has to be said, whoever designed the Swing library needs to be beaten over the head with a book on Fluent Design and a pamphlet explaining the Law of Demeter...because that library fails at both.

C++ can enter dereferencing hell if you aren't careful. But like I said, if you break it down into separate declarations it's usually fairly readable. typedef and auto are your friends.

Heck, the lack of type deduction often means code is littered with useful information you don't need to process, wasting "brain-cycles", which is a major problem of older languages like pre-C++11 code and Java and a lesson pretty much all modern languages have learnt.

You could just give me Java but with support for the "var" keyword from C# and I'd immediately call it a vastly improved language. It's more or less what won me over to the "Scala is amazing!" crowd. Well, that and the functional programming...support for constants and encouraging the usage of them, a good futures library, closure support, linq-style chaining of operations on a collection...okay, there's a lot of reasons.

As an aside, and because I'm ranting to put off university documentation work, can visual studio and g++ hurry up with the C++14 support? I want me auto parameter in lambdas...imagine the possibilities, especially when combined with Linq for C++:
Code: [Select]
using namespace cpplinq;

from(std::initializer_list<int>({1,2,3,12,56,124,1,8})
   >> where([](auto x) { return x > 14; }
   >> select([](auto x) { return x + 90; })
   >> for_each([](auto x) { std::cout << x << std::endl; });
« Last Edit: November 12, 2013, 11:20:59 am by MorleyDev »
Logged

ECrownofFire

  • Bay Watcher
  • Resident Dragoness
    • View Profile
    • ECrownofFire
Re: if self.isCoder(): post() #Programming Thread
« Reply #5200 on: November 12, 2013, 11:20:48 am »

I decided to screw pretty OOP and go with the traditional, new-to-programming way (if (isAquifer) do STUFF, else do OTHER STUFF ). Of course I run into a problem where Mercurial won't let me discard the changes to the working directory. :/

For all your inheritance needs, I'd like to introduce you to the magic of dynamic_cast.

Just call dynamic_cast<DerivedBar*>(basePointer) and if basePointer is pointing to a DerivedBar then it returns a DerivedBar*, otherwise it returns nullptr. So you can chain if-elseif with those which is a lot cleaner and doesn't require any kind of outside functionality.
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5201 on: November 12, 2013, 03:27:18 pm »


Laugh or cry?

Both.  This does at least make me feel a little better.  For all the bad practices we have at work, we don't have anything nearly this horrible in our code.  Almost all of the PHP we write is working with databases, and we always use bound parameters in prepared statements and other parameter sanitation.  What little we have that uses exec never accepts user input directly in any fashion.
Logged
Through pain, I find wisdom.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5202 on: November 12, 2013, 06:40:11 pm »


Laugh or cry?

Both.  This does at least make me feel a little better.  For all the bad practices we have at work, we don't have anything nearly this horrible in our code.  Almost all of the PHP we write is working with databases, and we always use bound parameters in prepared statements and other parameter sanitation.  What little we have that uses exec never accepts user input directly in any fashion.
My reaction was about the same. My faith in myself as a developer has risen so much that I decided that I'd even release the next component that I built as open source.
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))

quinnr

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5203 on: November 12, 2013, 07:01:42 pm »

So, thanks for the advice when I asked a few days ago on where to start learning web programming. There was a 24-hour Hackathon I went to, and actually ended with a working app and a bunch of free swag, and a ton of learning. That said, the app was absolutely terrible coding-wise and cut so many corners, so I'm working on my own project now that I know I can actually do something that is a large-ish project.

I do have a question though...is there any kind of PHP library or something similar that can do basic database operations but with a file or something instead of an actual server? Getting a MySQL set up on my web-host is annoying, as I don't actually own the account, and there is a neat free MongoDB database, but I'm scared to touch that (although it could be a fun learning experience...anybody around use it before? Anything to say about it?...I got a free reference book from the thing I went to.) All I'm gonig to have is a log-in database with probably under 30 people, I don't know why I need a whole server running a seperate database for that, can't I just keep things in a text file or comma delineated list or something?
Logged
To exist or not exist, that is the query. For whether it is more optimal of the CPU to endure the viruses and spam of outragous fortune, or to something something something.

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5204 on: November 12, 2013, 08:37:36 pm »

It's not production-appropriate, but there's always SQLite3. It's suitable for running locally and/or testing, though.

SQLite is really unsuitable (unusable?) for concurrent connections.
« Last Edit: November 12, 2013, 08:40:24 pm by Mephisto »
Logged
Pages: 1 ... 345 346 [347] 348 349 ... 796