Search found 3024 matches

by Berengal
Wed Sep 22, 2010 7:51 pm UTC
Forum: Coding
Topic: Haskell efficiency concerns
Replies: 15
Views: 3449

Re: Haskell efficiency concerns

Oh, the joys of lazy evaluation... For starters, is using foldr as horrible an idea is it looks? No. In fact, you'll usually want to use foldr, and very seldom foldl. (foldl's stricter cousin, foldl', is almost always the better choice. More on this later.) The issue with foldr isn't efficiency. The...
by Berengal
Wed Sep 22, 2010 3:23 pm UTC
Forum: Coding
Topic: truly stand-alone applications
Replies: 25
Views: 3708

Re: truly stand-alone applications

I've never seen a web-based browser...
by Berengal
Tue Sep 21, 2010 4:47 pm UTC
Forum: Coding
Topic: Haskell: mapping with random numbers
Replies: 3
Views: 2031

Re: Haskell: mapping with random numbers

Another piece of advice: Don't try to understand monads on a conceptual level before trying to use them. There's very little to them, which means there's very little to hang on to and put in context, making them seem hard to understand. Understanding spesific instances of monads, however, is much ea...
by Berengal
Tue Sep 21, 2010 6:09 am UTC
Forum: Coding
Topic: Haskell: mapping with random numbers
Replies: 3
Views: 2031

Re: Haskell: mapping with random numbers

There's not really a better way; you have to do it like this in order to feed part of the result of one function (the "new" infinite list of random numbers) into the arguments of another. There are however ways to make this prettier, and they're called monads. People have already captured ...
by Berengal
Mon Sep 20, 2010 1:01 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9990
Views: 2000261

Re: Coding: Fleeting Thoughts

Coding is damned fun. I just spent a day writing a small asteroids-y game, including making the graphics, and have had a really good time, both coding and playing. This is why I program; making something worthwhile from scratch, assuming full responsibility for making it work correctly and full cred...
by Berengal
Sat Sep 18, 2010 11:09 am UTC
Forum: Coding
Topic: Having trouble limiting a recursive function
Replies: 8
Views: 1894

Re: Having trouble limiting a recursive function

Add the "moves_left" parameter. If you want your recursion to stop, you need one argument to become smaller each time you call it. It's the same as with loops; if you want your loop to stop, you need to decrease the loop variable every time.
by Berengal
Thu Sep 16, 2010 9:44 pm UTC
Forum: Coding
Topic: Question about generic types in Java
Replies: 9
Views: 2453

Re: Question about generic types in Java

There's a reason I didn't use '<? super T>'; usually subclasses of any class that implements Comparable breaks it in some way, usually by invalidating the contract of Comparable or the substitution principle. The same goes for any class that has meaningfully implemented equals.
by Berengal
Thu Sep 16, 2010 3:24 pm UTC
Forum: Coding
Topic: Commenting techniques
Replies: 5
Views: 1282

Re: Commenting techniques

What it says above. Here's a list ordered by the happiness and well-being I feel when I encounter new projects/libraries: ⋅ +10 happiness: Self-documenting code. The names are well-chosen, not too long, distinct enough from each other. There are no hidden dependencies or requirements; if y...
by Berengal
Thu Sep 16, 2010 6:42 am UTC
Forum: Coding
Topic: Question about generic types in Java
Replies: 9
Views: 2453

Re: Question about generic types in Java

Or something like this, if you want to be able to use a comparator in case you don't have comparables: class Tree<T> { public static <T extends Comparable<T>> Tree<T> newTree(){ return null; } public static <T> Tree<T> getTree(Comparator<T> comparator) { return null; } }
by Berengal
Thu Sep 16, 2010 6:19 am UTC
Forum: Coding
Topic: Language 'Types'
Replies: 9
Views: 2463

Re: Language 'Types'

Jython and JRuby can both be compiled. What they're compiled to varies a bit, but it's a mix of things between the kind of bytecode you get from compiling Java and an AST interpreted by the interpreter.
by Berengal
Wed Sep 15, 2010 6:46 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9990
Views: 2000261

Re: Coding: Fleeting Thoughts

I'd like to learn to do OOP in very elegant, precise, and correct way. Yeah, good luck with that. Write tests for everything and refactor mercilessly. Designs never survive enemy contact. And yes, interfaces become their own type. Check out File's listFiles methods. If the file represents a directo...
by Berengal
Sat Sep 11, 2010 12:00 pm UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9990
Views: 2000261

Re: Coding: Fleeting Thoughts

Using interfaces still gives you dynamic dispatch. I use that all the time in Java.
by Berengal
Fri Sep 10, 2010 12:28 pm UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9990
Views: 2000261

Re: Coding: Fleeting Thoughts

unlines . ((" **" ++ replicate 16 ' ' ++ "**"):) . ((replicate 3 [])++) . map (\d -> replicate (2* (7 - (round d))) ' ' ++ "*" ++ replicate (4 * round d) ' ' ++ "*") . map (*7) . map (\n -> sin (n*pi/12)) $ [0..6]
by Berengal
Fri Sep 10, 2010 7:10 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9990
Views: 2000261

Re: Coding: Fleeting Thoughts

What datastructure do pirates use the most?

Arrays.
by Berengal
Tue Sep 07, 2010 8:50 pm UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9990
Views: 2000261

Re: Coding: Fleeting Thoughts

The expressiveness (and at times impenetrableness) of Haskell never ceases to amaze me. I was just rehashing some old katas when I noticed the function I had just written was insanely clever (insane as in madness, not awesome) for it's size yet not too far removed from good style: combinations n lis...
by Berengal
Sun Sep 05, 2010 7:05 am UTC
Forum: Coding
Topic: java object comparison issue
Replies: 20
Views: 2532

Re: java object comparison issue

You can only break out of loops, switches and labeled statements. This means you can break out of an if if you label the block. if (true) fi: { break fi; } You can even use this instead of continues in loops, amazing your fellow coworkers with your language-construct-juggling abilities. If this is y...
by Berengal
Fri Sep 03, 2010 4:36 pm UTC
Forum: Coding
Topic: java object comparison issue
Replies: 20
Views: 2532

Re: java object comparison issue

Take a good hard look at your equals method. You've probably implemented it wrong. Feel free to paste it here for scrutiny.
by Berengal
Wed Sep 01, 2010 4:12 pm UTC
Forum: Coding
Topic: Haskell as a first language.
Replies: 10
Views: 4280

Re: Haskell as a first language.

LYAH is pretty good, but it doesn't cover the very basic concepts of programming very well; the things you learn in the first two weeks, only to spend at most one more week conciously thinking about before "forgetting" them. It also lacks goods excercises for newbies.
by Berengal
Wed Sep 01, 2010 3:07 pm UTC
Forum: Coding
Topic: Haskell as a first language.
Replies: 10
Views: 4280

Re: Haskell as a first language.

Familiar with math, but no programming experience you say? Haskell should be very easy to teach in that context. Much of his math knowledge and experience can be replicated in Haskell easily, introducing the basics of programming (syntax, running the interpreter, types, lexical closures) in a famili...
by Berengal
Fri Aug 27, 2010 6:11 pm UTC
Forum: Coding
Topic: Connecting shapes with lines in java
Replies: 5
Views: 1109

Re: Connecting shapes with lines in java

I've never done graphics in java before so I'm not even sure where to start. Any help would be appreciated thanks. With something like this. Add some recursion and mathematics and you've got yourself a tree graph. Or you could look for a library that does it for you. It's bound to exist, I just don...
by Berengal
Wed Aug 25, 2010 8:26 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9990
Views: 2000261

Re: Coding: Fleeting Thoughts

Why the thought never even occured to me.

Fucking Java, how does it work?
by Berengal
Wed Aug 25, 2010 6:51 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9990
Views: 2000261

Re: Coding: Fleeting Thoughts

So I've been writing Java code. Today I wrote this: class Schema { public static final UsersTable USERS = new UsersTable(); public static class UsersTable extends Table { private UsersTable(){super("users");}; public final IdColumn ID = new IdColumn(); public final NameColumn NAME = new Na...
by Berengal
Wed Aug 25, 2010 3:29 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9990
Views: 2000261

Re: Coding: Fleeting Thoughts

Do some underground work, set up a CI server (run it locally if you have to), and write tests for every bug you fix. Don't tell anyone until they start getting emails from the CI server about how they broke stuff. Gather a group of likeminded fellow developers in case your initiative gets under atta...
by Berengal
Sun Aug 22, 2010 9:57 pm UTC
Forum: Coding
Topic: Some help with Java Generics and duplicating constructors,
Replies: 7
Views: 1114

Re: Some help with Java Generics and duplicating constructor

It does, but a few notes: It's better to make several interfaces with different numbers of arguments than to let the argument be an array. This gives the compiler the ability to check that the correct number of arguments is passed in, removing that responsibility from the developer. It also helps th...
by Berengal
Sun Aug 22, 2010 6:26 am UTC
Forum: Coding
Topic: Some help with Java Generics and duplicating constructors,
Replies: 7
Views: 1114

Re: Some help with Java Generics and duplicating constructor

First of all, you can call other constructors and superconstructors in constructors if they're the first call made. To call other constructors in the same class, use "this(args)", and to call superclass constructors, use "super(args)". For example, to set the initial capacity you...
by Berengal
Sun Aug 22, 2010 4:22 am UTC
Forum: Coding
Topic: Haskell & Gtk2hs signals [SOLVED]
Replies: 2
Views: 825

Re: Haskell & Gtk2hs signals.

Does this fall under "stuff you'll learn when you get better at monads"? Sort of, but most of the time you don't need to understand monads to be able to use them. (You don't have to understand monads to program in Java, but every Java program exists in an "ErrorT Throwable IO" m...
by Berengal
Wed Aug 18, 2010 4:55 pm UTC
Forum: Coding
Topic: An Introduction to Java? Hn.
Replies: 12
Views: 1978

Re: An Introduction to Java? Hn.

The first part, checking for correctness, is entirely justifiable assuming you have a good specification for what the output is supposed to be. The second part sounds entirely laughable. What's it even trying to measure?
by Berengal
Mon Aug 09, 2010 12:24 am UTC
Forum: Coding
Topic: Fake Programming Language
Replies: 210
Views: 31268

Re: Fake Programming Language

It also looks close to some lisp object systems (not that I've studied any in particular detail), as well as a pattern I've been using in python from time to time when the class-based object system was insufficient. It's well known that lexical closures are a poor man's objects (and objects are a po...
by Berengal
Sun Aug 08, 2010 6:05 pm UTC
Forum: Coding
Topic: Python regex problem
Replies: 9
Views: 2123

Re: Python regex problem

Code: Select all

,[^,]*C[^,]*,
by Berengal
Fri Aug 06, 2010 10:54 pm UTC
Forum: Coding
Topic: [java] How to make my download class faster?
Replies: 3
Views: 872

Re: [java] How to make my download class faster?

Use buffers. There are several options, BufferedInputStream, BufferedOutputStream, read(byte[])/write(byte[], int start, int offset). I'd probably just go with the byte array and do something like final int bufferSize = 1024 * 512; // arbitrary number, experiment, but 512k should be more than you ne...
by Berengal
Fri Aug 06, 2010 9:08 pm UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9990
Views: 2000261

Re: Coding: Fleeting Thoughts

FT: What happens when you try to inline a recursive function? data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+DQo8aHRtbD4NCiAgPGhlYWQ+DQogICAgPHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiIHNyYz0iaHR0cDovL2FqYXguZ29vZ2xlYXBpcy5jb20vYWpheC9saWJzL2pxdWVyeS8xLjQuMi9qcXVlcnkubWluLmpzIj48L3NjcmlwdD4NC...
by Berengal
Thu Aug 05, 2010 4:01 pm UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9990
Views: 2000261

Re: Coding: Fleeting Thoughts

Any suggestions for writing a loop for continually prompting for user commands then executing them in Haskell? Best I can come up with right now is a recursive function with pattern-matching on the "quit" command to break the loop, but due to that exit strategy the function has to be seed...
by Berengal
Wed Aug 04, 2010 6:41 pm UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9990
Views: 2000261

Re: Coding: Fleeting Thoughts

main = let rick = rick roll = flip sequence you $ map ($me) [ giveUp , letDown , (&&) <$> const . (run around) <*> desert , makeCry , const . (say goodbye) , (&&) <$> const . tellLies <*> hurt ] in const rick roll [/made functional]
by Berengal
Tue Aug 03, 2010 3:51 pm UTC
Forum: Coding
Topic: coworker rants
Replies: 92
Views: 14300

Re: coworker rants

I have a new candidate for "worst name of the year". private void validateDeleteRequest(Request request, Connection conn) throws Exception { log.finest("validateDeleteRequest"); if (request.hasValidBillerAccountNumber()) { log.finest("RequestId " + request.getRequestId(...
by Berengal
Mon Aug 02, 2010 4:38 pm UTC
Forum: Coding
Topic: coworker rants
Replies: 92
Views: 14300

Re: coworker rants

Let me present you a snippet of some code I'm working on: public static Map<String, List<Request>> fetchRequestMap(Connection conn) { // long implementation } Focus on the name of the method. What does it tell you? Well, obviously it fetches a request map, but we can see that in the signature alread...
by Berengal
Sun Aug 01, 2010 5:32 pm UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9990
Views: 2000261

Re: Coding: Fleeting Thoughts

Keeping the entire thing in memory is exactly what I'm trying to do. If I can get gzip to compress this well then there's no problem since that's a stream compressor and doesn't need a ramdisk anyway. Another advantage of gzip (or a pure Java implementation with no dependencies on external tools) is...
by Berengal
Sun Aug 01, 2010 3:06 pm UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9990
Views: 2000261

Re: Coding: Fleeting Thoughts

What are you using to do the PDF to PS conversion? Ghostscript, and a regex to touch up some tray info (which incidentally also breaks PS viewers' ability to render the file for some reason). What I'd really like is to get rid of rar altogether and use zip since then I could outsource the heavy lif...
by Berengal
Sun Aug 01, 2010 1:45 pm UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9990
Views: 2000261

Re: Coding: Fleeting Thoughts

And if all the concatenated images have the same large identical prolog, there's plenty of scope for compression. If that's the case, it certainly explains the size difference between compressing a disk file v compressing stdin. That's what I've come to suspect as well. Perhaps if I can somehow for...
by Berengal
Sun Aug 01, 2010 11:36 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9990
Views: 2000261

Re: Coding: Fleeting Thoughts

Yes, they work. PostScript itself is highly redundant being a programming language and all, and in this case the large files are just a concatenation of thousands of smaller files, each with the same layout which is also very repetitive. The actual data content of each file is very small. I wouldn't...

Go to advanced search