THESE FORUMS NOW CLOSED (read only)

Fun Stuff => CLIKC => Topic started by: ankhtahr on 13 Mar 2014, 11:43

Title: A programming thread!
Post by: ankhtahr on 13 Mar 2014, 11:43
So I'm surprised to see that we don't really have a programming thread. We do have one, but it's from 2006.

I've just started to read "Learn you some Erlang for great good", a Erlang-guide based on the relatively well known "Learn you a Haskell for great good". It's good!

So what obscure programming languages do you enjoy, what anecdotes do you have to tell?
Title: Re: A programming thread!
Post by: hedgie on 13 Mar 2014, 12:23
So I'm surprised to see that we don't really have a programming thread. We do have one, but it's from 2006.

I've just started to read "Learn you some Erlang for great good", a Erlang-guide based on the relatively well known "Learn you a Haskell for great good". It's good!

So what obscure programming languages do you enjoy, what anecdotes do you have to tell?
Alas, I don't seem to have much aptitude for programming aside from just enough Perl to keep my systems running properly.   Haskell certainly looks interesting, though.  I do remember taking a programming class (which I had to drop due to my aforementioned lack of skill in that area) in which another student actually took it upon himself to complete one assignment in brainfuck.  I left before I found out as to whether or not he was successful.
Title: Re: A programming thread!
Post by: Pilchard123 on 13 Mar 2014, 15:58
Oh no, this is going to turn into another pun war. It's going to SNOBOL out of control!
Title: Re: A programming thread!
Post by: cesium133 on 13 Mar 2014, 16:08
I use Fortran pretty regularly, though I'm not sure if that counts as obscure. It's still used a lot in physics.

As for esoteric languages, I think I've mentioned previously on the forum that I've written a subroutine call setup in Shakespeare. I went looking on my hard disk, though, and couldn't find it.
Title: Re: A programming thread!
Post by: ChaoSera on 14 Mar 2014, 03:44
The only language that might count as obscure and that I've used so far is mIRC Script.
At work i use almost exclusively Java, apart from the occasional bash or XSLT Script. Right now I have to debug a shitload of Tests, because it's QA Phase now. I hate QA. My own stuff that I developed for this version is already tested and functional, so now I have to spend my time gonig through all the general tests, which are partly old and use principles we have since abandoned, so I now have to partly rewrite them.
Title: Re: A programming thread!
Post by: pwhodges on 14 Mar 2014, 04:15
It's years since I did any real programming, though I did loads back in the day.  And my best anecdotes are already somewhere in the forum.

Starting at uni in 1967, I was writing Algol-60 and K-autocode; out of uni I had a temporary job doing image processing in assembler for the English Electric Leo Marconi KDF-9.  I also played with Algol-68.  My first proper programming job at a software house had me writing in Coral-66; then doing embedded programming with no assembler - just writing the instructions in hex (non-standard hex using B-G instead of A-F).  And even some Cobol.

In the late 1970s and early 1980s I was selling an entire OS and medical image processing suite that I had written - to the Japanese, even - that was written in a mix of Assembler (for a Varian mini), BCPL and Fortran (both compilers ported and heavily modified by me), with some microcode for efficiency (subroutine entry and exit instructions for the BCPL and Fortran; backprojection code for tomographic image reconstruction).

Then I did a lot of system programming for Norsk Data machines, both in their machine code and in their own language, Planc (this work included a comms package for use with ICL mainframes which became one of Norsk Data's products).  I also ported my BCPL and used it for some utilities that the service department used (image storage and writing for our software library, which came from head office on floppies; a binary editor, which I used to rebuild messed up file systems on corrupted floppies).

The last part of my full-time programming career was in embedded systems (though I'd done some similar work right back in the early 1970s).  These systems were all for use in pharmaceutical manufacturing.  The main control programs were written in Modula-2.  At this time I started to make heavy use of OS/2 (starting with v1.3, and going on right through to the non-IBM successor product eComStation).

For the last fifteen or so years I have been a systems administrator, so comparatively little programming, but quite a lot of hacking of existing scripts (Rexx on OS/2, Perl especially, largely for spam detection in email servers).  Also web stuff (HTML & CSS of course, with JSP, Python and PHP scripting).  Mostly Windows systems these days; but I also run an OpenBSD firewall, and have an outdated RedHat Linux support qualification.

The main thing I've not had any practical involvement with is object-oriented stuff - C++, Euclid, etc.  I know the principles, of course (in fact the seeds of it are visible in Algol-68), but my mind just doesn't go that way.
Title: Re: A programming thread!
Post by: ankhtahr on 15 Mar 2014, 03:04
I'm not sure whether it was Fortran or Cobol, but my grandfather told me of a problem he encountered at university. One program of his caused an error. The operators told him that the error was trying to calculate the square root of a negative number. He was very sure that there couldn't be any negative numbers at that point of the program. He had to manually calculate what the program did in every step to finally find out that the problem was that there was a difference between a positive and a negative zero. The error occured because of a negative zero. Once he transformed negative zeroes to positive zeroes at that moment it worked flawlessly.
Title: Re: A programming thread!
Post by: pwhodges on 15 Mar 2014, 03:58
Zero being signed was a characteristic of certain hardware, not the languages.  Specifically, machines that didn't use twos-complement but used a signed magnitude format - typically these would be machines that worked directly in decimal, to avoid issues with binary-decimal conversion.  A decent compiler would have dealt with this problem, but many compilers were (are, I guess) not decent.
Title: Re: A programming thread!
Post by: snalin on 19 Mar 2014, 18:26
So I've got a compulsory exercise set in my "Modelling of Computing" course. It's about turing machines and state machines and logic circuits and computability and that sort of stuff. The book used is this one (http://cs.brown.edu/people/jes/book/)

Now, one of the problems is this:
"Design in detail a TM that (bubble-)sorts any input word (http://latex.codecogs.com/png.latex?w&space;\epsilon&space;\{a,&space;b,&space;c\}^{*})"

So, sort any string consisting of a's, b's and c's alphabetically; "cba" to "abc". Pretty simple stuff.

Now, the thing is, writing Turing machines in the form of state transitions gets kinda... messy. I hit 30 transition functions and lost completely track of where I was at. So, I figured I'd do this the good old fashioned way: test driven development! Yeah!

Now, to actually test a Turing machine, I need to have an actual Turing machine implementation. So I did that. Because to solve a simple problem, first solve a harder problem. This is the mantra! So now I can write Turing machines through TDD by testing against the expected output tape state. Aw yeah. The machines I can build don't actually have explicit accepting halting states - ALL halting states are accepting. So if they're used for language recognition, they can give positive answers ("the input string is in the language") by halting, but not negative ones.

If you want to see the Java project for whatever reason, I put it up on github: https://github.com/BBuanes/TM. Not sure why, but hey!

If you'd rather just see the setup of the machine:
(click to show/hide)

TL;DR: Programming at a university miiiight just have driven me insane.
Title: Re: A programming thread!
Post by: ankhtahr on 22 Apr 2014, 17:18
Ok, so during this semester I'll have to do exercise sheets both in programming and in "software technology", which is basically software engineering classes. I'll have to pass the programming one, otherwise I won't be allowed to study computer science in Germany anymore. I should pass the SWT one too, because it would slow me down a lot if I wouldn't. So yeah, I'll have to do basic and advanced sheets at the same time, with my knowledge being stuck at about the half of the basic ones…

I'm still not too comfortable with object oriented programming. I enjoyed the small bit of C and the bigger bit of AVR assembler, so I probably have a slightly different viewpoint than most of my classmates. While they look down at the programming language from an abstract algorithm, I look up at the programming language from a system architecture point of view. Object oriented programming feels counterintuitive to me.

Anyway, I probably need to pick up an IDE now. I'd prefer just using vim, but that isn't much of an option with the SWT class. I'm going to need Maven, Checkstyle and Code Coverage using JaCoCo. The recommended IDE is Eclipse, with EclEMMA and a Maven and a Checkstyle plugin, but that crashed on me a few times. I've managed to reduce the crashes to a tolerable level, but it's still annoying. I've looked at Netbeans and promptly discarded it, and I looked at IntelliJ IDEA Community Edition and liked what I saw. It lacks the code coverage tools though, those are only available in the paid version. I could probably try to usi it anyway, trying to use JaCoCo manually through Maven or something, but would that really be a good idea? Any comments?
Title: Re: A programming thread!
Post by: snalin on 23 Apr 2014, 00:58
I've been using Eclipse for so long that IntelliJ throws my keybinds of completely. Other than that, they're pretty much the same - from what I've heard from people who work, IntelliJ paid edition is a big upgrade over Eclipse, while the free version is a sidegrade with far less cool (and uncool) available plugins. Eclipse is... a memory hog for sure, it can crash (though I haven't been through that recently), but it has that brilliant marketplace for free plugins right there in the editor. IntelliJ comes with built in support for some extra languages (like Groovy, which is really fucking groovy), but in my experience, adding additional languages to Eclipse works like a charm. I had Python with autocomplete, debugging and in-editor console running in minutes.

By the way, stay the away from Eclipse classic, as it's just bullshit. It's no faster, but has a ton of less features.

If you're using Eclipse with the Maven plugin (m2e), you'll want to know that you don't have to use the bogus maven gui they include, you just have to right click and open as text file. On the other hand, whenever you want to add something from a Maven repo to your project, there's a right click menu that allows you to search and add from all of the publicly available Maven stuff. Saves you a ton of trouble. Generally, whenever there's a problem with the interface, there's a setting. I'd seriously recommend looking into changing the theme for Eclipse too - I've got colored text on a black background, and it's the best.

No matter which one of them you use, you'll definitely want to get familiar with all of the re-factoring and code helping tools available. The university here doesn't really teach them, or their value. While the value of being able to rename a class, and have the class be renamed over all of your hirearchy has obvious value, there's things I see people just not using which they should be using, so here's a selection:

- autocomplete (shift+space on both Eclipse and IntelliJ) is the best thing in the world - remember when you had to look up APIs somewhere else? Not anymore! Also you'll be writing code ten times faster.
- Autocomplete also has built-in shortcuts for some common statements. If you write "syso", and click autocomplete, it'll automatically expand to System.out.println();, with your cursor in the parenthesis. For and simplified for loops are available through "for" and "foreach" respectively, and expand with the closest array or indexable object in yr loop. It's great.
- If you have a variable a of class A, and write a. before you go autocomplete, you'll get a list of all available methods and variables you can use with a - it'll even filter out the ones you can use where you are, so private members will only be shown if you're in A.
- autoformat is also super useful. It's highly configurable, and your code will always look great. It also helps you spot dangling if's and that kind of stuff immediately.
- Jump to last/next error (compilation problem) with ctrl+, and ctrl+. in Eclipse. Added or removed something from the signature of a method? Just jump around to the problems.
- Auto-fix problem is just, wow, much help, so best. Whenever your cursor is over a warning or error, ctrl+1 (Eclipse) gives you a menu that you can select fixes from. So, say you write MyClass implements MyInterface, where MyInterface defines some methods. You'll immediately get a compilation error, as MyClass needs to implement those methods. You ctrl+, to jump to the error on MyClass, ctrl+1 to get the menu, enter to select "add unimplemented methods", and BAM, you have each of the methods filled out.
- Further Eclipse - ctrl+shift+r is "open resource", which allows you to write in the name of any file in the hierarchy to jump to it. Ctrl+o is "go to method", which is the same, but for the class you're in.
- Generate getters, setters and constructors from variables are great tools. Generally, too many getters and setters is a sign that you're not quite into the OO way of thinking, but you'll want some. The constructor tool is amazing. Three button presses (alt+s, a, enter) gives you a constructor that sets all of the privates.
- Alt+arrow up or down moves a line of text up or down. If you do it with multiple lines selected, it moves all of those lines. Did you suddenly realize that this one line needs to be outside the if block? Well, you're in luck! Want to move this entire method higher up the document? You betcha.


Basically, get to know your IDE. Spend time getting those keybinds and features into your fingers. If you at any point think "this is a thing I do all the time that it should be possible to do automatically", the
feature probably already exists, somewhere. Hell, you can sort your methods alphabetically, if you want to.

With the OO stuff - if there's one thing I know in this world, it's OO programming. I'm not a straight up guru, but I'm still pretty decent at it, and I have some experience TAing both introductory and advanced programming courses in Java. If you want help with some exercise sheets, seriously send me a PM, and we can talk over Skype or something.
Title: Re: A programming thread!
Post by: smack that isaiah on 23 Apr 2014, 02:56
Most IDEs that I've come across have plugins to add vim keybindings for text editing.  I use the vim plugin in Visual Studio at work and in PyCharm for my personal python projects.  I would bet Eclipse has some sort of vim plugin, if you want to keep to your normal text editing feel in whichever IDE you choose.

It's been a while since I did Java work, but I remember BlueJ being a good introductory IDE for Java, if you want to look into that one, too.
Title: Re: A programming thread!
Post by: Dimmukane on 23 Apr 2014, 07:29
Ending my long period of lurking to chime in and say that JetBrains has some seriously useful IDEs if you're willing to pay for them.  I use both PyCharm and Rubymine (both 199$) and they're so much more useful than what I could do with Eclipse.  If you have the scratch to get them, they're definitely worth the purchase (and they come with I think a year's worth of software updates, with the option to extend the maintenance license for another 99$ a year).
Title: Re: A programming thread!
Post by: ev4n on 23 Apr 2014, 12:26
I hate eclipse.  It's so big and slow.

Most people here use notepad++.  Not an IDE, but fast.
Title: Re: A programming thread!
Post by: snalin on 23 Apr 2014, 13:45
It's fast at not doing anything else useful than writing text. You're shooting yourself in the foot, and slowing your progress considerably if you stick with a text editor.

Seriously, if I was hiring a Java developer, and asked them "what's your IDE of choice", and got a text editor as a reply, I'd show them the door. The amount of speed and utility you get from any IDE is just incredible when compared to plain text, and I'd know I would be getting a lot more and better work from somebody who knew how to use proper tools. Maybe I'd accepts a pretty heavily pimped Vim, but that's a stretch.

As far as I'm aware, most places you learn programming does not teach proper tool usage, and does not teach how to write good unit tests. Both of those are sorely lacking here in Norway, and from what you guys have written about your education in various places, it's not stuff that's being taught there. Those two are essential skills, and if you don't know them, you can be as good as you want at understanding and writing in your language of choice and still not be able to write good software.
Title: Re: A programming thread!
Post by: ankhtahr on 23 Apr 2014, 15:09
That's one of the basic parts of this lecture. Stuff like "How to and why version control", unit tests, tools like Maven and methods like XP and the waterfall model.

Admittedly, I frickin love my text editor. For smaller things, I prefer it over a bloated IDE, but Java is completely insane without one. The stuff I have to do in "Computer Organisation / Technical computer science II) I'll probably do using vim. Mostly assembler and basic C. But trying to do all the things I need in Software Technology with it would probably end with me going insane. I'm still not sure what to use, but I guess I'll try and use Eclipse, as all the guides from the lecture are abed on it, and I don't understand enough to use of the inner workings to use a different IDE, even though IntelliJ seems more to my liking than Eclipse. Also I can't afford the Ultimate edition, and I need Code Coverage for this lecture. It's 89€+VAT with a student license for something that might be more comfortable, but takes a lot of getting used to (to learn how to transfer the Eclipse processes to IntelliJ), while I don't earn money from it, and am not even sure if I want to. I'd rather do some work in C or another lower level language. Or maybe Erlang, but who the fuck uses Erlang in a business.

But still I'm tempted by it, because IntelliJ made such a great impression on me.
Title: Re: A programming thread!
Post by: smack that isaiah on 23 Apr 2014, 15:19
Snalin is definitely right that an IDE is a must in modern programming with larger projects.  In college I did all my C++ programming with vim, a command line, and makefiles (I only took two comp sci courses in college; my major was really busy and I couldn't fit in too many intensive extra courses.  The majority of my comp sci experience came from high school and personal projects).   I had used an IDE in high school, but that was on Windows and on my school's computers; I didn't know of any Linux IDEs and didn't bother getting any or looking into it much--I could do what I wanted with just these tools; all my projects tended to be small.

Then I got a job doing lots of computer science and started using Visual Studio.  Having an IDE is fantastic.  All the knowledge of functions, interfaces, and other libraries just at your fingertips is unimaginably helpful.  No more constantly having to Google for APIs or keep headers, tlbs, or dll exports open next to my main terminal.  I have since then investigated IDEs for Linux when I wanted to start doing Python work on my own at home, and PyCharm is truly amazing, as Dimmukane mentioned.  When I get around to sitting down and devoting more than just a few hours a week towards my personal projects I'll probably upgrade from the free version.

I do still love vim and do do text editing work in it, and I do look for vim key bindings in almost any program I use, but I wouldn't want to go back to programming in it alone.
Title: Re: A programming thread!
Post by: Dimmukane on 24 Apr 2014, 08:00
Or maybe Erlang, but who the fuck uses Erlang in a business.

Heh. Heheheheh.
Title: Re: A programming thread!
Post by: jwhouk on 24 Apr 2014, 08:48
A funny thing: while I was trying to conjure up a new keyboard for the wife's new laptop, I found my copy of the SMART Software System Mini-Manual. 400 pages (letter-size) in a binder of information about a database system that doesn't exist anymore.

EDIT: I take that back. SmartWare still exists. (http://www.smartware4.com/about_us.html)
Title: Re: A programming thread!
Post by: ev4n on 24 Apr 2014, 09:28
It's fast at not doing anything else useful than writing text. You're shooting yourself in the foot, and slowing your progress considerably if you stick with a text editor.

Seriously, if I was hiring a Java developer, and asked them "what's your IDE of choice", and got a text editor as a reply, I'd show them the door. The amount of speed and utility you get from any IDE is just incredible when compared to plain text, and I'd know I would be getting a lot more and better work from somebody who knew how to use proper tools

Good thing I'm about 10,000 miles from being a Java developer, eh?

There are plenty of embedded software environments where debugging is not available from an IDE (assuming inline debugging is even available at all), where makefiles are maintained manually, and where the speed and usability of your text editor is more important than its general purpose usefulness.

Different strokes for different folks.
Title: Re: A programming thread!
Post by: Masterpiece on 25 Apr 2014, 08:12
Today I'm being taught Python! And pygame, and this is the result of the first ten minutes:

(http://i.imgur.com/dGe5UMo.jpg)
Title: Re: A programming thread!
Post by: snalin on 25 Apr 2014, 11:47
Quickly, make a 2048 clone in PyGame with just your own selfies.
Title: Re: A programming thread!
Post by: Pilchard123 on 25 Apr 2014, 13:24
Dooooo eeeeeeeet!
Title: Re: A programming thread!
Post by: Schmee on 25 Apr 2014, 20:12
No! Only use one selfie. Make each tile a slightly more zoomed-in version of the previous tile. 2048 is just your eye, 4096 is your pupil.
Title: Re: A programming thread!
Post by: Masterpiece on 26 Apr 2014, 18:43
I really wanna do that now.
Title: Re: A programming thread!
Post by: ankhtahr on 27 Apr 2014, 18:10
Yeah, this is great already. I'm working on the first exercise sheet of SWT. They've got relatively detailed instructions (which are specific to Eclipse…), but I'm stuck at one point. This subtask is:
Quote
Make sure that calling "mvn package" puts the correct main class in the resulting Java manifest. Also set the two settings of the maven-jar-plugin "addDefaultImplementationEntries" and "addDefaultSpecificationEntries" to "true". (This causes the jar which is produced by maven to be executable)

I think I've got the first part covered (even though it was never explained what a manifest is…), but I can't manage to do the second. I'm trying to do it using Eclipse, but can't figure out how. The provided pom.xml doesn't contain anything about maven-jar-plugin, and I don't know how to change the default settings (there is an entry in the tab "effective POM" for this plugin).
Title: Re: A programming thread!
Post by: snalin on 28 Apr 2014, 02:39
First of all, the manifest is a setting for the maven packaging plugin, if you hadn't googl'd your way to that yet. So in the POM, there should be something like this:

Code: [Select]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.1</version>
        ...
        <configuration>
          <archive>
            <manifest>
              <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
              <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
              <addClasspath>true</addClasspath>
              <mainClass>mainPackage.MainClass</mainClass>
            </manifest>
          </archive>
        </configuration>
        ...
      </plugin>

If you don't have that, you can just cut and paste it in your POM, under the <plugins></plugins> section. If that's not there, just add it wherever under the top level (<project>). As I might have mentioned earlier, you'll want to right-click the POM and select "open with -> text editor", because the eclipse pom editor is confusing.

I'll admit that my knowledge of maven is based on trial and error in addition to some copy-pasting and intuition. But, I got it working, using the above settings, where mainclass points to the fully qualified path to your main class. Try it - cd to the root of your directory, and run mvn package. If you get "build successfull" after it's downloaded everything, go to the newly made target folder, and try to execute the jar in there.

The idea with the plugins is that they each follow their own xml schema for what keywords and stuff they use - I think. The quote you have from the subtask is full of bullshit, by the way - addDefaultImplementationEntries and addDefaultSpecificationEntries does NOT make the jar executable. What they do is that they add a bunch of extra information to the MANIFEST.MF file inside the jar, this link (http://maven.apache.org/shared/maven-archiver/examples/manifest.html) explains it. All you need to do to make the thing executable is to add a main class. If you haven't already, I recommend that you go dig around in the jar files maven generates, and look at all of the files in there.


If you can't get it to work, send me a PM and I can mail you an example project with a simple hello world.
Title: Re: A programming thread!
Post by: ankhtahr on 28 Apr 2014, 13:00
okay, so now I've been screaming at my notebook for half an hour. Fucking Eclipse.

Running mvn package on the console works great. Running it from Eclipse, with the .launch file we're supposed to use (I have no idea what they do, or what they are for) fails, with this error (http://www.slf4j.org/codes.html#StaticLoggerBinder). This launch file (which seems to be the only way I can somehow launch mvn package) only runs with the embedded maven, and I can't seem to convince it to run with the external maven.

I already remember, why I can't stand Eclipse. It's a complete mess. The user interface is extremely far from consistent.
Title: Re: A programming thread!
Post by: snalin on 28 Apr 2014, 15:34
Why are you running it from within Eclipse? Is that a requirement?

When I right click the POM and go "run as -> maven build" and select "package" as my goal, I get the same error as you (probably a m2e problem), but the jar packs just fine (BUILD SUCCESS, as maven puts it). I'm using the  1.4.1.something version of m2e, which is the standard you pick up from their install site, so if you just installed it, you should have the same thing.

Btw, the .launch file is apparently a launch configuration that's been packaged to a file. So it basically does the right click, run as, whatever for you. Why your uni thinks it's a good idea to give that to you instead of just having you package the thing on your own is beyond me. The problem seems to be more that your uni is trying to hold your hand and just help you do stuff, and in the process makes a huge mess of everything. "You need to deploy your project with maven" would have been a good way to give the assignment.

It's also really silly that running maven goals is done from right clicking the pom instead of say right clicking the project and selecting something from the "maven" menu.
Title: Re: A programming thread!
Post by: Masterpiece on 28 Apr 2014, 17:31
I'm teaching myself Haskell.

(http://i.imgur.com/Ie05t2d.png)

I could be better.
Title: Re: A programming thread!
Post by: Masterpiece on 28 Apr 2014, 17:32
Oh wait, I know what I did wrong!
Title: Re: A programming thread!
Post by: snalin on 28 Apr 2014, 18:12
Uuuuhrghr Haskell.

Apparently it's not that bad when you learn to write it properly, but I saw one to many "couldn't match the expected type '[[Bool]]' with actual type '[[[[Bool]]]]'" in my half-semester of being taught it. I might try it again. They've got a really great book (Learn You A Haskell For Great Good), and at least it's not fucking Lisp.
Title: Re: A programming thread!
Post by: ankhtahr on 28 Apr 2014, 21:16
snalin: try Erlang, to me it feels like Haskell with more real world usecases, and also I feel more comfortable with Erlang than with Haskell.

In other news, I somehow finished the tasks, and am now working on the other programming task (which is due on May 12th, but I wanted to start early).

It starts so fucking easy (It's the new iteration of the "basic programming" course of last semester for the people who didn't manage to get enough points on the exercise sheets), but it gets difficult so fast, that I almost assume they worded the exercise wrong:

Quote
Write the classes "Point", "Line", and "Triangle". A point is a two-dimensional "double" Vector, a line segment consists of two, a triangle of three points.

For the class "Point" a constructor, that creates a Point out of two "double" values. Also write constructors for the classes "Line" and "Triangle", which create a line segment or a Triangle out of two or three points respectively.

Write a method for the class "Line", which returns the point of intersection between itself and another given line segment, if it exists.

Write a constructor for "Triangle", which creates a triangle out of three line segments.

What do you need to change, if you transfer this into a three dimensional space? Which advantages do you now see in object oriented programming?

Classes: Check.
Constructors: Check.
Intersection between two line segments? Argh. The simplest solution I've found was this (http://ix.io/bZb/cpp) C++ code. Converting this to object oriented Java doesn't seem like such an easy task, if only because I need to write so much. Also I don't see how that should be easy to convert into three dimensions.
Title: Re: A programming thread!
Post by: Pilchard123 on 29 Apr 2014, 00:06
Uuuuhrghr Haskell.

Apparently it's not that bad when you learn to write it properly, but I saw one to many "couldn't match the expected type '[[Bool]]' with actual type '[[[[Bool]]]]'" in my half-semester of being taught it. I might try it again. They've got a really great book (Learn You A Haskell For Great Good), and at least it's not fucking Lisp.

A Russian spy is returning with information. "I was only able to copy the final part of the new American missile guidance  system, but I can tell you that it's written in Lisp."

"How do you know?" asks his handler.

"Well..."

Code: [Select]
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))()())))))))))))))))))))()))))))
)))))))))))))))))))))))))))))))))))))))))))))))())))))))))))))))))))))))))))))))))
)())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))()))))))))))))))))))
)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
Title: Re: A programming thread!
Post by: snalin on 29 Apr 2014, 04:46
Intersection between two line segments? Argh. The simplest solution I've found was this (http://ix.io/bZb/cpp) C++ code.

The person who wrote that needs to die in programmer hell. Seriously, don't write variable names like s, s1, s1_x. Also, you're allowed to use objects (or structs) and return objects in C++, there is no reason for not having that method read:

Code: [Select]
Point get_line_intersection(Line line1, Line line2)
instead of

Code: [Select]
char get_line_intersection(float p0_x, float p0_y, float p1_x, float p1_y, float p2_x, float p2_y, float p3_x, float p3_y, float *i_x, float *i_y)

EDIT6: Okay, that took a lot of tries, but the method pointed out in this (http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=geometry2) article actually works. You have to check that the point of intersection is on the line, but otherwise it's golden. I really need to start doing more geometry again!


EDITEDIT: REMEMBER! Eclipse has a generate hashCode/Equals function from "source -> generate hashCode() and equals()", in addition to a bunch of other generators. You should use the equals one - Eclipse will generate a better equals method than you ever could. The correct one for the triangle class is:

Code: [Select]
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Triangle other = (Triangle) obj;
if (p1 == null) {
if (other.p1 != null)
return false;
} else if (!p1.equals(other.p1))
return false;
if (p2 == null) {
if (other.p2 != null)
return false;
} else if (!p2.equals(other.p2))
return false;
if (p3 == null) {
if (other.p3 != null)
return false;
} else if (!p3.equals(other.p3))
return false;
return true;
}

Did you remember all of your null-checks? You didn't. I wouldn't have remembered them, that's for sure. Have them generated for you!
Title: Re: A programming thread!
Post by: Masterpiece on 29 Apr 2014, 05:22
Code: [Select]
char get_line_intersection(float p0_x, float p0_y, float p1_x, float p1_y, float p2_x, float p2_y, float p3_x, float p3_y, float *i_x, float *i_y)
Return char? Whut?
Title: Re: A programming thread!
Post by: snalin on 29 Apr 2014, 05:42
The person uses 0 for "they did not intersect" and 1 for "they did intersect". It's C code, basically. If whomever wrote it was actually writing C, it's fine, if they were writing C++, again, it's bullshit.

EDIT: to make it clear, C doesn't have built-in boolean values. It's low level, what-you-see-is-what-you-get, remember, so instead of wrapping 0 and 1 in a thing and calling it "boolean" or "bool", they just let you do that yourself.
Title: Re: A programming thread!
Post by: snalin on 29 Apr 2014, 05:50
No, it does find the intersection point, and puts it in the variables *i_x and *i_y. Sending in primitive variables for storage is something you kinda have to do in C, and can do but really, really shouldn't in C++, C# (out keyword) and some other languages. Java does the correct thing and disallows that completely.

By the way, accepting arbitrary sized variables for output storage was how the Heartbleed bug happened, as far as I can remember.

EDIT: Oh you sneaky Masterpiece, removing your post so it looks like I'm insane, talking to shadows.
Title: Re: A programming thread!
Post by: Masterpiece on 01 May 2014, 12:16
Sorry I just realized I was speaking nonsense, my mistake.
Title: Re: A programming thread!
Post by: ev4n on 01 May 2014, 13:13
My kid is asking to learn some programming again.  Really not sure where to steer them.
Title: Re: A programming thread!
Post by: Pilchard123 on 01 May 2014, 13:35
I like codeacademy, though I haven't been there for a while.
Title: Re: A programming thread!
Post by: ankhtahr on 01 May 2014, 16:23
Depends. I enjoy low level stuff, but I also really enjoy abstract stuff like Erlang. But somehow I can't seem to get the hang of the stuff in between.
Title: Re: A programming thread!
Post by: snalin on 01 May 2014, 17:33
My kid is asking to learn some programming again.  Really not sure where to steer them.

codeacademy is pretty cool. If your kid is kinda young, I'd rather go with what Khan Academy has on programming, which is very visual and instant-feedback. Check it out here (https://www.khanacademy.org/computing/cs)
Title: Re: A programming thread!
Post by: ankhtahr on 01 May 2014, 18:10
Uh, I kinda forgot to make a recommendation there. I would look into Arduino. There's loads of things that can be done with it, some projects being aimed at children, and there's something really cool about typing code, flashing it into an arduino, and seeing an LED blink because of it.
Title: Re: A programming thread!
Post by: ankhtahr on 03 May 2014, 05:09
I was considering putting this into the pointless thread, but it's only relevant for programmers, so I'll throw it in here:

Wat (https://www.destroyallsoftware.com/talks/wat)

Anyone who doesn't know this talk, watch it. It's great!
Title: Re: A programming thread!
Post by: Pilchard123 on 03 May 2014, 11:35
I'm sure I've seen that before, but I don't remember the content.
Title: Re: A programming thread!
Post by: hedgie on 04 May 2014, 09:11

Seriously, if I was hiring a Java developer, and asked them "what's your IDE of choice", and got a text editor as a reply, I'd show them the door. The amount of speed and utility you get from any IDE is just incredible when compared to plain text, and I'd know I would be getting a lot more and better work from somebody who knew how to use proper tools. Maybe I'd accepts a pretty heavily pimped Vim, but that's a stretch.
There's probably an emacs command for that.
Title: Re: A programming thread!
Post by: Masterpiece on 05 May 2014, 04:44
I'm still struggling with Haskell. We're supposed to write a recursive function called "proceed", which should increment the amount of days you specified on the day you gave the function. The code I wrote so far looks like this:

Code: [Select]
data Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
deriving (Enum, Eq, Show)

next :: Day -> Day
next Sun = Mon
next d = succ d


proceed :: Day -> Int -> Day
proceed x y | y == 1     = next x
            | otherwise  = proceed x (y-1)

The problem I'm having is that no matter what Int I give the proceed function, it will still give the 'next' value of the day entered. So, what I'm expecting to happen is this:
Code: [Select]
*Main> proceed Mon 9
Wed
and what's happening is this:
Code: [Select]
*Main> proceed Mon 9
Tue

This frustrates me.
Title: Re: A programming thread!
Post by: Masterpiece on 05 May 2014, 05:33
Fixed it. It made no sense to only call 'next' once. That was my mistake.

Code: [Select]
proceed :: Day -> Int -> Day
proceed x y | y > 0 = proceed (next x) (y-1)
            | y <= 0 = x
Title: Re: A programming thread!
Post by: dr. nervioso on 08 May 2014, 17:30
The only code i have extensive experience with is Python. I really like using it to do graphic design like stuff. It's a lot more fun than Photoshop.

Also, can anyone suggest a good way to learn Java? I have to learn at least some of the language in the next month so I will know what's going on in my next CS class
Title: Re: A programming thread!
Post by: snalin on 09 May 2014, 02:42
Write some stuff. It's kinda hard to get started without a specific task, but you should write some stuff. Make sure you're using Java 7, by the way. And also grab an IDE as discussed at length up-thread - Eclipse is fine.

Java is... pretty close to Python when it comes to capabilities and how you think about the language, so you're pretty far ahead already. Python allows you to do everything as a script rather than a proper object oriented language, so I guess it depends on how you've been using it.

There's stuff like codingbat (http://codingbat.com/java), but that gives problems that you could solve in the same way in any language - it doesn't really get into the java-specific stuff. Which is probably what you need.

Basically, you need to get on terms with what classes and objects are, and how they relate - this also means knowing static methods from non-static ones. Depending on how advanced the course is, you want to know how packages work, how private/default/protected/public access works (and maybe when to use them!), have a basic grip on what recursion is, know how interfaces works, how to implement interfaces, and finally how inheritance works.

If you want a texty overview, check out the docs (http://docs.oracle.com/javase/tutorial/java/http://docs.oracle.com/javase/tutorial/java/) at oracle. You could also look into getting the book for your CS course - that might have some proper exercises that allows you to work with the stuff I mentioned above.
Title: Re: A programming thread!
Post by: Masterpiece on 09 May 2014, 03:26
The Java Docs are great if you want to know how a certain library in Java works.
Title: Re: A programming thread!
Post by: snalin on 09 May 2014, 06:11
For introductory courses, you probably only need the Collections library and the Scanner class. If somebody tells you to use arrays and/or IOStreams, they're probably dumb and/or from the 80s.

(click to show/hide)
Title: Re: A programming thread!
Post by: danpaul88 on 09 May 2014, 07:14
Anyone here done any work with Java EE? I'm not looking to get too deep into the guts of it, my plan is to use it as the backend for a website in preference to something like PHP or ASP.NET (which is limited to Windows servers, I'm aiming to make this code OS agnostic to some extent) whilst avoiding any dependency on Java on the client machine.

Links to useful resources to get started would be appreciated, if you happen to have any lying around... or if you'd like to suggest an alternative I've perhaps not considered that'd be great too. There's not a lot of heavy lifting required (it'll mostly be reading and writing JSON, doing database manipulation and some heavy number crunching, hence why I decided against node.js). I'll also be running some code independently so it can update states without any client requests occurring, ideally in the same process as the one listening for web requests.

I have used Java a fair bit in the past for command line applications so I have a decent understanding of the language itself, it's more the EE part of it I'm looking to learn more about. Intending to use NetBeans as an IDE since I understand it's EE support is far better than that offered in Eclipse.
Title: Re: A programming thread!
Post by: snalin on 09 May 2014, 07:53
I have not touched EE, so I can't help you there. Though it doesn't really sound like you need it - JSON is just string parsing, and both database manipulation (JDBC) and number crunching is available in SE.

Other than that, EE is just a bunch of libraries that allows you to do advanced, heavy duty stuff. If you want big, multithreaded applications that talks with everything on the web and interfaces with a ton of things, EE is probably a given - but if you're doing low-key stuff, I dunno.
Title: Re: A programming thread!
Post by: danpaul88 on 09 May 2014, 09:05
Yeah, I'm mostly just using SE features but from what I've read it looks like the EE stuff can be leveraged to make a cleaner interface for accessing the Java code from a web server without some sort of intermediary between the two.
Title: Re: A programming thread!
Post by: Pilchard123 on 09 May 2014, 10:43
Netbeans is a good IDE as well, though that opinion might be coloured by it being the first one I used seriously.
Title: Re: A programming thread!
Post by: ankhtahr on 09 May 2014, 15:10
So I think I've managed this line segment intersection stuff. There's room for errors due to rounding errors, but I'm relatively sure I don't have to compensate for that.

I now have a different problem, more programming related. Anybody have a nicer way for doing what I have to do here?

l still have the same structure, so a point is an object with two double values for coordinates, a line is defined by two points, a triangle by three. I now have to write a constructor to create a triangle from three lines.

I'd now put all the points I have into an array, and for every element I'd have to check, whether it's equal to another element. If I don't get three matched pairs I can't make a triangle from it. But this doesn't really feel elegant to me…
Title: Re: A programming thread!
Post by: snalin on 09 May 2014, 15:48
It's not elegant, and it doesn't work - it allows stuff like three parallel lines. You'll need to test both that there are three matched pairs, and no element that matches more than one other element.

I'd just put the endpoints of the three lines in a list of some sort (or array if you wanna be old fashioned about it), and test that every element has two objects in the list that's equal to themselves - the other point and itself. Also, use object equality on the Points, don't manually check their x- and y-axis values in your triangle constructor.

Also, you probably know this, but a reminder to everybody that's starting up with Java - '.equals' is not the same as '==' , unless you forgot to write the equals method in which case it still only check for reference equality. So this code prints false:
Code: [Select]
ArrayList<Integer> list = new ArrayList<>();
ArrayList<Integer> list2 = new ArrayList<>();
list.add(5);
list2.add(5);
System.out.println(list == list2);

This is where you really, really, really want to start using unit tests in a proactive way - test driven development is the nice way. If you don't know JUnit, familiarize yourself with it. Write tests for triangles that should work, and triangles that shouldn't. Start with obvious examples, and continue with harder ones. It's not really necessary, but if you are familiar with the technique, everything in your life will be a lot easier. Trust me.
Title: Re: A programming thread!
Post by: ankhtahr on 09 May 2014, 15:57
JUnit tests and stuff like that are exactly what we're taught in the software engineering class.

Sadly we're not allowed to use lists, but I'll see what I can do with arrays.

And thanks for pointing out the parallel lines. I really didn't think of that.
Title: Re: A programming thread!
Post by: snalin on 09 May 2014, 16:35
Yeah, I solved it now, and I remembered one trick you might want to use:

import java.util.Arrays;

This is one of the most overlooked libraries in the standard Java library. It has the really, really, really useful static method Arrays.toString, which you can use to get a nice string representation of all arrays (for stuff like debugging). It also has a fill method and a copy method that does what you expect them to.

What it can do for you right now that's really nice, is the Arrays.sort method. It sorts arrays for you. So if you make an array of points, you can sort it using Arrays.sort, and then check that the first and second element are equal, that the third and fourth are equal, and the fifth and six are equal. Then you can pick the first, third and fifth elements to represent your triangle. Makes what you're doing a lot easier.

You have to have your points implement the comparable interface, otherwise you'll get a ClassCastException (as sort casts to Comparable when it sorts), but if you don't know how to do that yet, you should really learn how to do that asap, as implementing interfaces is mandatory when you do Java.

This still doesn't fix the parallel problem, so you'll have to do some more work to make that check. It'll just allow you to skip using loops when you check for equal corners, and also give the nice plus of having your triangle's corners sorted, which kinda probably should be a requirement anyways.

If you're not allowed to use any imports at all, tell your lecturers to go fuck themselves. Even not allowing Lists is edging close to the line of "not teaching Java", as you'd really never write Java without using lists. ArrayLists are Arrays with free contains() and indexOf() and other super-useful operations that you're going to be using on Arrays all of the time. There was a short period where Java devs that worked on Android went back to Arrays because they needed the speed on the old, slow droids, but now that smartphones are getting faster, that's probably not a worry anymore.
Title: Re: A programming thread!
Post by: jwhouk on 09 May 2014, 16:44
Code: [Select]
10 LET X = 0
20 PRINT "BASIC turns 50 this year."
30 LET X = X + 1
40 IF X = 50, THEN GOTO 60
50 GOTO 20
60 PRINT "I feel old. This was the first language I learned how to program."
70 END
Title: Re: A programming thread!
Post by: ankhtahr on 10 May 2014, 15:58
Damn the TA who conceived this exercise sheet. I've never seen tasks as underspecified. I don't know what to do, if it's not possible to create a triangle from these line segments. I think I've solved everything else. I just don't know what to return in that case. I'm considering just returning a triangle with the three points (0,0), (0,0) and (0,0).
Title: Re: A programming thread!
Post by: ChaoSera on 10 May 2014, 16:27
When in question about what to return, return null and specify that case in the javadoc comment.
Title: Re: A programming thread!
Post by: snalin on 10 May 2014, 17:01
Yes, oh God, never return an invalid object to indicate that the constructor fails.

Since it's a constructor, you can't return null either. The only correct way to handle a faulty constructor input is to throw an exception. Consider making a custom exception (like a GeometryException or something), and throw it if the input is faulty. Specify in the javadoc (under @throws) that this exception is thrown if the input is invalid:

Code: [Select]
/**
* Constructs a Triangle from three line segments
*
* @param l1
*            The first line segment
* @param l2
*            The second line segment
* @param l3
*            The third line segment
* @throws GeometryException
*             if the three lines does not represent a valid triangle
*/
public Triangle(Line l1, Line l2, Line l3) throws GeometryException {
            ...
        }


If you're not at the point where you're expected to throw and handle exceptions, simply refactor the code that checks the validity of the Triangle into a method that returns true if the lines gives a valid triangle, and assert that method:

Code: [Select]
public Triangle(Line l1, Line l2, Line l3) {
    assert isValidTriangle(l1,l2,l3);
    ...
}

Of course, asserts are a notoriously bad idea because they're not activated by standard in java, so if you forget to turn them on, code that should throw errors simply runs fine.
Title: Re: A programming thread!
Post by: snalin on 10 May 2014, 17:05
By the way, the reason for wanting the code to throw an exception is this: if the constructor is a part of a bigger application, and a faulty constructor call simply makes the code return an invalid object, the error (the faulty call) will cause an explosion - but not where it happened. Instead, the faulty object will propagate through the system, and cause seemingly completely unrelated errors somewhere else.

In this case, I can imagine a flaw in the code that constructs the Triangle causing a division-by-zero exception much further on in the program, where some other piece is trying to figure out the angles of the triangle. Or something like that. A very important software engineering principle is this: an exception should be thrown in the first place it is possible that it is thrown, as that will make finding out why it happened easier.
Title: Re: A programming thread!
Post by: ChaoSera on 11 May 2014, 03:47
Oh, I didn't see that the method in question was a constructor. In that case, yes, throw an exception. In all other cases, returning null is usually the way to handle faulty input. Just always remember to specify that in the javadoc. Because if you'd be working in a larger team and somebody else used the method you wrote, he knows he has to check the outcome for Nullpointers. (It always somewhat bugged me that in Java a "NullPointerException" is thrown in that case, java doesn't have pointers...)
Title: Re: A programming thread!
Post by: snalin on 11 May 2014, 04:23
Java does have pointers. In fact, it only has pointer. So a nullpointer is correct - you're trying to access a method or variable from a pointer, but that pointer points to null instead of an actual object.

You can see the pointer behavior in code like:

Code: [Select]
public static void main(String[] args) {
String s = "This is a pointer to a String";
change(s);
System.out.println(s); //prints "This is a pointer to a String
}

private static void change(String s) {
s = "This makes the local s variable point to a different String";
}

This is a pretty good article about how things work: Java is Pass-by-Value, Dammit! (http://javadude.com/articles/passbyvalue.htm)
Title: Re: A programming thread!
Post by: ankhtahr on 11 May 2014, 16:14
Seriously, thank you so much, Snalin, I feel like I've learnt more about Java from your help with this exercise sheet than from the lecture itself.

I'm finished with it now, and can now turn to the fun part of the exercise sheets which are due tomorrow. The technical computer science exercise sheet which is mostly C.

The more I do with Java and the more I do with C, the more I dislike the first and the more I like the latter.
Title: Re: A programming thread!
Post by: Masterpiece on 11 May 2014, 17:13
See, I think that is weird, because I liked Java, adore C# and always watch C with caution.

Why hate on higher programming languages?
Title: Re: A programming thread!
Post by: snalin on 11 May 2014, 17:21
Heartbleed wouldn't have happened had it been written in a higher level language!

No, each to their own. You get shit done in C as well, you just have the whole additional layer of complexity between raw values and data types that you kinda have to handle yourself. And segfaults exist. Oh lawd, the segfaults. "Yr code did something wrong somewhere, good fucking luck!"

These days I write more C# than Java, and I find the languages pretty comparable in how easy they're to use. There's no free C# IDE that's at the quality level of the free Java ones, but Visual Studio is supposed to be the shit, so I guess there's a trade off to consider there. Javadoc is vastly superior to the stupid xml scheme in C#, which is  why I still prefer Java, but that's only slightly.

I also have an irrational hatred for anything with the Lisp-syntax and anything purely functional just doesn't seem worth the hassle.
Title: Re: A programming thread!
Post by: ankhtahr on 11 May 2014, 23:07
I don't know why, but to me C is a lot more intuitive than Java. I tell the computer what to do, it does what I tell it to do, and if it does something wrong, then I can be relatively sure that I made a mistake somewhere.

I think I prefer C over Java simply because I have my most experience with Assembler (AVR Assembler, but still), so I like to be able to project my code into stuff the CPU could do, or the memory. That's not at all possible with Java, it's too abstract.

But I somehow like both extremes, as I'm also a great fan of the functional Erlang.

Anyway, I'm finished with my C exercise sheets, and will go hand them in now, and then I'll go to sleep. It's 8 am. And then I should do the exercise sheet for software engineering! Yay! More Java!
Title: Re: A programming thread!
Post by: ev4n on 12 May 2014, 08:03
Heartbleed wouldn't have happened had it been written in a higher level language!

I'm always leery of statements like this.  I know what you're saying, but compilers and OSs have bugs too...

I don't know why, but to me C is a lot more intuitive than Java. I tell the computer what to do, it does what I tell it to do, and if it does something wrong, then I can be relatively sure that I made a mistake somewhere.

Which, as snalin rightly points out, is fine when you have 12 lines of code you wrote running independently.  A system of 100,000 lines of C code written by 3 organizations and couple of dozen developers?  Have fun....
Title: Re: A programming thread!
Post by: ankhtahr on 15 May 2014, 11:01
uh. Now this i a slightly more challenging task. It's for the algorithms lecture. I need to implement a LRU Cache in Java, by combining a doubly linked list with a hash table. For maximum points I need to implement the list and the hash table myself, without relying on java.util.HashMap or any list class. I've got a few files (http://algo2.iti.kit.edu/documents/algo1-2014/LRUCacheFiles.zip) where I have to fit it in. I have to put it into the LRUCache class.
Title: Re: A programming thread!
Post by: snalin on 15 May 2014, 12:05
Quote
Ihr code hier
machen Sie das schneller

I love how they use the formal pronouns when addressing you. We barbaric Norwegians stopped doing that sometime around the 1960s. They insist on writing the Javadoc in German (they do the same thing here), which makes it a tad bit harder for me to get you some hints, but I'll give it a god*.

Doubly linked lists are pretty easy - you need a class DoublyLinkedList, and a (possibly inner) class DoublyLinkedListNode. The head should always have a previous value of null, and the tail should always have a next value of null. That's the java way of doing it.

Code: [Select]
public class DoublyLinkedList<DataType> {

MyLinkedListNode<DataType> head;
MyLinkedListNode<DataType> tail;
}

public class DoublyLinkedListNode<DataType> {
DataType data;
MyLinkedListNode<DataType> previous;
MyLinkedListNode<DataType> next;
}

Then the insertFirst method in the DoublyLinkedList would be:

Code: [Select]
public void insertFirst(DataType data) {
DoublyLinkedListNode<DataType> node = new DoublyLinkedListNode<DataType>(data);
head.setPrevious(node);
head = node;
}

And so on.

The hash table is also really straight forward - it's a map from an int to a resizable list of some kind, and you use the hashCode of the element you insert as the key of the map. The map can be implemented as an array, where you use the index of the array as the key.

This means that you have an array of lists (for example your doubly linked ones):

map = DoublyLinkedList[]

And inserting an element o means inserting into the array at index o.hashCode:

Code: [Select]
public void insert(DataType data) {
    map[data.hashCode].addFirst(data);
}

Check that the map has that index. If it doesn't (IE. it's too small), you can make an array of double the size of the old one, and transfer all of the elements. Insertion is still an O(1) operation, if you look at the average insertion time (I'll save the proof for when you get it on an exercise sheet in some Data Structures or Algorithms course :p). You could also just use ArrayLists:

map = ArrayList<DoublyLinkedList>();

The way the built in ArrayList inserts elements is exactly the algorithm I just described. To do the LRU (if I've understood what the LRU is), simply removeLast on the LinkedList at the array space you're inserting in if it's got more than the max number of elements. Also, you shouldn't fill the array space with a list before you need that list, so the insert method will also need to check if the index of the array is currently null.

Hope that helps.

* When I found that typo, I realized that it needed to stay, because giving you a God is a pretty cool thing to do, I recon.
Title: Re: A programming thread!
Post by: ankhtahr on 15 May 2014, 12:38
It actually is a Algorithms and Data Structures lecture…

The exercise is number four on this (http://algo2.iti.kit.edu/documents/algo1-2014/uebung_04.pdf) exercise sheet.
I've tried to translate the given task as good as I can here: (refer to the PDF for the picture)

Quote
In computer science results of a time-wise expensive operation are often saved to be able to access them faster later on. Such an expensive operation is for example loading of data from the hard drive to the RAM, or the rendering of downloading of map tiles on a GPS. A data structure which allows this is called "cache". Usually the memory in which the data is to be buffered is too small to back up all requests. In this case some entries need to be removed. Which those are is decided by an eviction strategy.
One of the most common stategies is "Least Recently Used (LRU)", where the entry which hasn't been read for the longest time is deleted. To find this entry one can, instead of using timestamps, combine a doubly linked list with a hash table in an elegant way. The following picture shows the schematical setup of this data structure:
<picture here>
Your task is to implement this in Java. Your data structure should implement a method ValueType retrieve(KeyType key) in O(1), which returns the value to a given key. The hashtable contains all cached elements. The doubly linked list displays the age of these elements. A retrieve first checks whether an entry is already cached, using the hashtable. If this is the case, it needs to be removed from it's current position in the list and moved to the front. Else it needs to be read from the background container (expensive!) and inserted into hashtable and chained list. To solve this task use the following data, which can be retrieved from the lecture website:
ContainerInterface.java: An interface for the underlying operations.
SlowRam.java: An example container which implements this interface.
PagerInterface.java: An interface for the Cache.
Pager.java: An abstract class which implements this interface.
LRUCacheTest.java: A JUnit-class which you can use for testing your class. It's also the task your handed in solution will be pre-checked.

Create a Java Class LRUCache in a file named "LRUCache.java". Your class needs to extend Pager. Only upload this single file. You'll receive one point, if you hand in a non-trivial solution, which passes the JUnit test. You'll receive additional three points if you implement the described structure correctly. You'll then receive four additional points if you implement the hashtable and the chained list yourself, so using neither java.util.HashMap nor a list class.
Hint: Questions like this are often being asked in job interviews.

I'd probably want to implement it using java.util.HashMap first, and implement it afterwards.
Title: Re: A programming thread!
Post by: ankhtahr on 15 May 2014, 17:32
I'd probably want to implement it using java.util.HashMap first, and implement it afterwards.

Done.

All I need to do now is implement my own HashMap, which behaves like the java.util one, at least in regards to the put, get, remove and containsKey method.
Title: Re: A programming thread!
Post by: ankhtahr on 15 May 2014, 20:49
Motherfucking Java.

I need an array. Of elements of my self defined list. What do I need to do? Of course:
Code: (java) [Select]
DoublyLinkedListElement[] table = (DoublyLinkedListElement[]) new Object[11] with a damn @suppressWarnings("unchecked") beforehand. Because Java.

Sadly the system we use to hand in our solutions denies your solution anyway. We've been trying to fuck our way around this fucking language barrier for two hours now. It's 5:49 am. I need some sleep. Also I need to hand it in until noon. But as I have a partner, who has done basically the rest of the exercise sheet, I feel obliged to finish this. I guess I'll stay here until he appears and tells me to go home.
Title: Re: A programming thread!
Post by: pwhodges on 16 May 2014, 00:13
I'm amused at all this Java shenanigans. When I had to write a cache of this sort (commercially, for money), I sketched it out in pseudocode and then implemented it in assembly language. As I recall it took about 300 bytes. The improvement in OS performance was similar to installing a SSD in modern terms.
Title: Re: A programming thread!
Post by: Masterpiece on 16 May 2014, 00:18
Code: (java) [Select]
DoublyLinkedListElement[] table = (DoublyLinkedListElement[]) new Object[11]
I'm guessing you haven't had generics yet.

Title: Re: A programming thread!
Post by: ankhtahr on 16 May 2014, 01:15
I had to resort to this, because I was getting a "cannot create a generic array".

In the end I gave up, because I finally need some sleep. I've been up for 27 hours now, and can't think straight.

Now the next upcoming exercise sheet is technical computer science, and that is the only lecture I seriously enjoy. Currently we're looking at a theoretical processor designed by our professor. This week our tasks are mostly implementing assembly-commands in micro operations. I enjoy this!
Title: Re: A programming thread!
Post by: snalin on 16 May 2014, 04:00
I had to resort to this, because I was getting a "cannot create a generic array".

Yup!

So, a generic is just a placeholder for a class that will be supplied later. This is implemented in Java (and C#) through type erasure - the type of the element will only be checked during compile time, and at runtime, no information about the class will be available.

The way to solve the problem is to use an ArrayList, as that will handle type checking for you.


I'm amused at all this Java shenanigans. When I had to write a cache of this sort (commercially, for money), I sketched it out in pseudocode and then implemented it in assembly language. As I recall it took about 300 bytes. The improvement in OS performance was similar to installing a SSD in modern terms.

Those were the days, huh? 300 bytes of of code is ~350 ASCII characters. That's not a lot of code.
Title: Re: A programming thread!
Post by: Schwungrad on 18 May 2014, 13:12
This is a pretty good article about how things work: Java is Pass-by-Value, Dammit! (http://javadude.com/articles/passbyvalue.htm)
Urgs. Thanks for reminding me why I prefer C++ over Java.
Title: Re: A programming thread!
Post by: cesium133 on 18 May 2014, 13:30
Complaint: why, when compiling a program, do the libraries that need to be linked go after the file that requires them in the command line rather than before? I always think of them as prerequisites for the program, so when writing the command line I always end up putting them before and getting frustrated when it refuses to work...  :psyduck:
Title: Re: A programming thread!
Post by: snalin on 18 May 2014, 13:47
In Java it would be:

javac -cp [stuff to put on class path like .jar or .class files] [.java source files]

So then it's before the sources. Or you could just set PATH temporarily.

In C++ (gcc), on the other hand, options are after the sources. I think. So then it's the other way around. So the answer to your question is language-dependent.
Title: Re: A programming thread!
Post by: cesium133 on 18 May 2014, 13:52
I'm using Fortran, and the syntax I always end up typing in is:

gfortran -lblas -llapack arss.f

when it should be

gfortran arss.f -lblas -llapack

I suppose I should get unlazy and make a proper makefile for the program (I was given just the Fortran source for it).
Title: Re: A programming thread!
Post by: Schwungrad on 18 May 2014, 14:26
In C++ (gcc), on the other hand, options are after the sources. I think. So then it's the other way around. So the answer to your question is language-dependent.
http://linux.die.net/man/1/gcc says the options come before the input file(s). Same should go for gfortran. :?

However, dynamic linking works just the other way round: The compiler makes your source file into an object file that just contains the instruction "put args on the stack and call libraryfunction(args)". Then, in a second step, the linker makes the object file (or several object files) into an executable by adding the information that libraryfunction(args) is found in the file library.so (on Linux) or library.dll (on Windows) at address 0x00abcdef. At least that's how I think it works. So when you do linking and compiling in two different steps, you have to specify the libraries in the second step.
Title: Re: A programming thread!
Post by: cesium133 on 18 May 2014, 14:30
My problem was I was doing the compiling and linking as one command (rather than doing one command to build the object file then another to link it), and when doing it as one command gfortran expects the libraries to be after the source file that requires them.
Title: Re: A programming thread!
Post by: Schwungrad on 18 May 2014, 15:18
That's odd. Judging from the manpage and from my own experience with gcc, putting the -llib options before the input file should also be the syntax for one-step compilation/linking. Not because the libraries are a prerequisite to linking, but because the invocation syntax demands all options being put before the input files.

Just out of curiosity, though it shouldn't make a difference: are you doing this on Windows?
Title: Re: A programming thread!
Post by: cesium133 on 18 May 2014, 15:21
Yes, and I'm using Cygwin.
Title: Re: A programming thread!
Post by: Schwungrad on 18 May 2014, 16:24
OK, I just learnt that -l options are indeed supposed to go after the object files where they're referenced, though some linkers might not care (but cygwin-gfortran seems to care). Explained here: http://www.network-theory.co.uk/docs/gccintro/gccintro_18.html
Title: Re: A programming thread!
Post by: cesium133 on 23 May 2014, 13:20
Now I'm apparently running into a bug in gfortran that according to the bug tracker (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=20257) was fixed in 2006. Apparently the maximum record length is 10000, and I'm trying to output a record length of 25000. The bugfix is supposed to raise the limit to 1 GB, and there's no way I'm exceeding that...  :psyduck:

edit -- D'oh! The OPEN command was overriding the system default and setting the maximum record length to 10000...
Title: Re: A programming thread!
Post by: ankhtahr on 25 May 2014, 13:20
So I'm supposed to write a program for a theoretical architecture our lecturer has developed, called MiMa (minimal machine), which sorts an array of numbers. I feel tired, and don't feel like optimising anything here. The task didn't specify that it's supposed to be efficient, so I'm implementing bubblesort. And not even in a very effective way. But well, it should work. And this architecture is far from effective anyway. It's an extremely inefficient CISC architecture with less instructions than AVR. I want AVR back. That was great.

Here's (https://github.com/cbdevnet/mima/blob/master/mimasm/MIMA-ASSEMBLER.txt) a bit of documentation about the MiMa, written by a friend of mine (who has written the MiMa assembler mimasm and the MiMa simulator mimasim)
Title: Re: A programming thread!
Post by: ankhtahr on 26 May 2014, 15:04
Have I ever told you how much I despise UML?  :-(

Once again it's midnight, and I didn't even get to the programming part of the exercise sheet yet.
Title: Re: A programming thread!
Post by: snalin on 26 May 2014, 16:25
Oh lawd, UML.

I TA'd a course that was... I'd say 50% UML, 50% actual software development. It was a real power trip to make the students sweat over bad diagrams, but I really, really see why they didn't want to put much effort into it. Knowing the basics of how to draw class diagrams on a whiteboard is a great way to communicate what you want, and I guess that if you start making complicated structures and can't really keep the overview, some informal UML can be great to express the important parts of the system. You need to be able to draw how classes interact in a pseudo-standard way, so I like that.

But the fucking standard is just such unhelpful pile of shit that I can't even begin to describe it. Software is an ever evolving beast, and diagrams just doesn't have the agility to keep up, and you keep getting stuck and having to go back to keep them in order. UML exists to help you with developing software, but that scenario is just not helpful at all.
Title: Re: A programming thread!
Post by: cesium133 on 26 May 2014, 16:33
Oh God, UML.

I just had a bad flashback to college, before I dropped my CS major.
Title: Re: A programming thread!
Post by: celticgeek on 26 May 2014, 16:37
But the fucking standard is just such unhelpful pile of shit

You are being FAR TOO KIND to UML.
Title: Re: A programming thread!
Post by: ankhtahr on 26 May 2014, 17:31
Yeah, this exercise sheet has four tasks which are basically "Here you have a text, make a UML Diagram from it". The texts are extremely underspecified, and as I'm a perfectionist and want to do things the right way it just stops me from getting anywhere with these tasks. So far I finished one of these four. Sidenote: the four tasks give 5 points each, and the programming task, which will take me a few hours as well, gives 13 points…

And as I didn't get too many points in the last exercise sheet I need those points…

(the last exercise sheet had UML too, and my diagram had far too few classes for these object orientation extremists. Apparently they believe that the more classes you have, the better it is. I had about four. They wanted eleven.)
Title: Re: A programming thread!
Post by: Masterpiece on 04 Jun 2014, 09:54
So.
I'm learing JavaFX.
I'm writing a UI with two labels whose CSS text-fill attribute I want to turn from grey to white when I hover over them with a mouse.
It's basically album title and song title for a music player I'm writing.
They are on a black background, and I want them to be grey when unneeded, so the album cover in the middle pops more.
And when I mouse over the info, I want them to turn white, so you can see them better.

At first, I tried using the :hover modifier class in my CSS, but quickly noticed that that would only work on one label, not both at the same time.
So I removed the :hover property, and added a style in runtime during every "mouseEntered" and "mouseExited" event.
Then I wanted transitions between the two states.
I wanted to use Keyframe animation, since I'm used to keyframing from AfterEffects.
I thought I could bind a SimpleStringProperty to the StyleProperties of the labels and wrote the style attributes into the SimpleStringProperty.
That wouldn't create transitions though, it would just blip from one state to another at the relevant keyframe.

I was getting annoyed.
SO. Instead, I didn't change the SimpleStringProperty value during the keyframe animation, but I changed a SimpleObjectProperty<Color> object.
I added a change listener to that Object, that fired a method that would change the SimpleStringProperty which contained my styling.
The styling was still bound to the StyleProperty of the labels.
EUREKA! Working transitions.

...that broke if I fired them again before the previous animation finished.
Since I had a "fadeIn" and a "fadeOut" animation, firing the fadeIn before the fadeOut ended broke fadeIn and vice versa.
So I wrote a while-loop that waited for the fadeIn animation to finish before fadeOut could play.
That created a while-loop that would never finish, freezing the application.

The Timeline-Animation API revealed that the animations had a "setDelay", a "getCycleDuration" and a "getCurrentTime" -method.
Through these, I could see how much time was remaining in one animation, and could set that as the animation delay on the other.
FadeOut would now wait until fadeIn was finished.
That made sense, since fadeOut would wait five seconds and then turn the labels gray again.
FadeIn should work instantly, so I told it to stop whatever fadeOut was doing and play fadeIn immediately.

...and now it works! Yay!

This is how I program, everybody!
Title: Re: A programming thread!
Post by: Sorflakne on 06 Jun 2014, 16:08
This post technically isn't programming-related, but it relates to program testing :P

So I set up a Filezilla server and client on my computer to test php with, but after loading up the necessary files, to include a html, php, css and jpg, to the client directory, I open the html file up, and it's just a raw webpage; the css rules aren't being applied and the image is a broken link.  When I enter some data and tell it to run (it's basically an email form), I get taken to a 'server not found' page.  Php is installed for the browser and all the files are in the same directory, but not sure what I'm missing when trying to open it from Filezilla.
Title: Re: A programming thread!
Post by: Pilchard123 on 07 Jun 2014, 01:51
Have you installed a webserver and PHP interpreter?
Title: Re: A programming thread!
Post by: pwhodges on 07 Jun 2014, 05:22
Php is installed for the browser

Um, php is a server-side technology.  You need a web server to handle it, not a file server like FileZilla.
Title: Re: A programming thread!
Post by: hedgie on 07 Jun 2014, 07:17
It's been a couple of years since I've touched PHP, but isn't it just easy enough to install a LAMP stack on a stripped-down linux install in a VM?
Title: Re: A programming thread!
Post by: Pilchard123 on 07 Jun 2014, 07:34
It's easy enough to install it on Windows, as well. Only without the Linux bit and with a few language changes too.
Title: Re: A programming thread!
Post by: cesium133 on 07 Jun 2014, 07:48
WampServer (http://www.wampserver.com/en/)
Title: Re: A programming thread!
Post by: Pilchard123 on 07 Jun 2014, 07:53
XAMPP (https://www.apachefriends.org/index.html)
Title: Re: A programming thread!
Post by: hedgie on 07 Jun 2014, 17:13
It's easy enough to install it on Windows, as well. Only without the Linux bit and with a few language changes too.
For a test environment, I could see using Windows.  But I never would think of using it for a production environment.  The only thing I can think of using a Windows server for is Exchange.
Title: Re: A programming thread!
Post by: pwhodges on 08 Jun 2014, 00:01
For a test environment, I could see using Windows.   But I never would think of using it for a production environment.

There's nothing like a good set of blinkers! (I run Apache, Tomcat, PostgreSQL, etc on Windows at work, and the same plus Deluge and Kerio Connect at home.  But I use Open BSD for firewalls).

Quote
The only thing I can think of using a Windows server for is Exchange.

I hate Exchange with a passion, though I've been running it for 15 years; it's just that for the user Exchange plus Outlook is still unrivalled by any alternative.
Title: Re: A programming thread!
Post by: ankhtahr on 08 Jun 2014, 12:13
Huh. The programming task for this week is actually a lot more complex than I expected.

Our task is to model the game Battleships. Given are a ShipType and a Direction enum. We've got a number of methods to implement, and at first I thought it would be a relatively easy task. But the more I look into it, the more modelling decisions I need to make. So far I've got an FieldType[][], which is basically the field, and gets initialised with water in every element. (the size is a parameter of the constructor and can't be changed afterwards, as specified in the task)

Now I'm working on the demanded "addShip" method. I guess it'd be the right decision to create a Ship class, and make every ship an instance of it, so I know, which fields belong to which ship and don't have to iterate over the whole array to find out whether there are still ships left. I'm thinking about saving direction and starting point of each ship (which are the parameters given to the addShip method), so every ship knows, which fields in the array belong to it.

Any better ideas?

yeah, and I need to be finished with this task tomorrow at 13:00.

Edit: and once again I'm not allowed to use anything but Java.lang
Title: Re: A programming thread!
Post by: ankhtahr on 08 Jun 2014, 14:22
argh. Accessing multidimensional object arrays without making them public sucks. Especially if you can't use java.util.

Array.copyOf and things like that could be useful here, but I have to do everything by hand.

Maybe I'll even do a setVerticalLine/getVerticalLine and setHorizontalLine/getHorizontalLine…
Title: Re: A programming thread!
Post by: Masterpiece on 08 Jun 2014, 14:25
Why can't you iterate over the array? It only has 10x10 fields anyway.

If you do it the other way around, you'd have to iterate over the list of boats, which would have to iterate over the fields they occupy, which just seems more, well, cumbersome.

Do you have to make a visual representation of the field? In that case I guess you could do the boat thing. In any other case, I guess it would be irrelevant to the code if the field you hit was a cruiser or an airship.

Beware that I'm only musing and am not a reliable reference.

If you do need to know which ship you're using, how about using a Map? In this case, I would create a Point -> Ship kind of map, aka, you input a point (for example, 4,6) and it either returns the reference to the ship that occupies that point, or a Null reference (as a stand-in for water). Then you can do fancy things like check if the ship is still alive after that shot, and removing that ship from the list of alive ships (which may be valuable if you want to check for a game-ended condition).

If you have any questions to my line of thinking, please ask. I'm not sure I know how I'd implement it in detail, but I'd love to work it out together with you. What are the methods you have to implement? What are their parameters, and their return values (and throws declarations, while we're at it).

If you want to, I can go online and we can have a chat on mumble. I love practical programming exercises like these.
Title: Re: A programming thread!
Post by: Masterpiece on 08 Jun 2014, 14:27
Hmm. I didn't read that part about only being allowed access to java.lang libraries. Which ones do they entail?
Title: Re: A programming thread!
Post by: Masterpiece on 08 Jun 2014, 14:28
By the way, if you really want to chat, send me a pm as i'll react to that quicker than to a forum post.
Title: Re: A programming thread!
Post by: ankhtahr on 08 Jun 2014, 14:44
At first: Thanks!

java.lang (http://docs.oracle.com/javase/7/docs/api/java/lang/package-summary.html)

What I'm worried about is, that the tutors correcting these tasks value modelling above everything.

I need to implement two toString methods, creating the opponents and the players view. In the players view I need to differentiate between the different types of ships.

Here's an example output (toStringWithShips() on the top, toStringWithBombs() on the bottom. Their names, not mine.):
Code: [Select]
.1.......
.....2...
..3..2...
..3......
4.3.4444.
4....1...
4......22
4........
.........
..1.333..


......XO..
..X.......
......O...
.O.O......
..........
.......O..
...O......
.......O..
..X.......

And as this is supposed to work for any field sizes and any number of ships, and there are always less ships than fields, I thought it a good idea to iterate over the ships only.

The way I'm currently working on it is that every ship is an object, I have an array of ships, and every ship has a getter which tells me, whether it's sunk or not (by checking every field it's placed on, an information I can get by saving the end point, direction and ship type with every ship).

What I'm currently struggling with is changing the type of the fields the ship is placed on in the constructor, as the field is private in the "Sea" class.

And I actually just now remembered how arrays work in Java, and now things got a little bit more complicated.
Title: Re: A programming thread!
Post by: Masterpiece on 08 Jun 2014, 15:08
Not being allowed to use util is MEAN. I'm afraid I can't help much here.

Wait, what's the sea class?
Title: Re: A programming thread!
Post by: ankhtahr on 08 Jun 2014, 15:12
the class which is actually my task to write. It's supposed to model the field and the rules of the game.

Here's the whole task if anybody's interested. I don't feel like translating it this time…

(click to show/hide)
Title: Re: A programming thread!
Post by: Masterpiece on 08 Jun 2014, 15:14
Oh man I'm reading through the Map-API and IT WOULD HAVE WORKED SO WELL HERE.
Title: Re: A programming thread!
Post by: Masterpiece on 08 Jun 2014, 15:24
Oh but that is easy! If the access to the actual array is private, just write a public 'setCell' method. This could look like this:

(I am assuming an int array as a datastructure)

Code: [Select]
private int[][] field;

...

public void setCell(int x, int y, int state) throws IndexOutOfBoundsException{

     this.field[x][y] = state;

}

The Index out of Bounds exception is just for debug, if you falsely input a higher index into the array than it has indices.

You could also give the setCell method different parameters:

Code: [Select]
private int[][] field;

...

public void setCell(int x, int y, Ship ship) throws IndexOutOfBoundsException{

     this.field[x][y] = ship.toString();

}

Everything's possible!
Title: Re: A programming thread!
Post by: ankhtahr on 08 Jun 2014, 15:28
In addition to this I have now created a getter and setter which set an entire row. Makes some things easier, and I don't have to write that iteration multiple times.

Also I added the task in my previous message.

Edit:

seriously, not using java.util makes anything ridiculous:
Code: (java) [Select]
Ship[] afterAdd = new Ship[this.shipCount + 1];
for (int i = 0; i < this.shipCount; i++) {
    afterAdd[i] = this.ships[i];
}
afterAdd[this.shipCount + 1] = new Ship(type, dir, x, y, this);
this.ships = afterAdd;
Title: Re: A programming thread!
Post by: Masterpiece on 08 Jun 2014, 15:42
can you tell me how ShipType and Direction look like? I'm writing a solution for your task, it's not that difficult.

edit: Nevermind, I wrote them on my own.

second edit: It would be so great if you could modify the shiptype enum.
Title: Re: A programming thread!
Post by: ankhtahr on 08 Jun 2014, 15:46
You could find them here (http://baldur.iti.kit.edu/programmieren/index.php?cat=assignments) together with the original task PDF and the checkstyle xml.
Title: Re: A programming thread!
Post by: Masterpiece on 08 Jun 2014, 15:52
ugh I hate the way they wrote the shiptype enum

I mean, it does what it has to, but so sloppily. You could write the same class like this:

Code: [Select]
enum ShipType{
MINENSUCHER(1),
SCHLACHTSCHIFF(2),
GROSSKAMPSCHIFF(3),
FLUGZEUGTRAEGER(4);

public final int length;

private ShipType(int length){
this.length = length;
}

public int getLength(){
return this.length;
}
}

which has a lot less redundant code.
Title: Re: A programming thread!
Post by: Masterpiece on 08 Jun 2014, 16:50
There you go! I haven't checked if it's 100% correct, but if you're struck this should give you a good starting point. Have fun!

Code: [Select]
package battleship;

public class Sea {

/**
* A representation of the ships in the coordinate field.
*/
private int[][] shipField;
/**
* A representation of the bomb-runs in the coordinate field.
*/
private String[][] bombField;
/**
* The width of the coordinate field.
*/
private int width;
/**
* The height of the coordinate field.
*/
private int height;

public Sea(int width, int height){

this.width = width;
this.height = height;

this.shipField = new int[width][height];
this.bombField = new String[width][height];

for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
this.shipField[x][y] = 0;
this.bombField[x][y] = null;
}
}
}

/**
* Adds a ship to the field. Only works if the ship fits in the field,
* the field is not occupied by another ship, and no bombs
* have been thrown yet.
* @param type The ship type.
* @param dir The direction the ship is facing.
* @param x The x - coordinate of the ship-rear
* @param y The y - coordinate of the ship-rear
* @return Returns true, if the ship could be placed.
*/
public boolean addShip(ShipType type, Direction dir, int x, int y){

// Checking if the ship rear is within coordinate field.
if (x < width && x >= 0 && y < height && y >= 0){

// Checking if no bombs have been thrown yet.
for(int n = 0; n < width; n++){
for(int m = 0; m < height; m++){
if(this.bombField[n][m] != null){
return false;
}
}
}

// Getting the ship length.
int shipLength = type.getLength();
// A helper variable used in the for-loops.
int iterator;

switch(dir){
case NORTH:
// Checking if the ship fits in the coordinate field.
if((y - shipLength) >= 0){
// Checking if no other ship occupies space.
for(iterator = 0; iterator < shipLength; iterator++){
if(this.shipField[x][y - iterator] != 0){
return false;
}
}
// Placing ship.
for(iterator = 0; iterator < shipLength; iterator++){
this.shipField[x][y - iterator] = type.getLength();
}
return true;
}else return false;
// Rinse and repeat for every direction.
case EAST:
if((x + shipLength) < this.width){
for(iterator = 0; iterator < shipLength; iterator ++){
if(this.shipField[x + iterator][y] != 0){
return false;
}
}
for(iterator = 0; iterator < shipLength; iterator ++){
this.shipField[x + iterator][y] = type.getLength();
}
return true;
}else return false;
case SOUTH:
if((y + shipLength) < this.height){
for(iterator = 0; iterator < shipLength; iterator++){
if(this.shipField[x][y + iterator] != 0){
return false;
}
}
for(iterator = 0; iterator < shipLength; iterator++){
this.shipField[x][y + iterator] = type.getLength();
}
return true;
}else return false;
case WEST:
if((x - shipLength) >= 0){
for(iterator = 0; iterator < shipLength; iterator ++){
if(this.shipField[x - iterator][y] != 0){
return false;
}
}
for(iterator = 0; iterator < shipLength; iterator ++){
this.shipField[x - iterator][y] = type.getLength();
}
return true;
}else return false;
default:
return false;
}
}else return false;

}

/**
* Places a bomb on the field. Sets {@link #bombField} to X or O,
* depending on whether a boat is hit.
* @param x X-Coordinate of the bomb hit.
* @param y Y-Coordinate of the bomb hit.
* @return Returns true if a ship has been hit.
*/
public boolean dropBomb(int x, int y){
// Checks if the field is occupied, and if it is, lays an X.
if(this.shipField[x][y] != 0){
this.bombField[x][y] = "X";
return true;
}else{
this.bombField[x][y] = "O";
return false;
}

}

/**
* A method that returns true if all the ships that were
* placed in the field were sunk.
* @return True if all ships are down.
*/
public boolean allShipsSunk(){

/* Helper Variables. Ship counter counts
* every cell with a ship and sunk counter
* counts every cell with a hit mark.
*/
int shipCounter = 0, sunkCounter = 0;

// Iterate over field
for(int x = 0; x < this.width; x ++){
for(int y = 0; y < this.height; y ++){
// If cell contains ship
if(this.shipField[x][y] != 0){
// Increment shipCounter
shipCounter ++;
// If cell contains hit marker
if(this.bombField[x][y].equals("X")){
// Increment sunkCounter
sunkCounter ++;
}
}
}
}

// If shipcounter and sunkcounter are the same,
// every ship has been sunk.
if(shipCounter == sunkCounter){
return true;
}else return false;
}

public String toStringWithShips(){
String stringWithShips = "";
String concat;

for(int y = 0; y < this.height; y ++){
for(int x = 0; x < this.width; x ++){
if(this.shipField[x][y] == 0){
concat = ".";
}else{
concat = String.valueOf(this.shipField[x][y]);
}
stringWithShips.concat(concat);
}
stringWithShips.concat("\n");
}
return stringWithShips;
}

public String toStringWithBombs(){
String stringWithBombs = "";
String concat;

for(int y = 0; y < this.height; y ++){
for(int x = 0; x < this.width; x ++){
if(this.bombField[x][y].equals(null)){
concat =  ".";
}else{
concat = this.bombField[x][y];
}
stringWithBombs.concat(concat);
}
stringWithBombs.concat("\n");
}
return stringWithBombs;
}

}
Title: Re: A programming thread!
Post by: ankhtahr on 08 Jun 2014, 16:59
Wow.

It's a very different approach to mine (and so incredibly much shorter) but it looks great! It'll be a great help if I run into trouble! Thanks a lot!

If we ever meet I owe you at least one beer! And I want us to meet one day!
Title: Re: A programming thread!
Post by: Masterpiece on 08 Jun 2014, 17:02
This is short? I hate the way I wrote "addShip" but I can't think of a better way of doing it (but seriously, so much redundant code, SO MANY ITERATIONS OVER THE FIELD :'( )
Title: Re: A programming thread!
Post by: ankhtahr on 08 Jun 2014, 17:07
Yeah, short in the sense that I have multiple additional methods, and one additional class. So lots of whitespaces and formatting.

And these additional methods all have checks for invalid parameters. So lots of redundant checks. But they're public, and my tutor likes to poke public methods until they break, so one should make sure they don't.
Title: Re: A programming thread!
Post by: Masterpiece on 08 Jun 2014, 17:09
I would much rather work with try-catch expressions, but since none of the methods you're supposed to write have any throw declaration I wasn't able to.

If your tutor likes poking methods, you should rewrite dropBomb in my method implementation. That method doesn't check if the coordinate given is in the field.

I'm tired! I'm off to sleep now. If you still have questions, PM me ( I should hear the e-mail sound.)
Title: Re: A programming thread!
Post by: ankhtahr on 08 Jun 2014, 17:16
I'll try to get my approach to work first, and I think I'm checking for valid coordinates everywhere. (Actually one of my methods is for checking whether a row (given with length, direction and coordinates) goes out of bounds, because I'm doing that everywhere.

The way my code looks right now, I've just thrown in everything I thought I could use, and will have to throw away around a quarter of it again, but I'm positive that it might do what it's supposed to do.

Also I think you've done enough for me by now, so I can finish without too much trouble. Thanks again!
Title: Re: A programming thread!
Post by: ankhtahr on 09 Jun 2014, 01:51
Sometimes you just want to throw your notebook against a wall…

(http://i.imgur.com/Usseuz1.jpg)

So I guess I won't get the bonus points. I won't sit here for another three hours, when I should be sleeping, only to do work I already did.
Title: Re: A programming thread!
Post by: Masterpiece on 09 Jun 2014, 02:58
If you lost your work, just submit mine
Title: Re: A programming thread!
Post by: ankhtahr on 09 Jun 2014, 03:18
All that was lost was the work for the bonus points (improved dropping of bombs in the test class), so it's no big deal, just annoying.
Title: Re: A programming thread!
Post by: cesium133 on 09 Jun 2014, 05:18
Sometimes you just want to throw your notebook against a wall…

(http://i.imgur.com/Usseuz1.jpg)

So I guess I won't get the bonus points. I won't sit here for another three hours, when I should be sleeping, only to do work I already did.
How on earth did you manage to get Linux to do that? I've only ever gotten a kernel panic when I had screwed up something royally...
Title: Re: A programming thread!
Post by: ankhtahr on 09 Jun 2014, 22:46
Probably a hardware fault. I've had HDD issues in the past, and I had noticed first signs of bad RAM before. Both could have cause this.
Title: Re: A programming thread!
Post by: hedgie on 09 Jun 2014, 23:08
For a test environment, I could see using Windows.   But I never would think of using it for a production environment.

There's nothing like a good set of blinkers! (I run Apache, Tomcat, PostgreSQL, etc on Windows at work, and the same plus Deluge and Kerio Connect at home.  But I use Open BSD for firewalls).

Aah, I'm more Apache and MySQL on Linux, myself.  Although I'm a bit of a recent (4 years) convert to Linux after I switched from OS X.

Quote
The only thing I can think of using a Windows server for is Exchange.

I hate Exchange with a passion, though I've been running it for 15 years; it's just that for the user Exchange plus Outlook is still unrivalled by any alternative.
[/quote]

Agreed.  It's an abomination against any gods that may exist, but I haven't seen any replacement for it.
Title: Re: A programming thread!
Post by: Masterpiece on 20 Jun 2014, 08:34
Our final task for our multimedia programming module is:

Write the game "Flappy Bird".

I'm writing in Python and it's SO FUN TO DO THIS I CAN'T BEGIN TO EXPLAIN

Like, every time I start coding I remember how AWESOME it is.
Title: Re: A programming thread!
Post by: GarandMarine on 01 Aug 2014, 19:28
Title: Re: A programming thread!
Post by: hedgie on 01 Aug 2014, 20:03
Well, at least he wasn't flinging poo.
Title: Re: A programming thread!
Post by: ankhtahr on 27 Aug 2014, 11:45
I'm sitting in front of my IDE, having to do one of the two final tasks which are counted as exams until Sunday. I can't really motivate myself to do it.
Title: Re: A programming thread!
Post by: ankhtahr on 28 Aug 2014, 15:40
Found out that using java.util.regex apparently isn't forbidden and makes the first part of the task a lot easier. Yay!

Edit: To specify: Finding every link in a long string marked with brackets ([[link]]) is a lot easier with regexes: \\[\\[(.*?)\\]\\]
Title: Re: A programming thread!
Post by: ankhtahr on 29 Aug 2014, 11:28
Anyone here who knows their (Java) regexes better than I do?

I need to extract every "word" from a very long string (the strings may only contain the symbols mentioned in the description here). A word delimiter is either a space or any of the following symbols:
Code: [Select]
.,;:_-?!Words which are connected with a hyphen are considered one word. (e.g. this-is-all-one-word) A word may contain numbers and umlauts, but must consist of at least one letter. My current regex for that is this one:
Code: [Select]
[A-ZÄÖÜ]+[^.,;:_?!\ ]*(I use CASE_INSENSITIVE of course)
I still need a way to cut off a hyphen at the end of a word. I tried it with a "-?" at the end, putting the rest in parenthesis, but that doesn't work of course, because the "not these special characters" is greedy.
Title: Re: A programming thread!
Post by: Pilchard123 on 29 Aug 2014, 11:35
Try http://www.regexr.com/ - it's not perfect (it uses a JavaScript regex engine which can be a bit flaky with lookarounds), but does the job for most things I've needed.


EDIT:

Must it be all regex? Could you use something like (code not checked, but hopefully you get the idea)
Code: [Select]
String toGetWords = "a long string of tokens that blah blah blah blah blah"
String delimiters = "a string containing all the delimiter characters"
StringTokenizer st = new StringTokenizer(toGetWords, delimiters)

while(st.hasMoreTokens()){
    String token = st.nextToken();
    //Trim trailing hyphen, or discard the token if the trailing hyphen disqualifies it.

    //Then use a regex to check if the token contains [A-ZÄÖÜ], case insensitive.
}
Title: Re: A programming thread!
Post by: Pilchard123 on 29 Aug 2014, 11:53
Doublepost for great justice!

http://codegolf.stackexchange.com/
Title: Re: A programming thread!
Post by: ankhtahr on 29 Aug 2014, 12:01
I think it should be relatively easy, My idea is to allow hyphens only if they are followed by another symbol. I just don't know, how to put this into a regex. And I feel like the other solution would stumble over a few other cases.

Huh, I just noticed that my regex has another problem. Words which start with a number won't be recognised.

Edit: found a solution:
Code: [Select]
\d*[a-zäöü]+([a-zäöü0-9]|\-[a-zäöü0-9])*
Title: Re: A programming thread!
Post by: Pilchard123 on 29 Aug 2014, 14:13
Have look at lookaheads, though I can't remember how to also capture those.
Title: Re: A programming thread!
Post by: Tea For The Tillerman on 30 Aug 2014, 01:26
Anyone here who knows their (Java) regexes better than I do?

I need to extract every "word" from a very long string (the strings may only contain the symbols mentioned in the description here). A word delimiter is either a space or any of the following symbols:
Code: [Select]
.,;:_-?!Words which are connected with a hyphen are considered one word. (e.g. this-is-all-one-word) A word may contain numbers and umlauts, but must consist of at least one letter. My current regex for that is this one:
Code: [Select]
[A-ZÄÖÜ]+[^.,;:_?!\ ]*(I use CASE_INSENSITIVE of course)
I still need a way to cut off a hyphen at the end of a word. I tried it with a "-?" at the end, putting the rest in parenthesis, but that doesn't work of course, because the "not these special characters" is greedy.

If this regex works:
Code: [Select]
[A-ZÄÖÜ]+[^.,;:_?!\ ]*(gonna call this block "word" from now on)

Couldn't you write something like this:
Code: [Select]
<word>[-<word>]*Basically saying "must have one word, but can have multiples as long as subsequent words start with a hyphen".
Title: Re: A programming thread!
Post by: ankhtahr on 31 Aug 2014, 13:55
Any tips for easy parsing of commandline arguments? I could of course use more regexes, but that feels like a little bit of overkill. I'm free to use java.util, but not much more. Switch cases seem impractical because the arguments can occur in any order, but not multiple times.
Title: Re: A programming thread!
Post by: Loki on 31 Aug 2014, 14:01
Never done that, but my approach would be: stuff all of them into an array, do linear search on the array (you only have a set universe of arguments, right?)

For determining the pairs of arguments and values, I'd indeed use regexes - or, more naively, indexOf(' ') plus substring.
Title: Re: A programming thread!
Post by: ankhtahr on 31 Aug 2014, 16:35
Yeah, I've decided to just use regexes anyway. I think with this task I learnt a lot about those. Anyway, I now have around 11.5 hours until I have to hand this task in. This might be a long night.

And now I discovered that I can apply another design pattern to this task. Good thing I studied for the software engineering exam. I'm now using the Composite and the Stategy pattern.
Title: Re: A programming thread!
Post by: ankhtahr on 31 Aug 2014, 19:56
AAAAAAARGH

uhm, anyone know a good way to divide a search string based on the following format into nice parts?

A search string consists of the command "search ", followed by either a single word, or multiple words put together using "AND(word1, word2)" or "OR(word1, word2)". You can nest ANDs and ORs. I wanted to model this using the composite design pattern, so I have "AndTerm", "OrTerm" and "FinalTerm", all extending "Term", with AndTerm and OrTerm consisting of two terms. Somehow I have to break a string down into a format I can use for these classes.

Edit:
Hmm, maybe I chose the wrong way to model this… This is difficult. I need to look into this.
Title: Re: A programming thread!
Post by: ankhtahr on 31 Aug 2014, 20:51
ok, I realised that my modelling is pretty much shit, and I'm starting to panic. I have 7 hours left to make this a running, Checkstyle compliant solution.

It would go into too much detail if I'd explain everything here, but here's the task (http://baldur.iti.kit.edu/programmieren/assignments/final01/final01-2.pdf).

I'm currently implementing the search for single search terms. I'm now at a point where I can get an ArrayList of Sites in which the term occurs, and I can get a ranking for each. Basically for the single term search to work I just need to put the results in a structure together with the rankings and sort it by the rankings. My mind is too full of fuck to manage that currently. I'm trying to do it anyway though.

And then I have no idea what to do about the multiple search term things.

Edit: okay, I think I'm writing a class for the results, which implements comparable to sort the results by the ranking. Still no idea about the multiple search terms.
Edit2: Slightly less panicky now that I at least have the search for single terms working in theory. I still need to write the parser for the commandline interface for that, but that shouldn't be so difficult. Now I need to understand how the hell the ranking with multiple search terms is supposed to work.
Title: Re: A programming thread!
Post by: ankhtahr on 01 Sep 2014, 01:17
I think I understand how the composed search terms are supposed to work, but I'm not getting anywhere. Besides, I have a terrible headache and feel sick. I definitely need to sleep, but I mustn't before I finished this task. Damnit.
Title: Re: A programming thread!
Post by: Loki on 01 Sep 2014, 01:20
Cannot help you there, unfortunately, except through moral support :(
Title: Re: A programming thread!
Post by: pwhodges on 01 Sep 2014, 03:00
I think I understand how the composed search terms are supposed to work, but I'm not getting anywhere.

Well, I have no idea about what framework you have available in modern programming, which may suggest or impose a particular technique; but I would have seen this as a very simple compilation problem: parse the command string into a tree structure, then walk that in reverse-Polish order doing the required tests and thus generating the answer.  Or have I missed the point of where your problem lies, through being so out of date?
Title: Re: A programming thread!
Post by: ankhtahr on 01 Sep 2014, 03:07
I think I understand how the composed search terms are supposed to work, but I'm not getting anywhere.

Well, I have no idea about what framework you have available in modern programming, which may suggest or impose a particular technique; but I would have seen this as a very simple compilation problem: parse the command string into a tree structure, then walk that in reverse-Polish order doing the required tests and thus generating the answer.  Or have I missed the point of where your problem lies, through being so out of date?

No, not really. I just didn't really think of such a solution. I've done basically everything in this task with regular expressions, so I only thought about regular expressions here as well.

I've managed to get a tiny bit further, which should give me at least a few points more, and now I'm so tired that I'll probably leave it at that and go to bed.

My horrible code can be found here (http://halfur.de/pic/fin1.tar.gz) if anybody feels like torturing themselves. I started out alright, but it got messier and messier with every hour. Now it's a trainwreck.
Title: Re: A programming thread!
Post by: ankhtahr on 14 Sep 2014, 11:52
So I'm now working on the second final task. Admittedly, I started very late (I have to be finished in 17 hours), but so far I don't see any big problems with it. It's a nice task. We have to model Conway's Game of Life with some variations. I'm considering throwing some design patterns on the task, but I don't think I really need to.
Title: Re: A programming thread!
Post by: Masterpiece on 14 Sep 2014, 12:25
I've done Convay's Game of Life before and I can give you some basic guidelines if you want.
Title: Re: A programming thread!
Post by: ankhtahr on 14 Sep 2014, 12:27
Nah, don't worry, I've got this so far. And my modelling seems to work well for once  :mrgreen:
Title: Re: A programming thread!
Post by: ankhtahr on 14 Sep 2014, 20:33
Yep, for once my modelling didn't completely blow up in my face. I'm finished with 7.5 hours to go. My solution did work right on the first try. I was a little bit suspicious, but even more testing didn't show any real problems, except for one small OutOfBoundsException, where I had swapped two parameters. It seems like I can go sleep now. I didn't expect that to happen.
Title: Re: A programming thread!
Post by: ChaoSera on 15 Sep 2014, 01:11
So, I don't suppose anybody knows how to connect TRACE32 PowerView to a GDB-Server, so I can use remote debugging from Eclipse?
Title: Re: A programming thread!
Post by: Pilchard123 on 17 Oct 2014, 13:29
Trying to learn my way around WCF. I left the book I've been using at work.

EDIT: I just wrote a method for copying a file that you can't select to a location that you can't change, using three different assemblies. For some reason I am proud of this.
Title: Re: A programming thread!
Post by: Pilchard123 on 18 Oct 2014, 06:29
TIL that if you import antigravity into a python program, xkcd #353 is opened in the default browser.
Title: Re: A programming thread!
Post by: Schmee on 18 Oct 2014, 22:13
So I'm doing an assignment in C, and for one part of it I have to print a specific character depending on the value of a double, temp_spl.
Basically, if temp_spl is between 30 and 35 I print a 3, 35 and 40 I print a space, and so on up to 90.
The solution I have currently is here, but it seems really clumsy. Is there a better way?
Code: [Select]
if (temp_spl>90.0){
printf("9");
} else if (temp_spl<30.0) {
printf(" ");
} else if (((int)floor(temp_spl))%10 >= 5) {
printf(" ");
} else {
printf("%d",(int)floor(temp_spl/10.0));
}
Title: Re: A programming thread!
Post by: ev4n on 20 Oct 2014, 11:34
If it works, that seems ok?

I can think of performance improvements, or ways that are more elegant, but I'm not sure why one would want to spend more time on improving a working solution without a good reason.

Sorry, maybe I'm being too cynical.
Title: Re: A programming thread!
Post by: ev4n on 24 Oct 2014, 08:31
Wait, Ecplise thinks that to run any kind of debugger, the top level make associated with the current workspace needs to be run?

What kind of moronic idea is THAT!?!?!?!
Title: Re: A programming thread!
Post by: osaka on 24 Oct 2014, 08:47
So I'm doing an assignment in C, and for one part of it I have to print a specific character depending on the value of a double, temp_spl.
Basically, if temp_spl is between 30 and 35 I print a 3, 35 and 40 I print a space, and so on up to 90.
The solution I have currently is here, but it seems really clumsy. Is there a better way?
Code: [Select]
if (temp_spl>90.0){
printf("9");
} else if (temp_spl<30.0) {
printf(" ");
} else if (((int)floor(temp_spl))%10 >= 5) {
printf(" ");
} else {
printf("%d",(int)floor(temp_spl/10.0));
}

I'd go with something a bit more nested, but that's just me:

Code: [Select]
char* result = "9";
if(temp_spl < 90.0 && temp_spl > 30.0){
  if(temp_spl % 10 < 5){
    result[0] = (int) floor (temp_spl/10) + 48;
  }else{
    result[0] = 32;
  }
}
printf("%s%n", result);

Some hacking in here with ascii tables and how C handles pointers/arrays, but it should work. You can always define result as char[]

EDIT: I just noticed that that doesn't take into account the possibility of the value being less than 30. Also, I found a way to express it in 1 line with ternary operators, just for funziez.

Code: [Select]
(temp_spl > 90.0) ? printf ("9") : ((temp_spl < 30.0) ? printf (" ") : ((temp_spl % 10 < 5) ? printf("%d", (int)floor(temp_spl/10.0)) : printf(" ")));

//"a ? b : c" stands for "if a, do b. Else, do c". a has to be a boolean or an expression that returns a boolean.+
//Example: Max(a, b) as ternary operation: a > b ? a : a < b ? b : a == b ? a : b;
Title: Re: A programming thread!
Post by: Loki on 25 Oct 2014, 09:39
What'd you need the third ternary for? Is there any case where !(a&lt;b) &amp;&amp; !(a&gt;b) &amp;&amp; !(a=b)?
Title: Re: A programming thread!
Post by: osaka on 25 Oct 2014, 10:37
Consistency. Technically, with the first two you've covered all possible outputs, but you have to define what happens when they're equal.

As a fun fact, that max(a,b) was actually a #define sentence made by a friend for our Operating Systems course. Knowing him, he probably didn't do the third part and either the compiler threw an error or the code segfaulted. So he added the third part.
Title: Re: A programming thread!
Post by: smack that isaiah on 26 Oct 2014, 07:27
Am I missing something, or couldn't a max function be done with just one ternary operation?

#define MAX(a, b) ((a > b) ? a : b)

if a is bigger than b, use a; otherwise use b (the otherwise necessarily being "if b >= a")

I think the main reason to use the more fleshed out version that osaka has posted would be if you're using objects which have overloaded the <, >, and == operators where it may not follow that {!(a > b) == (a <= b)} (imo, this means that these operators should never have been overloaded in the first place...).  Since this would be a #define, the types of a and b are not limited to int/double/float/etc.
Title: Re: A programming thread!
Post by: osaka on 26 Oct 2014, 09:28
Indeed it could be done. Once again, this was for Operating Systems, and things tended to get a bit overdone just to make sure.
Title: Re: A programming thread!
Post by: Masterpiece on 30 Mar 2015, 07:52
I have a problem, and was wondering whether you could help me out:

I have a method that is supposed to return a scaled instance of a Buffered Image I feed it. Since the program needs two different scaled versions of the same image, I first determine a scaling factor for the individual images and then feed that scaling factor to a general scaling method.

I know the scaling works, I also know that the methods propagate as needed. But the methods that are supposed to calculate the scaling factors always return zero. I have no idea why that happens, if I explicitly tell it that scale = 1.0, it works, but if I try to calculate scale as follows, scale will always be zero.

Code: [Select]
private ImageIcon scaleFiltered(BufferedImage filtered){

double scale = (screenHeight - HEIGHT_SCREEN_PADDING) / filtered.getHeight();

// scale = 0.5;

return scaleImage(filtered, scale);

}

any thoughts?
Title: Re: A programming thread!
Post by: ChaoSera on 30 Mar 2015, 08:40
I suppose screenHeight and HEIGHT_SCREEN_PADDING don't have the same value? Also there might be cast errors if some of the values are integers. Casting from int to double does not always work as good as one might expect.
Title: Re: A programming thread!
Post by: Masterpiece on 30 Mar 2015, 08:56
The values are not the same.

What would you do instead of casting?
Title: Re: A programming thread!
Post by: ChaoSera on 30 Mar 2015, 09:10
Declare them as double to begin with, unless you're limited by some external framework. Alternatively cast them explicetly to double, which might help as well.
Another method, although not a pretty one, would be to create Integer objects from the int values and then use the doubleValue() of those objects.
Title: Re: A programming thread!
Post by: Sorflakne on 15 Apr 2015, 18:33
So for a final project in my web publishing class, I'm making a Monopoly clone.  However, things...got off to a hairy start.  We were given a base of code to build off of that included the game board, players, and an auto-mover that moves each piece in turn on page refresh.  We have to build the rest of the game.  My partner and I got it to where an actual dice roller is working, but each page refresh not brings back a random number of errors; sometimes only three, sometimes, as the pic shows, only three thousand...

(http://i.imgur.com/wXryxG5.jpg)

As you can see, I'm still able to make fun of myself, so maybe there's hope.
Title: Re: A programming thread!
Post by: Masterpiece on 15 Apr 2015, 19:42
Reminds me of this:

[tweet]484373063077998592[/tweet]
Title: Re: A programming thread!
Post by: Pilchard123 on 27 May 2015, 11:56
https://fortune.com/2015/05/26/google-oracle-api-supremecourt-obama-appeal/

Apparently, APIs can be covered by copyright.
Title: Re: A programming thread!
Post by: Masterpiece on 27 May 2015, 12:29
WHAT THE EFF, ORACLE.
Title: Re: A programming thread!
Post by: cesium133 on 27 May 2015, 13:18
To be fair, Oracle has always been evil.
Title: Re: A programming thread!
Post by: pwhodges on 28 May 2015, 02:44
The report is unclear to me - it seems to say that Google was using a bit of the actual Java code to implement the API.  In that case, the copyright issue would lie with the code rather than the API itself, which there would be strong defences over, concerning the natural way to pass information (I was involved in an international software copyright dispute in the 1970s - but there's a lot more law to deal with now, I admit).

As for Oracle - evil?  Probably, just like pretty much any corporation of its size.  Incompetent?  You know how the current version of Java is [1.]8?  And updates for earlier versions are no longer available?  Well, my university's finance and student information systems are written by Oracle, in Java, and both were recently updated - they both will only run with Java [1.]6!  We get privately issued security updates for it (the last public update was #45, we're currently at #94), but there is a currently ongoing argument about whether our licence entitles us to use them!
Title: Re: A programming thread!
Post by: Masterpiece on 28 May 2015, 03:22
The problem is rather, that Oracle is suing Google because they're using API commands that have the exact same nomenclature in Java. In most cases, the only thing they kept is the method declaration, and changed the method bodies.

Oracle is suing Google because they used the same names for their API. Which I think is ridiculous.
Title: Re: A programming thread!
Post by: Masterpiece on 28 May 2015, 03:27
The wikipedia article (https://en.wikipedia.org/wiki/Oracle_America,_Inc._v._Google,_Inc.)
Title: Re: A programming thread!
Post by: pwhodges on 12 Jul 2015, 17:09
A new programming language (http://lhartikk.github.io/ArnoldC/)
Title: Re: A programming thread!
Post by: hedgie on 12 Jul 2015, 18:05
Meh.  Perl or death for me.
Title: Re: A programming thread!
Post by: cesium133 on 12 Jul 2015, 18:07
Randomly-generated ASCII characters do not a programming language make.