Quantcast

Maximum PC

It is currently Sat Aug 23, 2014 11:04 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 41 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: Mon Apr 05, 2010 7:22 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Dwood15 wrote:
Gadget wrote:
Dwood15 wrote:
Every halo uses an extremely LISP-like scripting engine. Just thought I'd point that out.

OK... =)

Now share some of your favorite language features / idioms!


#ifdef

#endif

in C++. If you ever make an addon for a program that has multiple versions, or a game that has multiple versions... Or simply just differences between debug//release builds, that's your best friend. :)

I don't know if I'd go as far as to say "best friend", but macros can certainly help make C code more elegant. C macros can also be a pita. In fact, I worked on one team at Boeing that forbid me from using macros... of course, that was the same team that decided to write their own half-ass XML parser in C. Stupid.

If you like C macros, you'll LOVE Lisp macros. Unlike C, where you're basically working in a separate little macro-language, Lisp allows you to write macros in Lisp code that expand into standard Lisp forms. Imagine that you have a function foo, which calls two other functions bar and baz. Let's say that we're trying to speed up the performance of foo. In most languages, you'd have to go find some kind of profiling tool and run foo inside of it. In Lisp, you can use a macro... (profile foo) ...that can tell you the cumulative time spent in each function. In fact, this type of functionality is a part of the language standard... tracing, inspecting, stepping, etc.

Paul Graham has a book available online called On Lisp that is basically 4oo pages of meta-programming using Lisp macros. He touches on all kinds of cool stuff like DSLs and non-determinism. Definitely worth checking out.


Top
  Profile  
 
 Post subject: Re: Favorite programming idioms and language features...
PostPosted: Mon Apr 05, 2010 7:30 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Beomagi wrote:
StringRegExp ( "test", "pattern" [, flag ] [, offset ] ] )
With the flag set to 1, will return the array of matches.
can be used to split the "test" string, or simply parse out sections.

I actually haven't used Perl (beyond wanting to puke at the code that I've seen) or PhP, so this is pretty new to me. =)

Does setting flag to 0 (or not specifying a flag) do splitting instead of matching?

What is the offset?


Top
  Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2010 9:57 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
I was reading some old posts by JWZ and RMS on Emacs today and thought of the famous Regex quote by Jamie. I imagine that at least a few of you haven't seen it before... at least the youngin's. =)

[b]Some people, when confronted with a problem, think “I know,
I'll use regular expressions.â€


Top
  Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2010 12:44 pm 
Northwood
Northwood
User avatar

Joined: Sun Jul 15, 2007 6:37 pm
Posts: 2261
Location: No. 1 Thread Killer
Call me noob, but I still don't understand the reasoning for that statement.

Scratch that, I really am noob.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2010 1:13 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
I've done a couple of projects in Common Lisp recently. Here are two things that I have found to be pretty useful. Note: I'm purposefully leaving out the Common Lisp Object System and macros. These are extremely cool and powerful features, but require quite a bit of time to truly appreciate. We'll start with a couple of easy ones. =)

First, I love having the ability to return multiple values. What is so great about multiple return values? It either saves you from having to write the same function multiple times OR having to use a combination of additional parameters or globals (OR both OR you having to compute the remainder, etc). Let's use a really easy example... a rounding function. There are essentially two items of interest when rounding a number, the integral portion and the truncated remainder. A solution that returns both values in C or Java ends up being a bit convoluted... I'm sure that you guys can come up with all these variations easily enough on scratch paper.

The method in which CL implements this language feature seems very well thought out.
Code:
CL-USER> (setf integral (round 25.125)) ;a function that returns multiple values operates as expected during the normal case...
25             ;(ie when I only want one value)
CL-USER> (setf remainder (nth-value 1 (round 25.125))) ;or we can get at just the remainder if that is all we want
0.125
CL-USER> (multiple-value-bind (integral remainder)  ;or BOTH, with a _single_ call when we really need both of them...
        (round 25.125)
      (format t "integral: ~a  remainder: ~d  sum: ~d~%" integral remainder (+ integral remainder)))
integral: 25  remainder: 0.125  sum: 25.125
NIL
CL-USER>


I LOVE IT...
1) A single function. No code duplication.
2) A single function call; No need to make n calls for n different values.
3) No need to create global vars for multiple values or things like error conditions.
4) Simple function definitions -- round(val &integral &remainder) is a bit fugly, no?

A couple of places that I've found it to be handy are when computing some basic statistical values like average, median, std dev, var, etc. With multiple return values, I only have to make one pass over the data. Plus, I don't have to write eight different functions (or one giant fugly one).

Another example is in the CL library for hash tables. Why does Java, for example, have containsKey() and get() when get() could suffice for both functions by returning null? Well, if I need to null as a value, then I can't tell them whether I have a key with a null value or that key isn't in the hash table, hence containsKey(). The CL equivalent of get() is gethash. Instead of having a containsKey() function, you just check the second value returned by gethash. How either language does the check is an interesting problem to think about... =)

The second thing, I'm not so sure that I like it as much as I'm starting to think it is pretty useful. As with many newer languages (eg Python, Java, C#), CL has a data type hierarchy. Floats and Integers are both of type Number, etc. At the top of the hierarchy is T, which is the normal method for stating true (and like C, any values that is not nil is true). This struck me as odd at first -- I kind of like the way Object is the top in Java. Here is the twist. Nil is not just false. It is also the empty list. Keep in mind that Lisp stores is written as a series of lists (ie (+ 1 2) is the list starts with the function + and has two args). Having nil be an empty list just didn't seem like the "right thing" to do, but it does have a few unexpected practical perks.

In Java, I would normally store the results of a Monte-Carlo sim (or some other task) in a hash table using an ArrayList to hold the values. The code would almost always end up looking something like...
Code:
if (my-map.containsKey(key) == false)  //or !containsKey() if you prefer... ;)
           my-map.put(key, new ArrayList());

values = my-map.get(key);
values.add(newValue);
my-map.put(key, values);


There is nothing particularly unsightly about it -- 5 lines of code -- pretty standard stuff. It just always had that extra little if-step and I never really thought anything of it until I did the same thing in CL.

Code:
      (setf values (gethash k ht))   ;get the list
      (push v values)                ;add the new value v to it; works because nil is an empty list
      (setf (gethash k ht) values)   ;put it back in the ht... notice that using setf on a get function
                                          ;adds an item in CL... this appears throughout the language

;;I can even reduce it to a single line of code...
(setf (gethash key ht) (push new-value (gethash key ht)))


Alright... if someone else doesn't post an example, I'm going to post some more Lisp stuff. ;)


Top
  Profile  
 
 Post subject:
PostPosted: Tue Apr 13, 2010 12:39 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Dwood15 wrote:
Call me noob, but I still don't understand the reasoning for that statement.

Scratch that, I really am noob.

The link covers the history and reasoning. The comments are worth a quick read.


I'm wondering if anyone has come across a good cross-platform documentation facility (ie somthing like JavaDoc). I have quite a bit of code written in BASIC, Python, CL, Java and C. I'd like to be able to create a single set of hyperlinked documents.

Just a shot in the dark. =)

Does anyone know of a documentation facility that they think is better than JavaDoc? I'm just using that as a benchmark because I figure most people will probably be familiar with it.


Top
  Profile  
 
 Post subject:
PostPosted: Sat Jun 26, 2010 12:23 am 
Team Member Top 100
Team Member Top 100

Joined: Fri Sep 17, 2004 5:35 pm
Posts: 1176
I've recently been fascinated by Prolog. Although it can be a pain to debug and the performance can be lackluster at times, its very "out-of-the-box" paradigm continually impresses me with the cleanliness and succinctness with which it describes solutions. Lately I've also been toying with ML, which I really like a lot.

Maybe I think they're cool because I've spent so much of my programming time working in imperative/OO languages that I just see something "shiny" and it interests me; in any case I have no plans on using Prolog or ML in any serious professional projects (not that it can't be done, mind you).


Top
  Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2010 9:38 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Kybo_Ren wrote:
I've recently been fascinated by Prolog. Although it can be a pain to debug and the performance can be lackluster at times, its very "out-of-the-box" paradigm continually impresses me with the cleanliness and succinctness with which it describes solutions. Lately I've also been toying with ML, which I really like a lot.

Maybe I think they're cool because I've spent so much of my programming time working in imperative/OO languages that I just see something "shiny" and it interests me; in any case I have no plans on using Prolog or ML in any serious professional projects (not that it can't be done, mind you).
How is you? back from the ded?


Top
  Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2010 6:58 pm 
Northwood
Northwood

Joined: Mon May 30, 2005 11:16 pm
Posts: 2057
GIGO. Garbage in, garbage out. True in any language.


Top
  Profile  
 
 Post subject:
PostPosted: Mon Jul 05, 2010 2:55 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Kybo_Ren wrote:
I've recently been fascinated by Prolog. Although it can be a pain to debug and the performance can be lackluster at times, its very "out-of-the-box" paradigm continually impresses me with the cleanliness and succinctness with which it describes solutions.

For certain problems, it is pretty darn hard to beat Prolog. I plan on spending quite a bit of time writing Prolog code in the future.

Is there a programming language that is a bit higher up the logic tree than Prolog? Something that mimics a first-order order or higher logic? That would be an interesting language.


Top
  Profile  
 
 Post subject:
PostPosted: Tue Jul 06, 2010 4:18 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
So far my favorite feature of .NET 4.0: http://msdn.microsoft.com/en-us/library/dd460717.aspx


Top
  Profile  
 
 Post subject:
PostPosted: Sat Jul 10, 2010 5:38 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
CrashTECH wrote:
So far my favorite feature of .NET 4.0: http://msdn.microsoft.com/en-us/library/dd460717.aspx


Cool. Now write a program to find the convex hull of a set of points using it!


Top
  Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2010 3:44 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
pffttt... Like I have time to do that? I have LOB apps to write :)


Top
  Profile  
 
 Post subject:
PostPosted: Thu Jul 15, 2010 7:16 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
CrashTECH wrote:
pffttt... Like I have time to do that? I have LOB apps to write :)

LOL... how do you keep from shooting yourself?! =)


Top
  Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2010 3:47 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Gadget wrote:
CrashTECH wrote:
pffttt... Like I have time to do that? I have LOB apps to write :)

LOL... how do you keep from shooting yourself?! =)
Every two weeks I look at my paycheck? It is how I have all my toys... two motorcycles (although one is my wife's technically) a nice truck. We'll be getting her a new car next year too... I mean, :: shrug :: I guess I sold my soul to the "devil" for a paycheck, but I ain't complaining.

:)

I had two choices really, stay in the academic world, which I was only so-so at anyway, work on some more interesting things for a lot less money. OR go into the world of business, work on less interesting stuff (although we still have some really super challenging problems that makes me think! So it isn't totally boring) and make more money. I decided I could always go back to school and do research, work on a degree... but I needed to get a job while the getting was good. Glad I did. People who graduated about when I did still haven't found real full time work.

I did some more research, and my total compensation is valued more like $100k.... so, I can't complain. Insurance is a nice thing to have.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2010 4:57 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Yeah, a fat paycheck is nice. Of course, it sounds like both of us should probably have much fatter ones... snag one of Jip's when he isn't looking... he won't miss it! =)

I think that part of my bias against companies has been due to the unfathomable ignorance of my managers and the senior techies (ie more like "How the eff did you get a job?!") on the teams that I have worked over the past four years. I'm just amazed that any of these people were able to find employment. Now that I have most of the toys that I need/want, I'm looking to fulfill a different area of my personality/being.

PS -- Oh, and there is NOTHING wrong with getting paid to get better! I think that part of my bias against corps was that I felt like I was getting jobs that weren't allowing me to get any better... a bunch of maintain bullshit apps type of thing.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2010 5:45 am 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24222
Location: Granite Heaven
Hey! Gimme that back! :P

The situation you're describing is the result of the Peter Principle: "in a hierarchy, every employee rises to the level of his incompetence."

Sad, but I've only ever worked in one place where that doesn't hold true .. thankfully, that place is my current job. :)


Top
  Profile  
 
 Post subject:
PostPosted: Sat Jul 17, 2010 12:38 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Jipstyle wrote:
Hey! Gimme that back! :P

Sure... one small problem... Crash and I spent it in Vegas. We'll send you some pics. ;)


Top
  Profile  
 
 Post subject:
PostPosted: Sat Jul 17, 2010 9:22 pm 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24222
Location: Granite Heaven
Bastards spent my money in Vegas and didn't even invite me.

:?


Top
  Profile  
 
 Post subject:
PostPosted: Sun Jul 18, 2010 8:29 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
You were on the roof... passed out with a sun burn :)


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 41 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group