Open Side Menu Go to the Top

07-12-2013 , 01:47 PM
apologize for the fish question, but can anybody explain the difference between comprehension and generators? i don't understand the concept of generators, except that they are neither a tuple, nor a list, nor a set.

thanks!

eg: why would:

Code:
list(x**2 for x in range(100))
be less expensive than:

Code:
[x**2 for x in range(100)]
also the difference between xrange and range; i vaguely understand that one is stored memory and one isn't. and that xrange only works one at at time i think? which is therefore more efficient?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
07-12-2013 , 01:52 PM
assume i know basically nothing about computers, memory, processing, or storage. because that is pretty much true.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-12-2013 , 02:26 PM
Going backwards, the difference between xrange and range in Python 2 is something like "I'm going to count to 10,000" and "I'm going to write every number from 1 to 10,000, spread the paper on my desk and read the series of numbers off the paper".

The code samples you wrote are basically equivalent because you end up with the whole list either way. The difference comes when you write something like this:

Code:
sum(x**2 for x in xrange(100))
In this version, the computer pulls values out of the generator one at a time and adds them to its running total. It never has all 100 integers in memory because it doesn't need to. If we instead write this:

Code:
sum([x**2 for x in range(100)]
First it creates the numbers 0-99 and builds a list. Then it squares each value and builds another list. Then it finally adds the numbers in that list together. The first one scales really well because the computer never needs to have more than a few numbers in memory at once, while this one needs at least N numbers, which becomes a problem if N gets large.

EDIT: I just realized, the big thing I never said explicitly is that generators don't actually store their values; they just spit out values according to a rule when asked. Like, here's kind of a fake xrange (this is a runnable program and should give a vague idea what yield does):

Code:
def xrange(N):
    i = 0
    while i < N:
        yield i
        i += 1

for i in xrange(10):
    print i
That isn't quite the same thing, but it works similarly (you can even write the for loop using it). The important idea is that it behaves like a sequence of temporary values.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-12-2013 , 02:50 PM
ahhh i see what you mean.

so in the example you just described, the range function would be more like:

Code:
>>> def range_n(N):
	nset = []
	i = 0
	while i < N:
		nset.append(i)
		i += 1
	return nset

>>> range_n(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
xhad your explanation was fantastic btw thank you.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-12-2013 , 02:51 PM
yes, you have the right idea wrt what range does.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-12-2013 , 03:35 PM
Great explanation imo...but the syntax error still bothers me
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-12-2013 , 03:50 PM
And also, generators are only good for one use, and I really don't know why. That's just a broken feature of the language.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-12-2013 , 06:43 PM
Nchabazam,

Authentication is actually pretty complicated and annoying to implement, that's why I didn't roll my own but I think I might end up rolling my own soon.

There's a lot of crap to account for if you plan to support both creating new accounts and signing in with various third party sites like twitter/facebook.

There's a ton of edge cases involved with having a single user being able to login with twitter but at the same time if they logout and login with facebook or create a new account from scratch they should all be considered the same user by your system.

Then there's all the common and fairly straight forward (but still a lot of code) stuff for password resetting through e-mail, updating your settings (changing e-mails, etc.), lock outs based on invalid login attempts, saving secure tokens to a cookie for "remember me" and other stuff I'm probably forgetting.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-12-2013 , 07:51 PM
@Shoe,

Indeed.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-12-2013 , 08:15 PM
I'm going to base my hand rolled authentication on top of omniauth because it seems to be a great base for setting up a standard interface for the actual logging in part and receiving a standardized hash of user info.

Will have to think through and implement all of the tricky stuff though.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2013 , 12:07 AM
How do you ensure the user is the user in each instance?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2013 , 08:13 AM
I haven't given it a ton of thought yet but I think the only secure way of doing this is to have the user link in the additional providers in their settings page. I like this approach because it also allows them to have different e-mail addresses between providers.

So the idea would be you would have a user model that has many providers.

Most providers will return back an e-mail and if you use e-mail as your unique constraint on your users then you could throw directions at the user in most cases for when they use the same e-mail address across providers.

You could make the user experience pretty nice though for most cases. Something like "You have signed in with Facebook and the e-mail address returned matches a user in the system. If you would like to merge this login into your account then goto your settings page and add Facebook as a provider for this account".

If they want to use different providers and they use different e-mail accounts for each provider then there's really no reasonable way to handle this. You could store unique hashes of combinations of ip addresses, agent headers, etc. to try and find uniqueness but it seems like it would require doing 10000% the work for 0.001% of the cases.

I feel like the above paragraph could be solved with good tooltips aimed at the user. If they know they can goto their settings to merge providers into 1 account then they could do it themselves and the entire thing could be complete by clicking 1 button. Worst case scenario is it's a simple reply back to them if they happen to message you for support.

Luckily I don't have to deal with this bs for this project though. I'm just going to merge in omniauth and only use the local identity aspect of it (standard registration) since it's aimed for an admin panel. I'm looking forward to making a full solution though, I think it would make for a great base to use on almost any project that requires any form of authentication.

Last edited by Shoe Lace; 07-13-2013 at 08:19 AM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2013 , 08:58 AM
That seems like an anti-feature. Offering multiple options to login is good, but I have never had the need to use two at the same time. Can you even do this on sites like SO?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2013 , 11:55 AM
Quote:
Originally Posted by gaming_mouse
That seems like an anti-feature. Offering multiple options to login is good, but I have never had the need to use two at the same time. Can you even do this on sites like SO?
It's a convenience to the user. Now they don't have to remember which provider they used to sign in to your site. If they don't use it for a few months it's quite possible they will have forgotten. Making them play a guessing game with 5 providers is lame. If they go 0/4 now you have 4 dead accounts in your system too.

It also makes it painless to handle situations where either a provider is no longer accessible due to the service going down for good or maybe the user no longer has an account with them.

Rather than go into some type of maintenance mode where you fix users by hand and making it an announcement on your site you can fix the root of the problem so that it's not a problem at all.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2013 , 12:14 PM
Quote:
Originally Posted by Shoe Lace
It's a convenience to the user. Now they don't have to remember which provider they used to sign in to your site. If they don't use it for a few months it's quite possible they will have forgotten. Making them play a guessing game with 5 providers is lame. If they go 0/4 now you have 4 dead accounts in your system too.

It also makes it painless to handle situations where either a provider is no longer accessible due to the service going down for good or maybe the user no longer has an account with them.

Rather than go into some type of maintenance mode where you fix users by hand and making it an announcement on your site you can fix the root of the problem so that it's not a problem at all.
yeah i figured that was your reasoning, and you're right it would be nice for that 1 use case. but you introduce a ton of complexity to account for this one case. and it's most likely a tiny problem anyway.

but i checked and stackexchange does work that way, so i guess if you have the resources why not.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2013 , 02:55 PM
I'd rather have them pick one signup mechanism and stick to it for eternity (and also limit their choices to say three when they sign up). If I'd let them change login method it would be replace i.e. change from facebook to twitter not allowing both (and quite frankly this should happen rarely).
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2013 , 03:13 PM
I log into SO with my gmail credentials. I forgot the official password a long time ago. The way they do it is pretty simple and straightforward. Not sure how I feel about allowing people to sign in with several different other accounts, but at least in their case, it is pretty straightforward.

I think SO works solely because (I think?) you have to have an official account before logging in with another account, and those accounts are bound to the email.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-14-2013 , 07:10 AM
I want to get into programming and start off self-learning. Is there a textbook or something that I can buy that gives me assignments to work through to begin learning how to code. I've been searching on online and amazon, and all I have been able to find is books with just chapters of information. I'm looking for something more where I can get my hands dirty and learn through trial and error.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-14-2013 , 09:36 AM
What kind of programming?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-14-2013 , 10:52 AM


A classic! Is very good, and IIRC is sort of an "assignment driven" style.

Tho really I'd probably suggest trying some of these online courses (see thread here: http://forumserver.twoplustwo.com/19...lable-1235403/ ) or to find online docs from a University (search the google with "site:.edu" or "site:.ac.uk", e.g http://www.google.com/search?q=java+...ient=firefox-a or others) for the language you want.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-14-2013 , 11:23 AM
i don't think C is a good starting language. also isn't learncthehardway the cool book these days?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-14-2013 , 04:27 PM
CS50 is taught in C and ShoeLace took that. Not sure what he would think of C as a starter language.

K&R really isn't that good, IMO. There is a bit of questionable and non-working code in the book and the file i/o is outdated, for example. K&R is not meant to be a "learn to program" book and it states this in the opening pages. LearnCtheHardWay isn't meant to be a "learn to program" book either, and it states this in the opening pages.

There are at least 3 threads on the front page about how to start from zero and self-learn. Why ask this question?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-14-2013 , 04:36 PM
Quote:
Originally Posted by kerowo
What kind of programming?
The kind you would learn in a introductory programming course at college. Messing around with your basic functions and data types. I don't care if it is c++, java, python or whatever, I just want to get my feet wet in the coding process.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-14-2013 , 05:45 PM
Quote:
Originally Posted by animas
The kind you would learn in a introductory programming course at college.
Then why don't you just take one of those classes. There are dozens of them online for free. They're the exact same as the ones you would take at the University.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-14-2013 , 06:25 PM
Just go your favorite search engine and look for coursera, edx, and mit ocw. Find a class called "introduction to programming" or something close, then sign up and go for it.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m