|
the whole notion of abstraction here is that interfaces capture the behaviour of an object but not the implementation. java objects with different implementations can share the same interface but cannot share the same parent class (easily). and again, interfaces allow classes in java to declare they satisfy other behaviours beyond the ones through class inheritance. there is something to be said about how inheritance in java is used for both code-reuse and sub typing relationships. interfaces allow you to indicate typing without sharing implementation. there isn't a pretty way in java to share code without sharing the type though.
|
# ? Dec 16, 2011 07:27 |
|
|
# ? May 31, 2024 14:14 |
|
tef posted:there is something to be said about how inheritance in java is used for both code-reuse and sub typing relationships. interfaces allow you to indicate typing without sharing implementation. there isn't a pretty way in java to share code without sharing the type though. This is why I like Vala's interfaces, binding method bodies at compile time. It gives all the benefits of the mixin pattern with all the benefits of static typing and type-safety, at the expense of a code size increase (method bodies are literally copied wholesale, with the functions that they refer to changed)
|
# ? Dec 16, 2011 07:40 |
|
Suspicious Dish posted:This is why I like Vala's interfaces, binding method bodies at compile time. It gives all the benefits of the mixin pattern with all the benefits of static typing and type-safety, at the expense of a code size increase (method bodies are literally copied wholesale, with the functions that they refer to changed) That's an interesting article. While interfaces are often very useful, I think that not allowing any logic/fields to be defined within the interface declaration leads to less-maintainable code. For example, suppose you have a simple interface like code:
code:
Do any languages have something like this (fields/logic/constructors), or is there a reason that it's a really bad idea that makes them avoid it?
|
# ? Dec 16, 2011 16:43 |
|
Suspicious Dish posted:This is why I like Vala's interfaces, binding method bodies at compile time. It gives all the benefits of the mixin pattern with all the benefits of static typing and type-safety, at the expense of a code size increase (method bodies are literally copied wholesale, with the functions that they refer to changed) The Article posted:Especially for a technique that’s replacing a form of inheritance, which is all about reusable code?
|
# ? Dec 16, 2011 17:07 |
|
PDP-1 posted:
For example, you might proxy to another object: code:
code:
code:
|
# ? Dec 16, 2011 18:12 |
|
I'm looking for patterns and methodologies for keeping a sequence of instructions somewhat intact when they require requesting stuff from different threads. Say I have a code block that: 1. Requests object X from thread A. 2. Requests object Y from thread B, and thread B needs object X to do the work. Threads A and B will get to it within some milliseconds, but not right away. They'll usually be preoccupied with some system state that will blow right the hell up if the requesting code could directly get objects X or Y directly. So the requests get queued up. The natural thing to do is have some callbacks, which I find to be obnoxious to write out for sequences like this--especially if the volume of instructions starts to get pretty long. Do I need to live with it?
|
# ? Dec 16, 2011 19:03 |
|
use queues and pass messages between the threads
|
# ? Dec 16, 2011 19:57 |
|
tef posted:use queues and pass messages between the threads
|
# ? Dec 16, 2011 20:34 |
|
Rocko Bonaparte posted:I'm looking for patterns and methodologies for keeping a sequence of instructions somewhat intact when they require requesting stuff from different threads. More seriously, *don't do it that way*. You should be able to encapsulate the flow control you want if you find a good way to express the problem. You might find pipelines or dataflow styles a more appropriate way to structure the problem. I have some terrible java code around somewhere which was an attempt to use generics to build mostly type safe pipes - that looks something like this (apologies for the following quality, but hopefully this will explain the ideas I am suggesting - the code happened late one night a few years ago after reading a paper about arrows (do not blame arrows)). this really belongs in the coding horrors thread. code:
This only serves as an example of a related approach - I have no idea how well it fits your problem. I am trying to demonstrate the ideas of composing your program from smaller independent blocks, where the operators you build determine the data flow between them and the execution.
|
# ? Dec 16, 2011 21:46 |
|
I was thinking for some cases, it's fine enough to just queue something up and have a callback take care of it, but for those sequences, I'd write a helper that takes the callback and waits for it. I don't have it fully formed in my head though. I'm working in C++ right now so I was pondering if there was something with templates I could do there so the helper would be less tedious.
|
# ? Dec 16, 2011 22:45 |
|
PDP-1 posted:It'd be nicer to have some kind of strong interface type (like in the Vala example) that'd let you do something like What you're talking about is sometimes referred to as "role" or "trait" based OOP. All I know about it, I learned from these slides: http://sartak.org/talks/osdc.tw-2010/nonhierarchical-oop/
|
# ? Dec 16, 2011 22:53 |
|
Edit: didn't realise there was a Java thread!
MrZig fucked around with this message at 05:58 on Dec 17, 2011 |
# ? Dec 17, 2011 05:47 |
|
Smugdog Millionaire posted:What you're talking about is sometimes referred to as "role" or "trait" based OOP. All I know about it, I learned from these slides: http://sartak.org/talks/osdc.tw-2010/nonhierarchical-oop/ Traits own (and often called roles). I really wish they were in more languages. I mentioned a design style earlier (DCI) which is heavily influenced by traits. The important difference with roles as opposed to traditional class or prototype based pop is that they are 'flattened' when composed - there is no notion of a 'parent' (class or object).
|
# ? Dec 17, 2011 07:35 |
|
nielsm posted:If you have an object of class Bar that inherits from class Foo, where Foo implements interface Baz, and Bar additionally implements interface Qux, the following is all valid: tef posted:Almost. The idea is that many things can implement the Foo interface, and that the code does care not *which* one. Between the two of you, I think I've gotten the idea behind interfaces and how they can be pretty powerful tools. Orzo posted:Both are bad practice, if that helps explain anything. Oh. poo poo. I'm making use of method overloading in my app right now. Orzo posted:Seriously? If you're using inheritance as a code-reuse mechanism you're doing it very, very wrong. Creating and inheriting from a base class because two or more classes that share code, instead of abstracting that behavior into a separate composed class, is the root of so very many badly designed systems. I'm doing this, too. I figured if a couple classes are going to be using the same function to, for example, connect to a DB, then why duplicate the code when I can re-use it. Between reading here what I can do with interfaces and learning about some of the design patterns like composition, it looks like I'm going to have some code rewriting to do...
|
# ? Dec 18, 2011 07:29 |
|
Dolemite posted:Oh. poo poo. I'm making use of method overloading in my app right now. Don't worry too much. Objects aren't great for code, and doing the right thing™ is often more verbose and clunky. Objects haven't changed much in the last 30 years, but the best practices have moved on. Unfortunately, until languages catch up with the idioms, we're left with design patterns and other boilerplate to make-do. Sometimes, it's easier to do the 'wrong' thing if it is simple to write, and easy to fix later. quote:Between reading here what I can do with interfaces and learning about some of the design patterns like composition, it looks like I'm going to have some code rewriting to do... The key problem here is that inheritance serves two purposes in mainstream class based languages: Subtyping and Code/Structure-Reuse. And you don't get to choose which. Some languages don't have this problem -with multiple Inheritance means you can get away with code-reuse and accidental subtypes - it makes it possible, but ugly. Traits are similar to multiple inheritance, but a cleaner mechanism - by composing the traits together, into a flat object you avoid the issues with multiple parents. So yeah, inheritance has two intents - code reuse, sub typing. and two possible mechanisms - copying from a parent, and delegating to a parent Other solutions involve controlling the exposure of sub typing information (private inheritance), or a separate mechanism altogether for sub-typing, leaving inheritance only for code-reuse.. Really, It's not you, the language is just not designed to be used in the way we recommend. Hooray!
|
# ? Dec 18, 2011 08:10 |
|
Maybe one day all objects will be like Moose
|
# ? Dec 18, 2011 08:12 |
|
Is call-with-current-continuation in Scheme effectively the same thing as the yield keyword in Python? That is the conclusion I drew after reading the Wikipedia page on the subject. Then, I came across this comp.lang.lisp entry and now I doubt that I am understanding command correctly. To make matters worse for me, I'm having trouble completely wrapping my head around what is going on with the sample given on the Wiki page to explain this phenomena. code:
This is where I get confused, shouldn't yang be called again? This should result in an infinite number of "*" being displayed, since each call to yang would result in a halt and flow control returning to the other instance of yang? Edit: I tried to emulate this behavior in Python, but didn't achieve the same result. So, unless my Python code has a bug, I guess yield and call/cc are different. code:
oRenj9 fucked around with this message at 08:32 on Dec 18, 2011 |
# ? Dec 18, 2011 08:19 |
|
python's yield is more like a coroutine, not a continuation. you can 'simulate' some of call/cc in python, but not scheme people please don't hurt me code:
However, with call-with-current-continuation in scheme, it actually wraps up the call stack, starts a new one afresh and passes the old one in as an argument. Meanwhile, python is different, with a generator, yield returns to the caller of the function. You can think of continuations as like yield, but yielding the state to an arbitrary function, rather than the caller. tef fucked around with this message at 08:49 on Dec 18, 2011 |
# ? Dec 18, 2011 08:42 |
|
oh god I can't sleepcode:
code:
code:
|
# ? Dec 18, 2011 10:21 |
|
code:
|
# ? Dec 18, 2011 11:41 |
|
Suspicious Dish posted:
Seems fairly simple to me, if a bit butchered by terrible naming and that strange block that can never do anything. self.exc must be a variable they place an exception into instead of raising it immediately for some reason. Single exit points hooray? code:
code:
Edit2: Eh, I think what I said still applies fairly well. That's what I get for posting so late though I guess! Jewel fucked around with this message at 13:46 on Dec 18, 2011 |
# ? Dec 18, 2011 13:43 |
|
Suspicious Dish posted:
Haha, this is what you get when you write some code at 9am on a sunday. Originally I used self.result to keep a tuple of return values and None for the lack of a value, so it was possible there was no return value and no-exception.
|
# ? Dec 18, 2011 19:39 |
|
tef posted:now you can call-cc within a call-cc. and also call-cc with the cc. does this make things clear? Yes, thank you. At first, I missed where call/cc created a completely new call stack. That explains why call/cc operates the way it does. The reason why call/cc stops execution after the passed function completes is because there is nowhere left on the call stack to return to. In the wiki example, yin calls yang, which then reinvokes the yin, but in the context of the original call and appends another yang to that call stack. pre:yin( yang( yang( yang( yang( yang( [ad infinitum] )))))) ^-(cont)- ^----(cont)---- ^-------(cont)------- ^----------(cont)---------- ^-------------(cont)-------------
|
# ? Dec 18, 2011 20:24 |
|
This is less a specific programming question and more a resource question: I've been taking a class that decided to make a huge deal of lambda calculus, which apparently, I do not understand in the least. While it's really too late to do much about that, I actually do want to know what I did or did not understand. Does anyone have any recommendations as to resources that are useful for this end? Either theory or application would work, but something that is well written is obviously preferable.
|
# ? Dec 19, 2011 11:53 |
|
ManlyWeevil posted:This is less a specific programming question and more a resource question: I've been taking a class that decided to make a huge deal of lambda calculus, which apparently, I do not understand in the least. While it's really too late to do much about that, I actually do want to know what I did or did not understand. Does anyone have any recommendations as to resources that are useful for this end? Either theory or application would work, but something that is well written is obviously preferable. Types and Programming Languages is very well-written, and (IMO) does a very good job of explaining what the lambda calculus is and why it's important.
|
# ? Dec 19, 2011 22:30 |
|
I'm considering selling a little Windows utility. Having never done for-pay software before, what are my options for accepting payment? I guess I'm fine with just using paypal, but I don't want to do all this poo poo manually of course. What's a good way to tie payments to users or product keys? I could, of course, develop a backend to take care of all this but surely this is a common enough thing where I don't have to bother with re-inventing the wheel. I'm not terribly interested in preventing piracy or whatever...that's going to happen no matter what, and I'm of the opinion that if someone pirates something they probably wouldn't of purchased it anyway. Anyway, just looking for some discussion of the options here.
|
# ? Dec 20, 2011 21:27 |
|
Question about R and Rcpp -- I have a package I'm writing for R 2.14.0, using C++ and Rcpp. I started this package by using Rcpp.package.skeleton("myPackage"). If I use gcc 4.1.2 (the default version at my company), I can use $ R CMD INSTALL myPackage and it will install fine, I can load the package, use it, etc -- this is in SPITE of the fact that during the compile step, R passes -R/usr/local/lib to gcc. gcc 4.1.2 just warns about the bad option and ignores it. But now, I want to use some C++0x features in my package, so I set my gcc version to 4.6. Now, gcc gets mad and errors out, quitting the compile step, ruining the package installation. Can I get gcc to shut up about the bad option and just keep going? I know how to get R to pass additional options. OR Can I get R/Rcpp to stop passing that bogus option in the first place? the only place I know where to configure the options that are passed to gcc are in the Makevars file, and that file doesn't make any reference to -R. This is a really difficult problem to google, incidentally.
|
# ? Dec 21, 2011 17:23 |
|
Thermopyle posted:I'm considering selling a little Windows utility. You can go with various shopping cart solutions (some free most not), but for something that small I'd just roll your own. For only one SKU I'd just dumb up a 4 page site (product/about/contact/cart) and then have PayPal do all the processing; it's really straightforward and there's tons of examples laying around. As for the license keys I have no idea; off the top of my head would probably take a GUID and then non-deterministically transform it somehow.
|
# ? Dec 21, 2011 20:31 |
|
Thermopyle posted:I'm considering selling a little Windows utility. PayPal can post to your endpoint with payment details, so you could use that to kick off an email with a license key. That way you could just have one "pay" button, let PayPal handle the demographics and payment details, then present you with some user info, and a tx ID. Factor Mystic fucked around with this message at 21:09 on Dec 21, 2011 |
# ? Dec 21, 2011 21:07 |
|
Consider a payment processor like Stripe if you don't want to turn off people that don't have Paypal accounts. (Yes, I know you don't need an account to use Paypal, but they might not). Also for licenses, consider using cryptographically signed license files.
|
# ? Dec 21, 2011 21:50 |
|
TasteMyHouse posted:Question about R and Rcpp -- You might be better off asking in the scientific computing thread.
|
# ? Dec 21, 2011 21:54 |
|
I didn't see a VBScript thread; hope it's ok if I ask a question here. I'm working with an adapted legacy script that checks for the existence of a folder on a remote host before continuing. However, the account that is running the script doesn't have access to the folder and will not be able to find it. According to this if you map a network drive in your script using the credentials you want to use, those creds will carry over when you check for whether the folder is there. When I try this though, I get an error reading "WSHNetwork.MapNetworkDrive: The network name cannot be found." I'm printing the path I'm using to stdout, and I can open the folder with no problems. My username and password are correct, though I would imagine I'd get an access denied error if they weren't. Here's the relevant portion of my script with some details modified for security: Set objNetwork = WScript.CreateObject("WScript.Network") objNetwork.MapNetworkDrive "", strUNClientDir, False, username, password I've tried specifying a specific drive letter to map to in case it was upset about me not using one, but I got the same result. Any ideas what I'm doing wrong here? e: This is actually some kind of bizarre connectivity issue that I don't fully understand. I'm calling the script in a different way now and it's working fine now. stubblyhead fucked around with this message at 04:01 on Dec 23, 2011 |
# ? Dec 22, 2011 04:50 |
|
Ok, so I'm a complete dummy. I'm trying to teach myself C# having never learned a language before, and I'm stuck on a textbook exercise. What I'm doing is creating a game that populates a form with random letters, and then tracks user keystrokes and matches them against whats in a listbox. As keys are pressed incorrectly, the box will fill up, and if it gets to 7 letters, the game is over. Here's the code. code:
I keep going over it and over it, and even checked it against the solution in the book (it matches).
|
# ? Dec 23, 2011 15:15 |
|
There is much in the forms designer that might explain what's going on. At a glance I'm not seeing any place in your non-generated code where the timer is actually started. There's also the .Net Questions Megathread if you've got any C# or .NET specific questions for the future
|
# ? Dec 23, 2011 15:31 |
|
csammis posted:There is much in the forms designer that might explain what's going on. At a glance I'm not seeing any place in your non-generated code where the timer is actually started. Yeah that was it. Like I said, I'm really dumb, and didn't set the timer value to "true"
|
# ? Dec 23, 2011 17:40 |
|
aBagorn: C# with Winforms is really really really easy to debug, you should definitely learn how to do it if you don't know how to already. If you had set a breakpoint on the first line of your timer code, and F5, and noticed that the program never stopped, you probably would have known right away that the timer wasn't activated. If you don't know, just click the left gray bar to the left of code to set a breakpoint, and hit F5 to run your program in debug mode. Then you can use F9/F10 to step through your code (or use the Debug menu)
|
# ? Dec 23, 2011 17:46 |
|
Not too sure if this belongs here, but is there any way I can convert a DDS texture + NIF model (header: "Gamebryo NIF") into a png-represenstation of it facing forward, or obj and png-texture? (preferably just a straight up .png of the model+texture facing forward. I've been googling for a day now and haven't found anything much useful
|
# ? Dec 24, 2011 03:14 |
Biowarfare posted:Not too sure if this belongs here, but is there any way I can convert a DDS texture + NIF model (header: "Gamebryo NIF") into a png-represenstation of it facing forward, or obj and png-texture? (preferably just a straight up .png of the model+texture facing forward. That's not a "conversion" you're looking at, that's a rendering. You'll need a rasterisation system capable of loading the model format and PNG textures. Then you'll want to analyse the model so you can set up a camera that includes the entire thing in view, without making it too small, and then render it to a new image file. (That is, render it to an in-memory image and store that to disk.) The reason it is complicated is because the model is 3D so you'll need a full texturing system, getting one right and looking good isn't exactly a simple thing. Even when just viewing the model from the front, there will still be surfaces at an angle to the camera*, regardless of the projection chosen. * Except in the simplest of simple cases, such as a cube aligned to the axes.
|
|
# ? Dec 24, 2011 03:27 |
|
nielsm posted:That's not a "conversion" you're looking at, that's a rendering. I have basically no experience in this and had a job dumped on me, is there any form of tool I can automate this with? It doesn't need to look good, just "is the basic structure and color there" I know there are actual modeling applications but there's 30 million of these sets, and it's just not going to work manually.
|
# ? Dec 24, 2011 03:36 |
|
|
# ? May 31, 2024 14:14 |
|
Biowarfare posted:I have basically no experience in this and had a job dumped on me, is there any form of tool I can automate this with? It doesn't need to look good, just "is the basic structure and color there" I'm not sure an automatic renderer is going to help here anyways since someone's going to then have to check those 30 million renders to see if they're properly structured. They might as well check them in the model viewer directly.
|
# ? Dec 24, 2011 05:13 |