Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
tef
May 30, 2004

-> some l-system crap ->
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.

Adbot
ADBOT LOVES YOU

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

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)

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.

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:
interface IBooleanValueHaver
{
   bool MyBooleanValue {get; set;}
}
If you go and add this interface to 10 classes, you need to add a backing _myBooleanValue field to all 10 classes. Then if you ever change the interface you have to go modify all 10 classes. Having multiple implementations scattered around your codebase that do essentially the same thing is just ugly as hell. It'd be nicer to have some kind of strong interface type (like in the Vala example) that'd let you do something like

code:
interface IBooleanValueHaver
{
   private bool _myBooleanValue;

   public bool MyBooleanValue
   {
       get {return _myBooleanValue;}
       set {_myBooleanValue = value;}
   }
}
Now everything is defined in one place, change it once and it works everywhere. You could even go a step further and allow the strong interface to have it's own optional constructor/destructor that would be handled much like base classes.

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?

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

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)
IMO the guy who wrote that article demonstrates almost no understanding of how interfaces and inheritance are actually supposed to be used. For God's sake, he actually says this:

The Article posted:

Especially for a technique that’s replacing a form of inheritance, which is all about reusable code?
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.

Sedro
Dec 31, 2008

PDP-1 posted:

code:
interface IBooleanValueHaver
{
   private bool _myBooleanValue;

   public bool MyBooleanValue
   {
       get {return _myBooleanValue;}
       set {_myBooleanValue = value;}
   }
}
Now everything is defined in one place, change it once and it works everywhere. You could even go a step further and allow the strong interface to have it's own optional constructor/destructor that would be handled much like base classes.

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?
The backing field is an implementation detail and not necessarily used by every implementer of the interface.

For example, you might proxy to another object:
code:
class BooleanValueHaver : IBooleanValueHaver
{
   private IBooleanValueHaver _inner;

   public bool MyBooleanValue
   {
       get { return _inner.MyBooleanValue; }
       set { _inner.MyBooleanValue = value; }
   }
}
Or perform some other action like change notification or thread synchronization:
code:
class BooleanValueHaver : IBooleanValueHaver, INotifyPropertyChanged
{
   private bool _myBooleanValue;
   public bool MyBooleanValue
   {
       get { return _myBooleanValue; }
       set
       {
           if (_myBooleanValue != value)
           {
               _myBooleanValue = value;
               PropertyChanged(this, new PropertyChangedEventArgs("MyBooleanValue"));
           }
       }
   }

   public event PropertyChangedEventHandler PropertyChanged = delegate { };
}
C# even optimizes for the trivial case (where the property is basically a field) with auto properties to reduce boilerplate:
code:
class BooleanValueHaver : IBooleanValueHaver
{
   public bool MyBooleanValue { get; set; } // Compiler generates backing field
}

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
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?

tef
May 30, 2004

-> some l-system crap ->
use queues and pass messages between the threads :2bong:

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

tef posted:

use queues and pass messages between the threads :2bong:
Eh why not . . . I'll try something in this line on my guinea pig project tonight.

tef
May 30, 2004

-> some l-system crap ->

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:
	static public abstract class Callback<I> {
		// ye old observer pattern
		abstract public void onSuccess(final I input);
		abstract public void onFailure(final RuntimeException e);
		abstract public void onComplete();
	}

	public interface Pipe<I,O> {
                // a pipe takes input and produces output

		// it can be run normally (one in one out) iterator style
		O process(I input);
		// or run with a callback (observer style)
		void processAsync(I input, Callback<? super O> callback);
		
		// if you combine it with another pipe, you get a new pipe with the outer types
		<O2> Pipe<I,O2> next(final Pipe<? super O,O2> pipe);		
		
		// if you combine it with a sink, you get a new sink that takes the pipe input
		Sink<I> next(final Sink<? super O> sink);	
		
		// you can also tee (copy) the output to a callback
		Pipe<I,O> tee(Callback<? super O> callback);
		
		// and you can signal the end of the source.
		void complete();
	}
	
	public interface Source<O> {
		// it can be run to produce a value, returning null on finish.
		O emit();
		// or run with a callback to write to
		void emitAsync(Callback<? super O> callback);
		// when combined with an pipe, it produces a new source
		<O2> Source<O2> next(final Pipe<? super O,O2> pipe);		
		// and with a sink it makes a complete runnable.
		Block next(final Sink<? super O> sink);
		
		Source<O> tee(Callback<? super O> callback);
	}

	
	public interface Sink<I> {
                // unlike a callback, errors propagate up? I have no idea why this is here
		public void consume(final I input);
		public void complete();
	}
	
	public interface Block extends Runnable {
	};
Anyway you have these pipes which can be run or passed a callback to process stream items. You have things that are inputs and things that are outputs. You do input+process*+output to make a runnable.

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.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
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.

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog

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

code:
interface IBooleanValueHaver
{
   private bool _myBooleanValue;

   public bool MyBooleanValue
   {
       get {return _myBooleanValue;}
       set {_myBooleanValue = value;}
   }
}
Now everything is defined in one place, change it once and it works everywhere. You could even go a step further and allow the strong interface to have it's own optional constructor/destructor that would be handled much like base classes.

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?

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/

MrZig
Aug 13, 2005
I exist onl because of Parias'
LEGENDARY GENEROSITY.
Edit: didn't realise there was a Java thread!

MrZig fucked around with this message at 05:58 on Dec 17, 2011

tef
May 30, 2004

-> some l-system crap ->

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

Dolemite
Jun 30, 2005

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:
code:
Bar A = new Bar();
Foo B = A;
Baz C = A; // or = B
Qux D = A;
You now have four variables of different types that all refer to the same object. However, the declared type determines how you may interact with the object.
You may call any public method in Foo or Bar on A, but because the declared (formal) types of B, C and D do not have everything Bar has, you cannot call everything from Bar on those, because formally, those variables are not of type Bar.

You can still call any public method from class Foo (or declared by interface Baz, since Foo implements that) on B, but not any of the methods of Qux or otherwise in Bar.
On C, you can only call the methods declared in interface Baz, and on D you can only call the methods declared in interface Qux.


An interface is a contract that allows your class to promise to adhere to some specification, and allows other code to accept any object that adheres to the specification, regardless of its actual implementation.


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

tef
May 30, 2004

-> some l-system crap ->

Dolemite posted:

Oh. poo poo. I'm making use of method overloading in my app right now.

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.

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!

tef
May 30, 2004

-> some l-system crap ->
Maybe one day all objects will be like Moose :3:

oRenj9
Aug 3, 2004

Who loves oRenj soda?!?
College Slice
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:
(let* ((yin
         ((lambda (cc) (display #\@) cc) (call-with-current-continuation (lambda (c) c))))
       (yang
         ((lambda (cc) (display #\*) cc) (call-with-current-continuation (lambda (c) c)))))
    (yin yang))
From what I can tell,

  • yin's first lambda will display an "@" then return the passed value unaltered.
  • Since let* is used, an @ is displayed because yin is being evaluated.
  • The return value from the yin's first lambda is called with a value that is the result of a call/cc to a lambda whose return value is its only parameter.
  • yang is then assigned and evaluated in the same way.
  • yin is then called with yang as a parameter.
  • "@" is displayed.
  • yang is called with a parameter of (call/cc (lambda (c) c)).
  • "*" is displayed.
  • cc is called, since cc is a call/cc, the procedure is halted.

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:
>>> def yin(x):
	print "@"
	yield x(yin)

	
>>> def yang(x):
	print "*"
	yield x(yang)

>>> gen = yin(yang)
>>> gen = gen.next()
@
>>> gen = gen.next()
*
>>> gen = gen.next()
@
>>> gen = gen.next()
*
>>> gen = gen.next()
@ # should print *

oRenj9 fucked around with this message at 08:32 on Dec 18, 2011

tef
May 30, 2004

-> some l-system crap ->
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:
class Ret(Exception):
    pass
def callcc(func,*args, **kwargs):
    # not really callcc, but hey, let me explain it first
    r = Ret()
    def ret(val):
        r.val = val
        raise r
    # if this was a real continuation, we would have *two* different call stacks
    try:
        func(ret, *args, **kwargs)
    except Ret as e:
        if e is r:
            return e.val
        else:
            raise StandardError('cant use callcc within callcc')


def add_1(r, x):
    r(x+1)

def mul_8(r, x):
    r(x*8)

print callcc(add_1, 1)
print callcc(mul, 1)

def example(r, x):
    add_1(lambda v: mul_8(r,v), x)

print callcc(example, 1)
From here you can see the notions of what a continuation is - it's like a function, but you pass it another function to *continue* to, instead of returning to the caller. The problem with this implementation is you cannot nest call/cc - it is all on the same call stack, and you cannot pass control arbitrarily.

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. :2bong:

tef fucked around with this message at 08:49 on Dec 18, 2011

tef
May 30, 2004

-> some l-system crap ->
oh god I can't sleep

code:
import threading

class ContExit(SystemExit):
    pass

class Continuation(object):
    """ created by call/cc, passed into a new thread, and used to indicate when to resume the calling thread (if at all)

    def __init__(self):
        self.event = threading.Event()
        self.result = None
        self.args = None
        self.exc = None

    def throw(self, e):
        if self.event.is_set():
            raise StandardError('Continuation not restartable, cannot throw exception')

        self.exc = e
        self.event.set()

        threading.current_thread.daemon = True
        raise ContExit()


    def __call__(self, r, *arg):
        """ restart the continuation, exit current thread"""
        if self.event.is_set():
            raise StandardError('Continuation not restartable, cannot resume')

        # don't return single element tuple (like return foo)
        if arg:
            r = [r]
            r.extend(arg)

        self.ret(r)
        threading.current_thread.daemon = True
        raise ContExit()

    def ret(self, r):
        """ set the return value of the call/cc, and tell it to resume """
        if not self.event.is_set():
            self.result = r
            self.event.set()


    def value(self):
        """ block until the continuation is invoked """
        self.event.wait()
        if not self.exc:
            return self.result
        else:
            exc = self.exc
            if not self.exc:
                exc = StandardError('no result')
            raise exc


def callcc(func,*args, **kwargs):
    cont = Continuation()

    if args and isinstance(args[0],Continuation):
        # Calling a continuation with our current continuation - so don't need a thread
        callee =args[0]
        callee.ret(cont)
    else:
        # we are invoking a function, so we create a thread, and block
        def run():
            try:
                cont.ret(func(cont, *args, **kwargs))
            except StandardError as e:
                import traceback; traceback.print_exc()
                cont.throw(e)


        t = threading.Thread(target=run)
        t.start()
    # wait until the contination is invoked
    return cont.value()
so the old examples still work (add_1, etc), but this should give you a taste of continuations
code:
def inner(cont):
    print "inner, calling cont with current cont"
    main_cont, i =callcc(cont)
    print "inner, got main_cont back, calling with",i
    main_cont(i)


def outer(main_cont, inside, i):
    print "outer, calling inner with current cont"
    inner_cont = callcc(inside)
    print "calling inner_cont with main_cont,",i
    inner_cont(main_cont,i)

print "main, calling: outer -> inner -> outer -> inner"
p= callcc(outer, inner, "butt")
print "main, got ", p 
prints

code:
main, calling: outer -> inner -> outer -> inner
outer, calling inner with current cont
inner, calling cont with current cont
calling inner_cont with main_cont,  butt
inner, got main_cont back, calling with butt
main, got  butt
now you can call-cc within a call-cc. and also call-cc with the cc. does this make things clear?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
code:
        if not self.exc:
            return self.result
        else:
            exc = self.exc
            if not self.exc:
                exc = StandardError('no result')
            raise exc

There's lots in that code that's WTF, but I'm going to single out this. I have no idea what this is trying to do. I know what it's trying not to do, though.

Jewel
May 2, 2009

Suspicious Dish posted:

code:
        if not self.exc:
            return self.result
        else:
            exc = self.exc
            if not self.exc:
                exc = StandardError('no result')
            raise exc

There's lots in that code that's WTF, but I'm going to single out this. I have no idea what this is trying to do. I know what it's trying not to do, though.

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:
If there was no exception:
    return the result
Else, if there was an exception:
    set exc to the exception
    <this never gets called>
    raise exc
Either way, can't that be written as:

code:
if self.exc:
    raise self.exc
else:
    return self.result
Edit: Wow I thought I was in the coding horrors thread whoops, I didn't actually read the post above the one I quoted. One moment!

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

tef
May 30, 2004

-> some l-system crap ->

Suspicious Dish posted:

code:
        if not self.exc:
            return self.result
        else:
            exc = self.exc
            if not self.exc:
                exc = StandardError('no result')
            raise exc

There's lots in that code that's WTF, but I'm going to single out this. I have no idea what this is trying to do. I know what it's trying not to do, though.

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.

oRenj9
Aug 3, 2004

Who loves oRenj soda?!?
College Slice

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)-------------
:2bong: Indeed.

Drape Culture
Feb 9, 2010

But it was all right, everything was all right, the struggle was finished. He had won the victory over himself. He loved Big Brother.

The End.
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.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


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.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

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.

TasteMyHouse
Dec 21, 2006
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.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Thermopyle posted:

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.

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.

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction

Thermopyle posted:

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.

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

Scaevolus
Apr 16, 2007

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.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


TasteMyHouse posted:

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.

You might be better off asking in the scientific computing thread.

stubblyhead
Sep 13, 2007

That is treason, Johnny!

Fun Shoe
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. :iiam:

stubblyhead fucked around with this message at 04:01 on Dec 23, 2011

aBagorn
Aug 26, 2004
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:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Typing_Game
{
    public partial class Form1 : Form
    {
        Random Random = new Random();
        Stats stats = new Stats();

        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            listBox1.Items.Add((Keys)Random.Next(65, 90));
            if (listBox1.Items.Count > 7)
            {
                listBox1.Items.Clear();
                listBox1.Items.Add("Game over");
                timer1.Stop();
            }
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (listBox1.Items.Contains(e.KeyCode))
            {
                listBox1.Items.Remove(e.KeyCode);
                listBox1.Refresh();
                if (timer1.Interval > 400)
                    timer1.Interval -= 10;
                if (timer1.Interval > 250)
                    timer1.Interval -= 7;
                if (timer1.Interval > 100)
                    timer1.Interval -= 2;
                difficultyProgressBar.Value = 800 - timer1.Interval;

                stats.Update(true);
            }
            else
            {
                stats.Update(false);
            }
            correctLabel.Text = "Correct: " + stats.Correct;
            missedLabel.Text = "Missed: " + stats.Missed;
            totalLabel.Text = "Total: " + stats.Total;
            accuracyLabel.Text = "Accuracy: " + stats.Accuracy + "%";
        }
    }
}
The problem is the listBox1 never starts populating at all.

I keep going over it and over it, and even checked it against the solution in the book (it matches).

csammis
Aug 26, 2003

Mental Institution
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 :)

aBagorn
Aug 26, 2004

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.

There's also the .Net Questions Megathread if you've got any C# or .NET specific questions for the future :)

Yeah that was it. Like I said, I'm really dumb, and didn't set the timer value to "true"

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
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)

Impotence
Nov 8, 2010
Lipstick Apathy
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

nielsm
Jun 1, 2009



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.

I've been googling for a day now and haven't found anything much useful

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.

Impotence
Nov 8, 2010
Lipstick Apathy

nielsm posted:

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.

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.

Adbot
ADBOT LOVES YOU

ToxicFrog
Apr 26, 2008


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 know there are actual modeling applications but there's 30 million of these sets, and it's just not going to work manually.

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.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply