Jump to content

Wikipedia:Reference desk/Archives/Computing/2010 July 2

From Wikipedia, the free encyclopedia
Computing desk
< July 1 << Jun | July | Aug >> July 3 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


July 2

[edit]

Does scala really have dynamic types?

[edit]

I have only just started to play with Scala, so I am probably doing things the wrong way. I decided to convert a Java program that demonstrates that Javea is statically typed

class A {
	
	def f(param: P): String = {
		return "A.f(P)";
	}
}

class B extends A {
	override def f(param: P): String = {
		return "B.f(P)";
	}
	
	def f(param: Q): String = {
		return "B.f(Q)";
	}
}

case class P  
case class Q extends  P

		
object TestApp {
	
	def main(args: Array[String]) {
		val  pRefingP: P = new P();
		val  pRefingQ: P = new Q();
		val  qRefingQ: Q = new Q();
		
		val  aRefingA: A = new A();
		val  aRefingB: A = new B();
		val  bRefingB: B = new B();

		
		println("\t\t|\tP referencing P\t|\tP referencing Q\t|\tQ referencing Q");
		println("A referencing A\t|\t" + aRefingA.f(pRefingP)
				+ "\t\t|\t" + aRefingA.f(pRefingQ) + "\t\t|\t"
				+ aRefingA.f(qRefingQ))
		println("A referencing B\t|\t" + aRefingB.f(pRefingP)
				+ "\t\t|\t" + aRefingB.f(pRefingQ) + "\t\t|\t"
				+ aRefingB.f(qRefingQ))
		println("B referencing B\t|\t" + bRefingB.f(pRefingP)
				+ "\t\t|\t" + bRefingB.f(pRefingQ) + "\t\t|\t"
				+ bRefingB.f(qRefingQ))

	}
}

The output of this is the same as for Java:

		|	P referencing P	|	P referencing Q	|	Q referencing Q
A referencing A	|	A.f(P)		|	A.f(P)		|	A.f(P)
A referencing B	|	B.f(P)		|	B.f(P)		|	B.f(P)
B referencing B	|	B.f(P)		|	B.f(P)		|	B.f(q)

Now You can achieve the result with a patern match:

class A {
	
	def f(param: P): String = {
		return "A.f(P)";
	}
}

class B extends A {
	override def f(param: P): String = {
			param match {
				case e:Q => return("B.f(Q)");	
				case e:P => return("B.f(P)");
			}
	}
}

case class P  
case class Q extends  P

		
object TestApp {
	
	def main(args: Array[String]) {
		val  pRefingP: P = new P();
		val  pRefingQ: P = new Q();
		val  qRefingQ: Q = new Q();
		
		val  aRefingA: A = new A();
		val  aRefingB: A = new B();
		val  bRefingB: B = new B();

	println("\t\t|\tP referencing P\t|\tP referencing Q\t|\tQ referencing Q");
		println("A referencing A\t|\t" + aRefingA.f(pRefingP)
				+ "\t\t|\t" + aRefingA.f(pRefingQ) + "\t\t|\t"
				+ aRefingA.f(qRefingQ))
		println("A referencing B\t|\t" + aRefingB.f(pRefingP)
				+ "\t\t|\t" + aRefingB.f(pRefingQ) + "\t\t|\t"
				+ aRefingB.f(qRefingQ))
		println("B referencing B\t|\t" + bRefingB.f(pRefingP)
				+ "\t\t|\t" + bRefingB.f(pRefingQ) + "\t\t|\t"
				+ bRefingB.f(qRefingQ))

	}
}

This gives the expected result:

		|	P referencing P	|	P referencing Q	|	Q referencing Q
A referencing A	|	A.f(P)		|	A.f(P)		|	A.f(P)
A referencing B	|	B.f(P)		|	B.f(Q)		|	B.f(Q)
B referencing B	|	B.f(P)		|	B.f(Q)		|	B.f(Q)

This is not really dynamic dispatch though, the same thing could be achieved in Java by testing instanceof in the overridden method. I understood that Scala was a dynamic language, is this wrong? -- Q Chris (talk) 13:50, 2 July 2010 (UTC)[reply]

To answer your question's title, no Scala doesn't have dynamic types. (see Scala (programming language)#Static_typing) It does have dynamic dispatch, just like Java. I scanned through the source you posted, and perhaps the language feature you are looking for is Multiple dispatch, aka. multimethods? Zigorney (talk) 14:52, 2 July 2010 (UTC)[reply]

Website

[edit]

I want to host a small website on my home computer, with a number of pages, images etc, probably 50mb total size. Will 40 KB/s upload speed be way too slow? That's all my ISP gives me (btw I've checked if I'm allowed to host a site, and they said I am) 82.43.90.93 (talk) 16:42, 2 July 2010 (UTC)[reply]

It really depends on the images, and the amount of viewers you are excepting. If this is a site for a limited audience, and you won't usually get many viewers at the same time, and you're not hosting high resolution photos or screen captures, it should be okay. Also, if it's just HTML and images, it's easy to transfer to another host if things seem too slow. So no harm in trying.
If you'd like to tell us more about what your site is all about, I'm sure we can help more on the specifics. If you want photos, for example, there's plenty of free photo hosting sites out there, which allow you to embed the photo in your own page, saving your upload bandwidth. Zigorney (talk) 18:36, 2 July 2010 (UTC)[reply]
It sounds to me as if you want your ISP to host your website. I'll assume for now that this is so. You don't suggest that your site is one to which viewers will be able to contribute. If they indeed won't, then the only person affected by upload speed will be yourself -- the speed will neither affect nor be affected by the number of people who view the site. Now some simple division: fifty thousand kilobytes at forty kilobytes per second. Is the quotient OK for you? -- Hoary (talk) 20:07, 2 July 2010 (UTC) ...... PS Uh, not quite. The upload speed will be forty kilobits per second, so multiply the time by eight. No, by ten or so, to account for error-checking and so forth. -- Hoary (talk) 23:09, 2 July 2010 (UTC)[reply]
Good call, this might very well be about hosting space offered by the ISP. I hope we'll hear more from the questioner. Zigorney (talk) 20:24, 2 July 2010 (UTC)[reply]
The way I interpreted the question, I think the OP is a subscriber to a residential broadband service, and plans to host the server in his/her own home. This means his/her "upload" speed is important - every page queried will be transfered via the ISP connection to the client at the "upload" speed. For this, 40 kbps is functional but it is not "high-performance." You might want to know that commercial hosting is pretty darned cheap - ~ $4 US per month nowadays, which is probably less than you will spend on electricity if you host the server in your closet. Nimur (talk) 20:27, 2 July 2010 (UTC)[reply]
And if all you are hosting are a few pages with a few images, you might as well just use Google Documents for free, no? It seems to me like a silly thing to waste one's up speed on, or to worry about security issues, etc. --Mr.98 (talk) 21:03, 2 July 2010 (UTC)[reply]
Unless it is for learning-purposes, or if you have special software/hardware needs, etc. Nimur (talk) 21:11, 2 July 2010 (UTC)[reply]
In addition the OP didn't say anything about security issues so perhaps they it's something they feel they have under sufficient control. Also in the past, the OP has mentioned having problems signing up to Gmail because of the requirements for a mobile phone in the UK which may make problems signing up for Google Docs but I'm under the impression Google have changed their policies anyway and actually I can't recall why the OP had no luck with the plenty of sites offering Google invites that I think existed at the time. There are of course plenty of free hosting services which provide various features and degrees of reliability so as with Nimur perhaps the OP has reasons for wanting to host the site themselves. (Besides what Nimur has explicitly mentioned an obvious one would be being uncomfortable with the privacy policies and/or history of the free hosting services, if you host it yourself while I can't stop people visiting it then doing dodgy stuff with it, at least you haven't potentially given them rights you have no desire to.) Nil Einne (talk) 17:03, 3 July 2010 (UTC)[reply]

Audio Voiceover In Videos

[edit]
Resolved

I'm putting some gameplay videos up on YouTube and various other websites, and a mate of mine has suggested that it might be better to add a voiceover - essentially to explain what I'm doing. Is there any software available (either for free or I already have it with Vista) that would accomplish this for me? I would prefer to record the screenplay of the game first, then record a voiceover to add to it later, not simultaneously (as XFire would allow). TIA! --KägeTorä - (影虎) (TALK) 22:53, 2 July 2010 (UTC)[reply]

I suggested he record the voice separately and glue the voice to the video using Windows Movie Maker. We just don't know how to record the voice. Vimescarrot (talk) 23:08, 2 July 2010 (UTC)[reply]

No, 'gluing' it is the problem. I have plenty of softwares that allow me to record audio. But thanks for the clarification. --KägeTorä - (影虎) (TALK) 23:26, 2 July 2010 (UTC)[reply]
Wait, what? (for clarification, I'm the mate who he discussed this with, although he doesn't seem to realise this.) Gluing it is the easy part. You just open the audio file and the movie in WMM and...well, yeah. Vimescarrot (talk) 11:14, 3 July 2010 (UTC)[reply]
That is what I'm on about! :) How!? It needs to be in synch with what's happening on the video - so, I suppose I should be asking 'will it be?'. --KägeTorä - (影虎) (TALK) 13:39, 3 July 2010 (UTC)[reply]
Watch the video while you're recording the audio, then what you say will be in synch with what's happening. Then just fuse the two with WMM. 'course they'll be in synch, as long as you were in synch when you were talking. At this point I'm very confused about what you're asking. Vimescarrot (talk) 13:46, 3 July 2010 (UTC)[reply]

Okeedokee. Let's take this back to MSN because it seems we're the only ones talking about this. --KägeTorä - (影虎) (TALK) 13:54, 3 July 2010 (UTC)[reply]