Options

using(PennyArcade.Forum){Threads.push(ProgrammingThread())}

13468963

Posts

  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited January 2010
    Java lets you do this:


    "someString".stringMethod()

    that just seems wrong.

    Jasconius on
  • Options
    HalibutHalibut Passion Fish Swimming in obscurity.Registered User regular
    edited January 2010
    Senjutsu wrote: »
    Senjutsu wrote: »
    Interfaces, in the AS/Java/C# meaning of the word, just specify a contract, they aren't an implementation sharing mechanism.

    So my answer would be (broadly) no, there are no languages that let you share implementation via a public method contract specification construct.

    Random geek point scoring. It's been aaaaaages since I used the language but I think Ada95 would allow you to do so. It would spit in your face and call you rude names as you did so but I believe you could do so given what can go in a spec file.

    Eh, I really think there's a lot of misunderstanding re: contracts vs implementation here.

    Jasconious' question was essentially meaningless. AS3 "Interfaces" specify contracts; contracts, by definition, do not impose implementation.

    So when I said, there are no languages with contract specification mechanisms that let you share implementation, it was kind of a joke answer. Any language feature which lets you share implementation is, by definition, not a contract mechanism.

    Also, Ada95 packages are basically class analogues in most other OO languages. A package spec can be a package in-and-of-itself if it is complete enough, and can be inherited from.

    I interpreted the original question as "How can I reuse a partial implementation of a contract so that I don't have to keep implementing the functionality in everything that implements that contract?"

    Almost all OO languages will let you partially implement an interface as an abstract class. And some, like Scala and C++, will let you piece together multiple partial implementations of an interface to create a new abstract class.

    Halibut on
  • Options
    SenjutsuSenjutsu thot enthusiast Registered User regular
    edited January 2010
    Halibut wrote: »
    Senjutsu wrote: »
    Senjutsu wrote: »
    Interfaces, in the AS/Java/C# meaning of the word, just specify a contract, they aren't an implementation sharing mechanism.

    So my answer would be (broadly) no, there are no languages that let you share implementation via a public method contract specification construct.

    Random geek point scoring. It's been aaaaaages since I used the language but I think Ada95 would allow you to do so. It would spit in your face and call you rude names as you did so but I believe you could do so given what can go in a spec file.

    Eh, I really think there's a lot of misunderstanding re: contracts vs implementation here.

    Jasconious' question was essentially meaningless. AS3 "Interfaces" specify contracts; contracts, by definition, do not impose implementation.

    So when I said, there are no languages with contract specification mechanisms that let you share implementation, it was kind of a joke answer. Any language feature which lets you share implementation is, by definition, not a contract mechanism.

    Also, Ada95 packages are basically class analogues in most other OO languages. A package spec can be a package in-and-of-itself if it is complete enough, and can be inherited from.

    I interpreted the original question as "How can I reuse a partial implementation of a contract so that I don't have to keep implementing the functionality in everything that implements that contract?"

    Almost all OO languages will let you partially implement an interface as an abstract class. And some, like Scala and C++, will let you piece together multiple partial implementations of an interface to create a new abstract class.

    All true, just a difference in the reading of the question, I guess.

    Senjutsu on
  • Options
    HalibutHalibut Passion Fish Swimming in obscurity.Registered User regular
    edited January 2010
    Halibut wrote: »
    Language: Java
    Framework: JEE, Spring, Hibernate, Struts
    Purpose: Web Development


    Summary: I do J2EE web development for my job. It's pretty awesome and I get to work on a variety of interesting problems. I work on all tiers of these systems from the UI down to the database and integration with legacy systems.

    If you want massively scalable enterprise web applications then Java is one of the best decisions you could possibly make. The only thing that would make me love my job more is if we switched to Scala instead of Java.

    That said, if you want to create a small-medium sized webapp, then Java and all of its enterprise-centric design decisions will probably be overkill. You're probably better off sticking with Python or Ruby or PHP (unless you just prefer static typing, or still need things to perform fast, or whatever reason makes Java more appealing to you).

    What is so good about it? It seems like I have to reinvent the wheel at every turn, and Java is like a language that forgot to have anything fun or cool. It's like someone took C++ and removed the insanity, but also half the features and all traces of personality. Granted, the project I am working on uses no libraries except an object-relational mapper written by my employer and I haven't been able to figure out any way to rig up a reasonable MVC system on my own, so that sucks.

    The main thing that is so good about it is performance. Look at any server running PHP or Python or Ruby and try throwing hundreds or even thousands of concurrent users at it. You'll usually get better server performance out of these languages by putting them on the JVM (Jython, JRuby).

    I fully endorse your statement that Java as a language sucks. Although, there are a lot of libraries out there that make Java, and specifically J2EE, better. Spring as an IOC container (as well as a ton of other useful features), Hibernate for your OR/M stuff, Struts or Spring MVC for your MVC (raw Servlet stuff starts to get unmanageable without a good view layer framework). And all of these are combined with relative ease and make your job as a programmer a lot easier.

    Halibut on
  • Options
    HalibutHalibut Passion Fish Swimming in obscurity.Registered User regular
    edited January 2010
    Jasconius wrote: »
    Java lets you do this:


    "someString".stringMethod()

    that just seems wrong.

    That's not so weird. It's just the language allowing you to shorthand something that would normally be annoying to write:

    new String("someString").stringMethod()

    Halibut on
  • Options
    SenjutsuSenjutsu thot enthusiast Registered User regular
    edited January 2010
    Halibut wrote: »
    The main thing that is so good about it is performance. Look at any server running PHP or Python or Ruby and try throwing hundreds or even thousands of concurrent users at it. You'll usually get better server performance out of these languages by putting them on the JVM (Jython, JRuby).

    While true to a certain extent, the reality of the situation is that most sites become database-bound before they become CPU bound, so choice of implementation language for a web app shouldn't primarily be based on CPU concerns.

    See also: Large chunks of google are written in python.

    Senjutsu on
  • Options
    SenjutsuSenjutsu thot enthusiast Registered User regular
    edited January 2010
    Jasconius wrote: »
    Java lets you do this:


    "someString".stringMethod()

    that just seems wrong.

    I'd say it just seems right. Strings should be strings. Things that are objects should always be objects. Far worse, to me, is having a String object and "some thing in quotes" not actually be an instance of it.

    Mind you I come from the Smalltalk/Ruby everything is an object school of thought

    Senjutsu on
  • Options
    StarfuckStarfuck Registered User, ClubPA regular
    edited January 2010
    Speaking of Smalltalk, I'm about half-way through my first book and I really like it. I also have to say, I work in VS2K8 and an Eclipse variant and I wish they were as efficient as the Squeak environment.

    Starfuck on
    jackfaces
    "If you're going to play tiddly winks, play it with man hole covers."
    - John McCallum
  • Options
    SenjutsuSenjutsu thot enthusiast Registered User regular
    edited January 2010
    I also have to confess a love for the Ruby block concept
    5.times do |i|
         puts i
    end
    

    is just so purdy

    Senjutsu on
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited January 2010
    but. but. it doesn't have these {}

    Jasconius on
  • Options
    xzzyxzzy Registered User regular
    edited January 2010
    Nor does it have the word "for" anywhere. I get uncomfortable without my for loops. :(

    xzzy on
  • Options
    LoneIgadzraLoneIgadzra Registered User regular
    edited January 2010
    Seconding that blocks confuse the hell out of me. Still trying to figure out how they are at all superior to the "normal" way of phrasing a for loop.

    LoneIgadzra on
  • Options
    dmitdmit Registered User regular
    edited January 2010
    do...end and curly brackets are interchangeable in Ruby. A common convention is to use the former for multi-line blocks and the latter for one-liners.
    5.times { |i| puts i }
    

    The for loop is a bit different from C:
    for i in 1..5
        puts i
    end
    
    Ruby blocks are pretty nice for callbacks and other situations when you need to pass an anonymous function along. Especially with event-driven programming being all the rage these days.


    They also allow to streamline certain code patterns:
    file = File.open("/tmp/file", "w")
    file.puts "text"
    file.close # don't forget to explicitly close the file handle
    
    vs.
    
    File.open("/tmp/file", "w") do |file|
        file.puts "text"
    end # the file handle is automatically closed here
    

    dmit on
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited January 2010
    They aren't. But a lot of people who make a living writing Ruby books want us to think they are.

    Jasconius on
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited January 2010
    Well, all that is is a using statement in C#

    Using(Object)
    {
    some code with Object
    }

    //object is disposed of at the end of using

    Jasconius on
  • Options
    InfidelInfidel Heretic Registered User regular
    edited January 2010
    Blocks and closures can be handy.

    I use so many languages I don't think I have a real preference.

    Infidel on
    OrokosPA.png
  • Options
    dmitdmit Registered User regular
    edited January 2010
    The difference is that using is a statement and has a limited purpose - disposing of temporary objects that implement a specific interface. Same for iteration with foreach. That's additional syntax you have to learn.

    Ruby blocks are more flexible and you don't have to create new keywords and change the runtime in order to get the functionality you need.

    dmit on
  • Options
    RiemannLivesRiemannLives Registered User regular
    edited January 2010
    Jasconius wrote: »
    Starfuck wrote: »
    Jasc, you could create a "fake" Abstract class from your interface and declare your variables and have the functions throw illegal operation errors. That's the cleanest way I know to do it. I'm pretty judicious in my use of Interfaces and Abstract classes while I work.

    Yeah I see what you are saying, but in Flash, and AS3 in particular, you can have functionally different elements with different base classes that both have the need for an end-result set of methods.

    In particular MovieClip and Sprite, which co-exist badly.

    Both are used for displaying, but you couldn't make an Abstract class to subclass from for both, you'd have to make two abstract classes and maintain both, which would be silly.

    They both inherit from a common class, however.

    Also, it's been a year since I wrote any AS3 but I could have sworn it (unlike AS2) allowed properties (aka: "getter, setters") in interfaces.

    If you are working with classes you really should be uses properties not public variables anyway.

    RiemannLives on
    Attacked by tweeeeeeees!
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited January 2010
    well, a huge amount of Flash API classes use public variables, one

    two, it totally doesn't matter for a lot of stuff, why write 15 getter/setters that do absolutely nothing nor will they ever.

    three, yeah, they inherit from the same class, but what good is it for me to subclass a DisplayObjectContainer? I can't magically wedge my abstract class in between DisplayObjectContainer and Sprite/MovieClip. That's an irrelevant piece of information. Similarly, a common inheritance gives me nothing, since I need new methods and DOC is not a dynamic object.

    four, I know interfaces allow getter setters, I said that in my first post on the topic. it mandates writing a lot of meaningless crust, and what good is that?

    Jasconius on
  • Options
    SenjutsuSenjutsu thot enthusiast Registered User regular
    edited January 2010
    Seconding that blocks confuse the hell out of me. Still trying to figure out how they are at all superior to the "normal" way of phrasing a for loop.

    "5.times" is a very artificial example, but the fact that it "reads" a bit like an english sentence points towards what blocks are really useful for in Ruby: creating Domain Specific languages.

    And of course if you're a language nerd passing lambdas is always cool

    Senjutsu on
  • Options
    ProtoMan39ProtoMan39 Registered User regular
    edited January 2010
    Jasconius wrote: »
    Java lets you do this:


    "someString".stringMethod()

    that just seems wrong.

    Honestly, there are so many things Java does that just seems wrong. I'm used to C++ and then Perl, and using Java is...ugh.

    ProtoMan39 on
  • Options
    RiemannLivesRiemannLives Registered User regular
    edited January 2010
    Jasconius wrote: »
    four, I know interfaces allow getter setters, I said that in my first post on the topic. it mandates writing a lot of meaningless crust, and what good is that?

    It solves your problem?

    RiemannLives on
    Attacked by tweeeeeeees!
  • Options
    HalibutHalibut Passion Fish Swimming in obscurity.Registered User regular
    edited January 2010
    Senjutsu wrote: »
    Halibut wrote: »
    The main thing that is so good about it is performance. Look at any server running PHP or Python or Ruby and try throwing hundreds or even thousands of concurrent users at it. You'll usually get better server performance out of these languages by putting them on the JVM (Jython, JRuby).

    While true to a certain extent, the reality of the situation is that most sites become database-bound before they become CPU bound, so choice of implementation language for a web app shouldn't primarily be based on CPU concerns.

    See also: Large chunks of google are written in python.

    Definitely. I'm hoping I didn't come across as "Java is the end-all be-all of languages," I was just trying to give an example of Java's strengths. Concurrency and performance being 2 of the biggest (aside from its library support).

    Halibut on
  • Options
    HalibutHalibut Passion Fish Swimming in obscurity.Registered User regular
    edited January 2010
    ProtoMan39 wrote: »
    Jasconius wrote: »
    Java lets you do this:


    "someString".stringMethod()

    that just seems wrong.

    Honestly, there are so many things Java does that just seems wrong. I'm used to C++ and then Perl, and using Java is...ugh.

    My only real problem with Java is that it's too verbose. I hate having to write this:

    Map<String,List<Integer>> map = new HashMap<String,List<Integer>>();

    instead of this:

    Map<String,List<Integer>> map = new HashMap();

    or even this:

    Map map = HashMap(("a",List(1,2,3)), ("b",List(4,5,6)));



    And don't even get me started on the need to create anonymous classes because there's no support for closures.

    Halibut on
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited January 2010
    Jasconius wrote: »
    four, I know interfaces allow getter setters, I said that in my first post on the topic. it mandates writing a lot of meaningless crust, and what good is that?

    It solves your problem?

    I wasn't asking for a resolution to a problem. I already solved it. I was asking an over-broad question about interfaces in general and pointing out some severe deficiencies in the design of Interfaces for AS3 given the public variable laden nature of their core API's.

    It's a language design thought, and I think the rational answer would be that Adobe should be rewriting their Flash libs to use properties instead of forcing their developers to write getter/setters for every variable in the API as it comes up.

    But I guess it makes you feel smart, so whatever.

    Jasconius on
  • Options
    LoneIgadzraLoneIgadzra Registered User regular
    edited January 2010
    Halibut wrote: »
    My only real problem with Java is that it's too verbose.

    TELL ME ABOUT IT. With Java I feel like my typing-to-meaningful code ratio is incredibly bad. It's not a hard or strange language. It's just so. damn. tedious. to. type.

    And you bring up a good point: why the hell can't I add things to a data structure in its constructor? C++ is getting that shit fixed... or auto-generated properties would be nice too...

    As for anonymous classes, so far the main uses seem to be in GUI programming and I use a UI designer like the one in NetBeans to avoid it.

    LoneIgadzra on
  • Options
    SenjutsuSenjutsu thot enthusiast Registered User regular
    edited January 2010
    The other thing that burns me about Java is its half-assed "generics", which in realty is nothing but a bunch of autogened casts to and from Object

    Senjutsu on
  • Options
    xzzyxzzy Registered User regular
    edited January 2010
    What pisses me off about java is how it appears no one can create a java program that runs on more than one release. A disturbingly large number of software packages I use at work bundle their own version of the java runtimes into an installer because they can't be bothered to try for some backwards compatibility. That runtime environment isn't small either. It turns a 1-2 megabyte piece of software into a 50 megabyte or more download.

    Really, someone fucked up pretty big when they created a language that has to be installed multiple times on a single system just so user programs will run.

    xzzy on
  • Options
    SenjutsuSenjutsu thot enthusiast Registered User regular
    edited January 2010
    Blame the deathgrip between the class library and the base VM. .Net is basically just as bad

    Senjutsu on
  • Options
    StarfuckStarfuck Registered User, ClubPA regular
    edited January 2010
    I think I'm going to take a crack at learning java this year too. Just about every book I have read on TDD or some Design practices has used java as it's examples, so I've seen plenty of it. Besides, I want to play with Selenium and I think it requires java to build acceptance tests.

    Starfuck on
    jackfaces
    "If you're going to play tiddly winks, play it with man hole covers."
    - John McCallum
  • Options
    HalibutHalibut Passion Fish Swimming in obscurity.Registered User regular
    edited January 2010
    Senjutsu wrote: »
    The other thing that burns me about Java is its half-assed "generics", which in realty is nothing but a bunch of autogened casts to and from Object

    This is usually only a problem when you need to get an object's "real" type at runtime. Which usually only happens when you are doing something weird like getting a parameterized constructor through reflection.

    I wouldn't go back to Java 1.4 though simply because it greatly enhances my productivity in an IDE when I can hover over a variable and see what type of object can be put in it. I would have to do all that casting myself, and now my code looks cleaner and the compiler prevents me from making a stupid type casting error.

    The edge cases though, where Java's type system breaks down, can get you in a bunch of trouble.

    Halibut on
  • Options
    SenjutsuSenjutsu thot enthusiast Registered User regular
    edited January 2010
    Halibut wrote: »
    Senjutsu wrote: »
    The other thing that burns me about Java is its half-assed "generics", which in realty is nothing but a bunch of autogened casts to and from Object

    This is usually only a problem when you need to get an object's "real" type at runtime. Which usually only happens when you are doing something weird like getting a parameterized constructor through reflection.

    Or if you want to create a new instance of the class. Or if you need to distinguish between instances of a class that were parameterized on different types.

    When I was re-implementing some custom ORM libraries I originally wrote in C# in Java, the silly type erasure system necessitated some silly and cumbersome work-arounds because of a couple of those issues.

    Senjutsu on
  • Options
    YontouryuYontouryu Registered User regular
    edited January 2010
    I have a question the programming thread. At work, the UI needs to be able to get content from a 3rd party (like Flickr) for a coverflow-like interface. In this way, the UI needs to be able to ask for content in a range, such as items 9-12, or 15-27. However, Flickr don't allow you to get stuff in that fashion, only allowing you get to things back in pages (as much as I've seen from the API). So I'm trying to come up with an algorithm that will take the range and find the minimum page size such that I can make one request that will return everything within that range, though likely with unless items as well. So far I've come up with:
    getContent(start, end) {
    if(end-start > start)
    {
    	//pagesize > number of elements before the first we want, so impossible to get a page with every elemented wanted unless its
    	//first page and the page size is end
    	//alternative is to make multiple calls with different sized pages, but this could be more overheard than getting some extra items back, depending on how big start is (ie wanting 2-10 and getting 1-10 is ok, wanting 40-90 and getting 1-90 no so ok
    }
    else
    {
    	oPagesize = end-start
    	cPagesize = oPagesize 
    	while(true)
    	{
    		if(cPagesize == start)
    		{
    			break;
    		}
    		
    		int diff = start mod cPagesize
    		if((cPagesize-diff) >= oPagesize)
    		{
    			found = true
    			break;
    		}
    		
    		cPagesize++
    	}
    	
    	page = floor(start / cPagesize)+1
    	photos = flickr.getphotos(page, cPagesize)
    	photos.subset(start % cPagesize, end)
    }
    }
    
    As such, if asked for a range of 16-26, oPagesize=11 (inclusive), minimum page size needed is 14, then we would get page 2 of size 14, giving us 14-28, then prune down to 16-26.

    Does anyone know any published/known algorithms that would what I need? And can you see any flaws in my algorithm? At this point the only thing I think there is trouble with is finding the lowest ceiling case for the loop, to make it as efficient as possible.

    Have at it!

    Yontouryu on
    a3968.png
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited January 2010
    Worst thing I've seen all day
    (clearanceFlag == "false")? "SALE! ":"CLEARANCE! ";
    

    Spacing preserved.

    Jasconius on
  • Options
    SenjutsuSenjutsu thot enthusiast Registered User regular
    edited January 2010
    haha

    Senjutsu on
  • Options
    naengwennaengwen Registered User regular
    edited January 2010
    Anyone here happen to have some ASP.Net experience? I'm looking to hide/disable/suppress the error dialog box that pops up when an unhandled exception occurs on my web app(relevant info is being passed through other means). Google only gives me a hundred different variations of "use CustomError in your web.config to redirect to another page," but I don't want to do this. I also can't clear the Error through the PageError event or the ApplicationError event, because then I don't get the error info. Any ideas?

    naengwen on
  • Options
    xzzyxzzy Registered User regular
    edited January 2010
    Can you wrap the line that's causing the problem in a try/catch block?

    I know nothing about ASP, but that's the standard way of trapping errors. The other solution is to fix whatever's causing the error. ;)

    xzzy on
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited January 2010
    You do this
    try
    {
    //Code that causes the error
    }
    catch(ex ExceptionType)
    {
    //basically nothing
    }
    

    The ExceptionType depends on the type of error you are getting.

    Jasconius on
  • Options
    ImperfectImperfect Toronto, Ontario, CanadaRegistered User regular
    edited January 2010
    Oh good, the programming thread. I was wondering what subforum you'd gotten to. Listen, I gotta question to ask.

    I'm writing a 2d engine in XNA, and it's lookin' pretty good. I have an array of ground tiles that I can move back and forth around on, wall tiles on top of that, and eventually I'll have entities that can be drawn in and around THAT mess, too. Enough bragging through.

    The problem I'm running across is that of zooming. I mean, I figured out the basics of it - I can zoom in and out already using various scaling factors, but it looks... *odd*.

    See when you zoom in and out on a regular man, you zoom in towards the middle of the screen. When *I* zoom in and out in *my* code, it seems to zoom centered on the top-left corner. I've tried a number of things to correct this, but I'm at a loss.

    I'm sure this is some simple mathematical thing of which I'm just not aware, but it's bugging me. Can anyone point me in the general direction I need to look to fix this?

    Imperfect on
  • Options
    SeolSeol Registered User regular
    edited January 2010
    Note: My experience with transforms is in Java, but this should apply.

    Scales always happen around 0,0. To scale around a point, translate the origin to that point, then scale, then translate back. Note that if you're using matrices, it executes the transform last appended to the list first, so you need to compose the matrix by first applying the untranslate, then the scale, then the translate.

    Seol on
Sign In or Register to comment.