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

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

Sometimes you have to roll the hard... two?

qntm posted:

So what's the best programming language?

mIRC script.

Adbot
ADBOT LOVES YOU

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

rolleyes posted:

mIRC script.

Truth. You will learn good things in that.

rolleyes
Nov 16, 2006

Sometimes you have to roll the hard... two?

Golbez posted:

Truth. You will learn good things in that.

Guilty confession: I wrote a (very basic, insecure) webserver in mIRC script a long time ago.

With that said, I'm now off to commit seppuku.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

rolleyes posted:

Guilty confession: I wrote a (very basic, insecure) webserver in mIRC script a long time ago.

With that said, I'm now off to commit seppuku.

I once made a lyrics script that would go out to lyrics.ch and get songs, but ... :stare:

rolleyes
Nov 16, 2006

Sometimes you have to roll the hard... two?

Golbez posted:

I once made a lyrics script that would go out to lyrics.ch and get songs, but ... :stare:

It was coupled with the MP3 player I also made* and served dynamic pages which displayed the playlist and allowed you to control playback. That probably makes it worse. In my defence this was about 10 years ago when I was a teenager.


*For those unfamiliar with mIRC, it provides a function to play MP3s so no I did not implement the actual algorithm in mIRC script - that would be a step beyond insanity. You had to do everything else yourself though - build the UI, event handlers, etc.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

rolleyes posted:

It was coupled with the MP3 player I also made* and served dynamic pages which displayed the playlist and allowed you to control playback. That probably makes it worse. In my defence this was about 10 years ago when I was a teenager.


*For those unfamiliar with mIRC, it provides a function to play MP3s so no I did not implement the actual algorithm in mIRC script - that would be a step beyond insanity. You had to do everything else yourself though - build the UI, event handlers, etc.

I made a drat sweet MP3 player. I had all these grandiose plans to support Winamp skins in it too... and then I found some insane person had actually done that. I was impressed.

rolleyes
Nov 16, 2006

Sometimes you have to roll the hard... two?

Golbez posted:

I made a drat sweet MP3 player. I had all these grandiose plans to support Winamp skins in it too... and then I found some insane person had actually done that. I was impressed.

Nice. I've always chased functionality over looks so mine was plain old winforms style but with ridiculous over-the-top features (see also: webserver).

I still have that script somewhere.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

rolleyes posted:

Nice. I've always chased functionality over looks so mine was plain old winforms style but with ridiculous over-the-top features (see also: webserver).

I still have that script somewhere.

Well I never actually made a GUI for it. But I considered it! The best part about mine was the customization. %name% for the song name, %artist, %genre%, etc... everything! And colors! poo poo, I remember when Khaled added colors to mIRC. That was a hell of a day, I tell you. It was exciting.

Then again, I also remember when Khaled added if. :v: Looking around Google, there's almost no trace of mIRCIf; not a surprise, since it ceased to be used years before Google came around. It was an external program to add if-then-else handling to mIRCScript.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
I know that in languages with strict typing, you typically have to declare the types of all the parameters to a function, as well as the type of the return value. Like in C you might have

int myfunction (int a, float b);

(I may have made a syntax error somewhere, it's not crucial to the post.) Aside from maybe being necessary for low-level languages to work properly, this has the nice property that you've made a declaration to some extent of what properties you want your function's arguments to satisfy, which makes your job easier. In some dynamic languages (PHP I'm looking at you) you cannot declare that you want an argument to be an integer, so you either have to do some kind of check in the function, or throw your hands up and say gently caress it, I'm just going to assume whenever this function gets called it is by somebody who isn't retarded. Maybe that isn't so bad but it is kind of unsatisfying.

But it seems like the capability of saying what type you want the argument to be is not going far enough. I should be able to say that I want the argument to be not just an integer, but an odd integer greater than 10, or that I want the return value not just to be a string, but that I want it to be a string precisely 8 characters in length.

Seems to me the easiest way to achieve that is by saying: when you define your function, for each argument you should supply not a type, but a predicate that you want to return true or else the function has been called incorrectly and an error should occur. For convenience, names of types should also be usable as predicates that take a single argument and return true or false according as the argument is of the appropriate type. So something like the following should be doable (syntax is made up; assume that nonnegativeInteger is a predicate that already exists and behaves in the obvious way):

code:
global predicateGreaterThan := function (n satisfying number) {
    return function (x satisfying number) capturing n {
        return x > n;
    };
};

global odd := function (x satisfying integer) {
    return x % 2 = 1;
};

local oddIntegerGreaterThan10 := all(predicateGreaterThan(10), odd);

global stringOfLength := function (n satisfying nonnegativeInteger) {
    return function (s satisfying string) capturing n {
        return s.length = n;
    };
};

local stringOfLength8 := stringOfLength(8);

local myfunction := function (x satisfying oddIntegerGreaterThan10, s satisfying string)
                    return value satisfying stringOfLength8 {
    ...
};
Here "all" is a function that takes an arbitrary number of predicates as arguments, and returns a predicate that returns true if and only if all of the original predicates return true on its argument.

Tell me languages that behave in a similar way to what I just described.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
What you're describing is typically called 'contracts'. For example, I recently came across contracts.coffee, a dialect of CoffeeScript that implements contracts. (Only runs in Firefox, so it's not really useful to play with, but it's an example to look at.)

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Hammerite posted:

Tell me languages that behave in a similar way to what I just described.

The general property of "I want types which are arbitrary predicates" in a language is called dependent types, which are typically only seen in proof languages such as Coq, Isabelle, and Agda. Generally, dependent type systems are seen as somewhat undesirable in real-world languages, as they tend to make the language overly verbose and have turing-complete (hence potentially non-terminating) compilation phases.

That said, there are less-complete type systems which can do an excellent job of letting you make very precise types, while not allowing arbitrary predicates; Haskell is probably the best example, as it has a very extensive type system and is reasonably well-known.

If you are fine with your predicates only being checked at runtime (potentially throwing an exception or some such) then obviously this becomes significantly easier and less interesting; any arbitrary functional programming language would make the task trivial and boring. Usually runtime predicates are called contracts or assertions, depending on how they're implemented.

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde

pokeyman posted:

The question was:

The answer was:

What the hell kind of an answer is that?

Hang around in this thread for ten minutes and you'll find a "what language should I learn?" post. The number of exceptionally unhelpful answers that pop up every time is so frustrating. I'm fine with posting pages of your diaries, just don't do it "in response" to a genuine request for help.

Apology accepted. :) To clarify where I was coming from he asked:

Sulk posted:

I feel like it comes down to whether I want to work on more traditional software versus having the ability to design iOS applications, but does anyone have more insight?

To me, this was the part that I was responding to. After all, if you understand Java, you can understand C# up to .NET 2.0 easily. You can probably also grok the syntax of Objective-C (I have no idea about the cocoa framework etc. having never used them) Part of his question came across as "Should I do 'traditional development' or mobile development." This was the bit I was responding to. By giving my opinion (and just that) on mobile development, it was to guide Sulk towards picking either Java or C#. Cos picking Objective-C for mainstream desktop development is a bit restrictive.

qntm
Jun 17, 2009

pokeyman posted:

What you're describing is typically called 'contracts'. For example, I recently came across contracts.coffee, a dialect of CoffeeScript that implements contracts. (Only runs in Firefox, so it's not really useful to play with, but it's an example to look at.)

Oh that's what contracts are. Everything I'd heard about them up until now just sounded like strict typing.

Eggnogium
Jun 1, 2010

Never give an inch! Hnnnghhhhhh!
You can create this behavior in Python using a combination of decorators and parameter annotations.

tef
May 30, 2004

-> some l-system crap ->
You mean static typing not strict typing, and the language sage is the closest thing I can suggest

raminasi
Jan 25, 2005

a last drink with no ice
D has contracts built in.

tef
May 30, 2004

-> some l-system crap ->

tef posted:

You mean static typing not strict typing, and the language sage is the closest thing I can suggest

to elaborate:

static typing vs dynamic typing - this is where the types are checked, at compile or runtime
strong typing vs weak typing - this is how far the language will go to interpret one data type as another, this can encompass implicit casts as well as things like duck typing

'strict' is often used to mean 'static' or 'strong' or a mixture of both

what you are talking about is typing basically, but types defined by a function rather than a class hierarchy.

as some have pointed out, some languages provide a facility for runtime checks, (notably eiffel), but these are normally implemented as a series of pre/post conditions and invariants around functions, rather than only defining a function which signifies a type.

of the languages where you can freely mix functions and types, I can only think of two off hand:

magpie: a toy language experimenting with some ideas
http://journal.stuffwithstuff.com/2010/10/29/bootstrapping-a-type-system/

and more realistically, sage: http://sage.soe.ucsc.edu/ is a more thought out version with type checking

this is more along the dependent typing area, but will try to type check your program as much as possible, but falling back to dynamic checks

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Most of the time I've heard "strict" typing it's used as an alternative to "dynamic" typing. Basically people who like languages with strong typing use "strong" vs. "weak", which makes weak typing sound bad. People who like languages with weak typing use "strict" vs. "dynamic", which makes weak typing sound good.

tef
May 30, 2004

-> some l-system crap ->
although alan kay likes to say things like "strong typing is for weak minds"

Achmed Jones
Oct 16, 2004



So I'm using ruby to parse an RSS feed and display the HTML:
code:
latest_tracks_rss = RSS::Parser.parse(latest_tracks_source)

for i in latest_tracks_rss.items do
	latest_tracks=latest_tracks + "<a href=\"#{i.link}\">#{i.title}</a><br>"
end
This gets me things like

Artist – Title

How the hell do I make that stupid Unicode thing go away and replace it with a dash? If I try to do latest_tracks.gsub it pukes on having unicode in the source file.

nielsm
Jun 1, 2009



Achmed Jones posted:

Artist – Title

How the hell do I make that stupid Unicode thing go away and replace it with a dash? If I try to do latest_tracks.gsub it pukes on having unicode in the source file.

You've got some UTF-8 there. Mark your output as UTF-8 too, either through the Content-Type HTTP header (best) or through one of the several HTML ways.

Super Dude
Jan 23, 2005
Do the Jew
How would I match the following using regular expressions (I'm using flex): A string surrounded by < > which contains one or more non-printable characters?

I thought it would be: \<.*[^[:print:]]+.*\>

but that also picks up things like <hello>. Any ideas?

nielsm
Jun 1, 2009



Super Dude posted:

How would I match the following using regular expressions (I'm using flex): A string surrounded by < > which contains one or more non-printable characters?

I thought it would be: \<.*[^[:print:]]+.*\>

but that also picks up things like <hello>. Any ideas?

code:
$ echo -e "foo <hi> bar\nfoo <bro\0020ken> bar\nwh<>at\0020" > testfile
$ cat testfile
foo <hi> bar
foo <broken> bar
wh<>at
$ grep '<[[:print:]]*[^[:print:]][^>]*>' testfile
foo <broken> bar
First match potentially a bunch of printables, then match just one non-printable, then maybe match a bunch of non-closing angles, then a closing angle.
Assuming grep works the same as flex.

Achmed Jones
Oct 16, 2004



nielsm posted:

You've got some UTF-8 there. Mark your output as UTF-8 too, either through the Content-Type HTTP header (best) or through one of the several HTML ways.

Awesome, that fixed it! Thanks!

Haptical Sales Slut
Mar 15, 2010

Age 18 to 49
Stupid newbie question: I'm calling CMD from a powershell script and I need to do two things:
1.) Open the command prompt at a defined location, so when it opens the path is already set to, say d:\custompath\
2.) Paste the contents of a PS variable into the command prompt

I want the CMD window to open, paste the command, run it, and stay open so I can view its progress. It seems like it would be so easy and yet Ive spent hours trying to figure this out. What I've ended up with is something like this:

$file = get-content D:\path\file.txt
$clip = get-clipboard
$both = $file += $clip
$both | cmd.exe

I'm a sys admin and I've never been able to learn anything except basic SQL because my brain doesn't seem to understand how computers want me to input information :( Any help is appreciated.

Super Dude
Jan 23, 2005
Do the Jew

nielsm posted:

code:
$ echo -e "foo <hi> bar\nfoo <bro\0020ken> bar\nwh<>at\0020" > testfile
$ cat testfile
foo <hi> bar
foo <broken> bar
wh<>at
$ grep '<[[:print:]]*[^[:print:]][^>]*>' testfile
foo <broken> bar
First match potentially a bunch of printables, then match just one non-printable, then maybe match a bunch of non-closing angles, then a closing angle.
Assuming grep works the same as flex.

edit: Actually I narrowed down the problem. Say I had the following input file.

code:
<not ^F valid>
<test1>hello
<test2>
My code is hitting the invalid detection line:
code:
\<[[:print:]]*[^[:print:]][^>]*\>
My code is saying the newline character after "hello" is not a valid character (It is matching the string <test1>hello\n<test2>). How can I make the match stop after it hits the > after test1?

Super Dude fucked around with this message at 04:37 on Sep 5, 2011

shrughes
Oct 11, 2008

(call/cc call/cc)
What is EPOLLPRI?

Looking at the epoll_ctl documentation, we see...

quote:

The events member is a bit set composed of the following available event types:

EPOLLIN
The associated file is available for read(2) operations.

EPOLLOUT
...
...

EPOLLPRI
There is urgent data available for read(2) operations.

What constitutes "urgent data"?

Edit: Oh my god, TCP supports the notion of "urgent data" and reserves 2 bytes in its header for this purpose. Nice going, TCP.

shrughes fucked around with this message at 06:34 on Sep 5, 2011

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
telnet uses it! It's mostly just feature bloat, though.

pseudorandom name
May 6, 2007

Yeah, just keep pretending urgent data doesn't exist.

Unless you're implementing Telnet.

e:fb

Zombywuf
Mar 29, 2008

I for one like having my keystrokes buffered.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Zombywuf posted:

I for one like having my keystrokes buffered.

You turn off Nagling to stop that, not set priority bits that basically everything ignores

Mr. Crow
May 22, 2008

Snap City mayor for life
This is probably really obvious but, is there some sort of pattern for a client/service application (it's not online, though it might be extended in the future) to easily call methods across the service?

Right now we're using strings to basically map out "Hey I want to call this function", and I'm converting everything to a system using enums so you can't fat-finger it but both seem like there really should be an easier/better way to go about it.

Mr. Crow fucked around with this message at 17:18 on Sep 6, 2011

tef
May 30, 2004

-> some l-system crap ->
http://en.wikipedia.org/wiki/Remote_procedure_call

you're slowly writing your own RPC mechanism. most languages platforms have existing solutions and there are a few cross platform ones too.

nothing really stands out but if you get to control both ends it is best to go with something native to the platform you're using

edit: fwiw there are lots of different styles of connecting up software - rest, rpc, messaging. and pros/cons of each

tef fucked around with this message at 18:08 on Sep 6, 2011

Mr. Crow
May 22, 2008

Snap City mayor for life

tef posted:

http://en.wikipedia.org/wiki/Remote_procedure_call

you're slowly writing your own RPC mechanism. most languages platforms have existing solutions and there are a few cross platform ones too.

nothing really stands out but if you get to control both ends it is best to go with something native to the platform you're using

edit: fwiw there are lots of different styles of connecting up software - rest, rpc, messaging. and pros/cons of each

That's what I was looking for, was reading up on it a day or two ago and I couldn't remember what it was called.

I take it I would basically have to completely re-work their system to implement anything though correct? Think that's why I shot the idea down when I read about it. It's a huge legacy system so the whole hardwired string stuff is in there in the finest detail, and I'm basically only re-working one application within the entire system. Would there be some kind of basic solution I could use to "wrap in" to what is already there (.NET Remoting?) or is that kind of defeating the purpose?

Mr. Crow fucked around with this message at 18:51 on Sep 6, 2011

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Mr. Crow posted:

That's what I was looking for, was reading up on it a day or two ago and I couldn't remember what it was called.

I take it I would basically have to completely re-work their system to implement anything though correct? Think that's why I shot the idea down when I read about it. It's a huge legacy system so the whole hardwired string stuff is in there in the finest detail, and I'm basically only re-working one application within the entire system. Would there be some kind of basic solution I could use to "wrap in" to what is already there (.NET Remoting?) or is that kind of defeating the purpose?

You probably could (if it's already .NET based you're already halfway there) but I'm guessing the people who architected/maintained the original system will freak out about it. These systems generally evolve because:
a)The system is so old RPC wasn't usable
b)The initial implementer was completely insane
c)A legacy app that doesn't support a global RPC protocol had to be supported

So unless one of those conditions has gone away I doubt you could get away with it; this is speaking 'politically' mind you. If you've got the juice go for it!

No Safe Word
Feb 26, 2005

Mr. Crow posted:

That's what I was looking for, was reading up on it a day or two ago and I couldn't remember what it was called.

I take it I would basically have to completely re-work their system to implement anything though correct? Think that's why I shot the idea down when I read about it. It's a huge legacy system so the whole hardwired string stuff is in there in the finest detail, and I'm basically only re-working one application within the entire system. Would there be some kind of basic solution I could use to "wrap in" to what is already there (.NET Remoting?) or is that kind of defeating the purpose?

Just go whole hog and enterprise the poo poo out of it

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Sulk posted:

I definitely wasn't looking for anything at an enterprise level or even a full time job right now, but for general knowledge and functionality, I suppose. I do wonder if Perl would be a better choice than Python, but as far as my creative side goes, I feel like Objective C might be useful. Just not sure which is why I thought to ask.
Learn all of them. Each of them will help your understanding of the others.

ColdPie
Jun 9, 2006

I have a dumb language theory/implementation question.

Why can't I do this in any language I know of?

pre:
void do_something(void)
{
    //do something
}

void init_then_do_something(void)
{
    //do some init
    return do_something();
}
That is, have a void function "return" another void function. I can't think of any reason not to allow it, and it makes refactoring easier should I want to add a return value to these functions, as I won't have to modify the body of init_then_do_something() at all. So, why can't I do this?

double sulk
Jul 2, 2010

Misogynist posted:

Learn all of them. Each of them will help your understanding of the others.

What's a very good, recent Python book or online tutorial? I'm not a huge fan of Learning Python the Hard Way because of how the author makes you learn something. The thread for Python didn't ever seem to have much.

Adbot
ADBOT LOVES YOU

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

ColdPie posted:

That is, have a void function "return" another void function. I can't think of any reason not to allow it, and it makes refactoring easier should I want to add a return value to these functions, as I won't have to modify the body of init_then_do_something() at all. So, why can't I do this?

This is valid in C++, and GCC and Clang allow it in C as an extension, only warning if you turn on -pedantic.

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