Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 383 384 [385] 386 387 ... 796

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

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5760 on: April 26, 2014, 11:19:02 pm »

Nice o.O

I sometimes wish I was better at algorithms and dynamic programming, since all the programmingncontests are basically informatics olympiads that are all about dynamic programming. :( To this date I have exactly 1 award (bronze, inschool) from such a competition.
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 #5762 on: April 27, 2014, 06:11:38 am »

Wait, what?

Code: [Select]
Field f = Integer.class.getDeclaredField("value");
f.setAccessible(true);
f.set(5, 6);

Integer i = 5;
System.out.println(i);

Java logic! We don't support operator overloading because it has the potential to be misused by a programmer, but all those other things that can be misused? A-ok!
« Last Edit: April 27, 2014, 06:15:14 am by MorleyDev »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5763 on: April 27, 2014, 06:36:50 am »

What does that code snippet do? What is it supposed to do/why is it being abused? :o
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 #5764 on: April 27, 2014, 07:05:47 am »

What does that code snippet do? What is it supposed to do/why is it being abused? :o
Through reflection, it makes the Integer wrapper class represent the primitive int 5 with primitive int 6.
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #5765 on: April 27, 2014, 12:04:59 pm »

Through reflection, it makes the Integer wrapper class represent the primitive int 5 with primitive int 6.

Essentially. This feature has some more serious use-cases. PowerMock, for example, uses this kind of reflection functionality to allow you to Mock or Stub implementations where you don't have access to an interface (i.e final classes).

Now, I do have some issues with using PowerMock (Most situations, I've found it cleaner to develop an lightweight, abstractable, manual and integration tested facade around the 3rd party libraries) but I can see some usage, especially in migrating towards a better system. A very useful temporary band-aid for working with legacy code.

I just find it somewhat arbitrary at times what features in Java were excluded because people can misuse them (like operator overloading), and what features they went out of their way to include inside the language despite being misusable (complex reflection logic).
Logged

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5766 on: April 27, 2014, 10:25:35 pm »

Probably because operator overloading is "nice to have" but not really a big problem if its not there, wheras reflection is a powerful and useful tool that can do all sorts of magic. Both are abusable, but one is more justifiable.

I am guessing anyway.
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5767 on: April 27, 2014, 11:51:18 pm »

To be honest, I haven't run into many situations where operator overloading was useful.  Vector and matrix math so far is the only example of anything I've written outside of a classroom where it was used.  Operator [] is one I can see being reasonably useful otherwise if you're writing smart containers of some kind, and of course I use that with vectors but not in any class I've written.  The dereferencing operator is useful for smart pointers, but in Java that's kind of pointless.

On the other hand, it is useful for math libraries, and excluding it because it can be misused sounds awfully heavy handed.  It's not like raw pointer levels of dangerous.
Logged
Through pain, I find wisdom.

tahujdt

  • Bay Watcher
  • The token conservative
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5768 on: April 28, 2014, 09:24:12 am »

I am going to embark on programming a text adventure with nothing but a TI-89 Titanium calculator. I will post the results later.
Logged
DFBT the Dwarf: The only community podcast for Dwarf Fortress!
Tahu-R-TOA-1, Troubleshooter
Quote
I suggest that we add a clause permitting the keelhauling of anyone who suggests a plan involving "zombify the crew".
Quote from: MNII
Friend Computer, can you repair the known universe, please?

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #5769 on: April 28, 2014, 04:39:52 pm »

On the other hand, it is useful for math libraries, and excluding it because it can be misused sounds awfully heavy handed.  It's not like raw pointer levels of dangerous.

More or less my thoughts. Not sure how I feel about the opposite extreme yet. Languages like Scala have it so you can use almost any symbol in a function name. So <++> could be a valid function name. They also support infix operations, so you can ommit the . and paranthesis when invoking a function. So x + y is equivalent to x.+(y).

It's mostly used so that they can apply the "everything is a function and every function is an object" concept, making addition and subtraction just predefined functions on certain types. Powerful, certainly, but people can take it a bit too far. Though I do kinda like how + is addition, whilst ++ is concatenation.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5770 on: April 29, 2014, 09:42:51 am »

I have a problem.

Spoiler: image (click to show/hide)

Take this DF map of oceans and rivers. It shows the width of the rivers in quantized levels (around five of them, plus Ocean). I want to make a tree that represents each river, with the parent node being the part where the river joins the ocean and branching off where the river splits. Each node represents a pixel. The problem is, given a piece of the map like



I have no way to decide the parent node. It wouldn't matter normally except that if I make the tree in the wrong direction I can't handle branching of the river :<. How should I go about solving this? I suppose it would be easier to solve if the entire map is given as input (since ocean is guaranteed to exist along the edges), but also take longer to solve.
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

Sheb

  • Bay Watcher
  • You Are An Avatar
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5771 on: April 29, 2014, 10:23:52 am »

So a friend of mine is required to use AIMMS for project in college, but they never taught her how to use it. Anyone here knows good ressources, or would be willing to answer a few questions.
Logged

Quote from: Paul-Henry Spaak
Europe consists only of small countries, some of which know it and some of which don’t yet.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5772 on: April 29, 2014, 10:50:02 am »

I have a problem.

Spoiler: image (click to show/hide)

Take this DF map of oceans and rivers. It shows the width of the rivers in quantized levels (around five of them, plus Ocean). I want to make a tree that represents each river, with the parent node being the part where the river joins the ocean and branching off where the river splits. Each node represents a pixel. The problem is, given a piece of the map like



I have no way to decide the parent node. It wouldn't matter normally except that if I make the tree in the wrong direction I can't handle branching of the river :<. How should I go about solving this? I suppose it would be easier to solve if the entire map is given as input (since ocean is guaranteed to exist along the edges), but also take longer to solve.

I don't think that can be solved if you are doing it in chunks like that.  Maybe you could make a bunch of unrooted nodes with those chunks, and then do a second pass that connects them up to a final tree? 

Honestly I think it might be faster to trace along the edge of the ocean to find the root nodes first, and then just trace the branches recursively.  You could still just load the chunks as you need them while tracing if memory is a concern.
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5773 on: April 29, 2014, 11:42:51 am »

I would go through the whole map first and convert the bitmap data into a more vector-ish format that has direction, elevation, and width, then work from that.
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5774 on: April 29, 2014, 04:29:02 pm »

Welp, I have a confession to make. I am TOO STUPID to figure out how to use IDEs. Its just... its not going to happen. I just can't handle the complexity. At this point I am pretty sure that anything beyond vim and g++  and the command line tools is just going to be forever beyond the grasp of my feeble mind. It is just.... too complex for me. :/

Spoiler: Danger, whine ahead (click to show/hide)
Logged
Pages: 1 ... 383 384 [385] 386 387 ... 796