Page 15 of 43

Re: Programming, computers, etc. [Serious]

Posted: Tue May 01, 2012 5:00 pm
by Dreams
Now that's just contradictory :(

Re: Programming, computers, etc. [Serious]

Posted: Tue May 01, 2012 7:29 pm
by Anonymously Famous
I think it will get more people to try Linux out (though live CDs are pretty cool, too).

Re: Programming, computers, etc. [Serious]

Posted: Tue May 01, 2012 8:39 pm
by atomtengeralattjaro
I've been spending the good part of today on learning linux bash scripting, I'm writing a test tomorrow..

Re: Programming, computers, etc. [Serious]

Posted: Wed May 02, 2012 4:16 pm
by Dreams
Good. Don't destroy system files.

Re: Programming, computers, etc. [Serious]

Posted: Wed May 02, 2012 7:06 pm
by Anonymously Famous
Bash scripting can be really powerful.

Re: Programming, computers, etc. [Serious]

Posted: Sun May 06, 2012 11:34 am
by atomtengeralattjaro
My flash sig seems to not work properly all of a sudden.. it stops between the last and the first image, i think. I'm just gonna change it to a simple image, i guess, I don't bother with bugs that come out of nowhere..

Re: Programming, computers, etc. [Serious]

Posted: Sun May 06, 2012 2:16 pm
by Anonymously Famous
Maybe an update to Flash?

Re: Programming, computers, etc. [Serious]

Posted: Thu May 10, 2012 10:06 pm
by atomtengeralattjaro
i'm writing a tough Assembly test tomorrow, wish me kind registers!

Code: Select all

mov bed,atomtengeralattjaro

Re: Programming, computers, etc. [Serious]

Posted: Fri May 11, 2012 2:29 pm
by Anonymously Famous
May your registers behave themselves.

Re: Programming, computers, etc. [Serious]

Posted: Fri May 11, 2012 4:30 pm
by atomtengeralattjaro
and so they did :) Fortunately we had enough time, and I think I passed. Only for some reason when the program drew a triangle, it also drew a bunch of other lines in other places.. :S i guess i lost my way in the video memory somehow.

Re: Programming, computers, etc. [Serious]

Posted: Fri May 11, 2012 7:41 pm
by Anonymously Famous
It's easy to get lost in assembly.

Re: Programming, computers, etc. [Serious]

Posted: Fri May 18, 2012 9:11 pm
by Anonymously Famous
I feel bad double posting, but I found out something interesting today.

First, the known facts:
In Python, everything has a "truthiness" to it. That is, logically, everything is either True or False. If it's None, False, 0, 0.0, or the length of it is 0, it's considered to be False. Everything else is True (including functions and classes).

What I found out:
The logical "and" and "or" in Python don't always return True or False. They return one of the operands. "and" returns the first operand if it's "False-like" and the second one otherwise. "or" returns the first operand if it's "True-like" and the second one otherwise. Sure, you can "cast" it as a bool, but if you don't, it can lead to some interesting side effects.

Examples:

Code: Select all

5 and "Bob"
is "Bob"

Code: Select all

5 or "Bob"
is 5

Re: Programming, computers, etc. [Serious]

Posted: Fri May 18, 2012 9:48 pm
by atomtengeralattjaro
this truthiness thingy is spooky. Do you know any scenarios where this can be used? i think it would just confuse me, but it does seem interesting.

Re: Programming, computers, etc. [Serious]

Posted: Sat May 19, 2012 2:07 am
by Anonymously Famous
Well, I don't know exactly when it would be used... It behaves exactly the way that you would expect it to in if statements and while loops. The truthiness thing exists in C/++, too. You can do "while(5){doStuffThatHopefullyEventuallyBreaksOutOfTheLoop();}". It only gets weird if you use it as a statement itself.

One possible use: Say you have 2 lists of Strings. The lists have the same length, just to make things simple. If an item in list1 is an empty string, you want to use the corresponding item from list2. There are several ways to do this. This is an unconventional one using "or":

Code: Select all

[i[0] or i[1] for i in zip(list1, list2)]
Here's one more like what you would expect:

Code: Select all

result = []
for i in range(len(list1)):
    if list1[i] != "":
        result.append(list1[i])
    else:
        result.append(list2[i])
Or, the same thing, as a list comprehension:

Code: Select all

[list1[i] if list1[i] != "" else list2[i] for i in range(len(list1))]
Still, it's just an oddity. If you want to force a boolean, you can use bool(a or b). It is a documented oddity. I just hadn't realized that it was there. Like I said, in most cases, it behaves as you would expect it to.

It also makes the implementation pretty easy, actually. For example:

Code: Select all

def customAnd(a,b):
    return a if not a else b

def customOr(a,b):
    return a if a else b
Voila! It all depends on the truthiness of a. In the implementation of the language, b isn't even evaluated unless it needs to be. I guess you could also use that side effect. For example:

Code: Select all

def printMe():
    print("Hello")
    return 0

def dontPrintMe():
    print("I should not print")
    return 1

printMe() and dontPrintMe() # This should only print "Hello"

Re: Programming, computers, etc. [Serious]

Posted: Sat May 19, 2012 10:01 am
by atomtengeralattjaro
woah..
i'm lost.
i have no idea about the whole syntax in your first example, and i don't even know what "zip" does :oops:
And the last one is just plain weird. But it makes sense. Took me a while to get it though..

Re: Programming, computers, etc. [Serious]

Posted: Sat May 19, 2012 1:29 pm
by Anonymously Famous
zip takes n lists and produces one list. That list contains tuples (which could be considered a special type of list) of n elements - one from each list. It's defined to stop at the end of the shortest list. so zip([1,2,3], [4,5,6]) would produce [(1,4), (2,5), (3,6)]. So in that look for strings example, it goes through each element in the zipped list, and does firstValue or secondValue. If firstValue seems False (i.e. It's the empty string), it uses the second value.

A modified first example (the C/++ code):

Code: Select all

if(5)
{
    cout<<"5 is considered to be \"True\" in C++";
}
In Python, "x if condition else y" is kind of their ternary (?) operator. If the condition is true, it results in x. If not, it results in y.

Re: Programming, computers, etc. [Serious]

Posted: Sat May 19, 2012 4:46 pm
by atomtengeralattjaro
I see! I think it's clear now.

Re: Programming, computers, etc. [Serious]

Posted: Fri Jun 01, 2012 10:26 pm
by Anonymously Famous
Speaking of Python...

I just learned of a site called Udacity today. It's kind of like an online school, with free online courses. It's not accredited, so you don't get a degree, but the instructors are university professors or professionals in their field. They're mostly programming classes, and the language used, as far as I can see, is Python 2.7 (though the theory learned is valuable regardless of the language). I may or may not have signed up today and enrolled in all of the classes. Simultaneously... Good thing there's no strict deadline! :)

Re: Programming, computers, etc. [Serious]

Posted: Sat Jun 02, 2012 1:05 pm
by atomtengeralattjaro
woah :o and it's free! as in free beer?

Re: Programming, computers, etc. [Serious]

Posted: Sat Jun 02, 2012 3:50 pm
by Anonymously Famous
It's free as in free online classes.