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
het
Nov 14, 2002

A dark black past
is my most valued
possession
My freshman high school CS classes actually started with functional Logo, though honestly I don't think any of us appreciated what that meant, it largely seemed like a tool to teach recursion at the time.

Adbot
ADBOT LOVES YOU

kitten smoothie
Dec 29, 2001

evensevenone posted:

I don't think it's really that surprising. Functional languages are kind of trendy for first-year CS education right now, but it's hardly all schools that do it that way or some kind of fundamental requirement of a CS program. Lots of places still use Java or some combination of Python, C and C++. Some places even use Lisp.

And if the intro courses aren't in a functional language, then probably the only courses that would use it are upper division electives that not everyone takes.

Is that a new trend? If so what's old is new again. My university's CS program originally used Scheme and SICP for the first year intro courses, but switched to Java in 1998, the year before I started there. The rest of the sequence was extremely theory-heavy and outside of learning C++ in an OO design course, any "practical" knowledge you got, you had to get on your own. As a result, people who graduated without having done internships were pretty well screwed on job prospects. (that said, I have zero problem with a theory-heavy program)

I did not see a functional language in coursework until my third year. I took a course on deeper fundamentals of programming languages, where over the course of the semester you'd end up with an interpreter for a toy language and you'd implement it in Scheme.

The course was a requirement for the computer science degree; however it was a 400 level class and due to the mess of trying to schedule all your requirements, most people didn't take it until their third or fourth year.

Tesseraction
Apr 5, 2009

My degree taught Java for the first two years and then did a combined 'Operating Systems and C/C++' module in year 3 which was about as effective as you might expect when you try and teach too much too quickly. When I'd finished that course you'd be lucky to get me to produce code that didn't segfault if it was more complicated than Hello World.

We were given the choice between Haskell or Prolog in the second year, though. The Haskell course was pretty good but it only taught you to use monads, not understand them, and never use them for more than IO or ordered instructions.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Shinku ABOOKEN posted:

Actually she is right. Freshman and Sophomore year are usually full of 101 courses from different unrelated majors (mandatory electives).

Also, CS programs have many courses that require prerequisites and as such you can't take them early.

Not to mention scheduling problems, professor availability, and seat availability.

Eh, okay buddy. Went to school too. People reaching their third year without going into an intro language course is what I am surprised about.

Oddly enough my school actually taught Scheme for intro classes ~13 years ago. This was right after they dumped C++ as the AP language which caused most of the other universities to switch over to Java as well. Oddly enough, I tested out of the intro class so instead I was put into a class that taught Java which they didn't have an intro course on.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


People go...to college...for programming? :confused:

Megaman
May 8, 2004
I didn't read the thread BUT...

Doc Hawkins posted:

People go...to college...for programming? :confused:

If you want to learn Java, because that's all they teach for some silly reason.

Westie
May 30, 2013



Baboon Simulator

Doc Hawkins posted:

People go...to college...for programming? :confused:

This also confuses me.

I was being served by a guy in Morrisons (uh, it's a superstore for you foreign, Nick Griffin hated folk) who was studying game development.

He had jumped straight into the uni (what could be called 'college' for Americans) course without any programming knowledge at all.

Surely you should have a knowledge of at least some sort of programming before you join, like, gently caress, you need a good grasp of Maths before you start a degree in Pure Maths, right?

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
When the most advanced computer class your high school offers is Introduction To Excel, yes, you may need some programming guidance in university.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Pretty sure they do the intro to programming courses so they can be sure everyone has a baseline knowledge. Seems to me to be preferable to trying to teach functional programming to autodidacts of the school of Rasmus Lerdorf.

Westie
May 30, 2013



Baboon Simulator

carry on then posted:

Pretty sure they do the intro to programming courses so they can be sure everyone has a baseline knowledge. Seems to me to be preferable to trying to teach functional programming to autodidacts of the school of Rasmus Lerdorf.

I'm slightly offended by that.

You're right though, personal experience (IE: what I do as a job) says it's 100% true, although I've been thinking of giving Erlang a bash - who needs ifs!

abraham linksys
Sep 6, 2010

:darksouls:

Misogynist posted:

This code just turned up in some code I'm writing to integrate Crossroads.js with Backbone :(

code:
// Trust me, works great!
Router.extend = Backbone.Model.extend;

Weird. Router already has the generic "extend" helper: http://backbonejs.org/docs/backbone.html#section-196 Oh, I just looked up Crossroads and realized Router is probably a non-Backbone router :v: In that case, if they really want the extend helper, it's not a "public"/exported/global'd helper in Backbone, so I suppose that's one way of doing it.

Curious, how is that integration going? I'm extremely frustrated with Backbone's lovely router, having been used to Ember's wonderful, promise-ified, basically magical router, and have been looking for an escape. I've been considering trying to get router.js (which Ember's router is built on) working with Backbone, but that seems like a dark road to go down.

abraham linksys fucked around with this message at 01:41 on Jan 26, 2014

shrughes
Oct 11, 2008

(call/cc call/cc)

Westie posted:

Surely you should have a knowledge of at least some sort of programming before you join, like, gently caress, you need a good grasp of Maths before you start a degree in Pure Maths, right?

The math prerequisite education (i.e. pre-calc) is supplied by universities for those who need it and is also provided for free by virtually all first-world high schools. You probably want to take pre-calc or at least some trig before starting calculus. Meanwhile you only need a basic grasp of algebra to get started programming or started with a CS degree, and high schools are typically awful at teaching intro CS or programming. Programming just has a lot less scaffolding, you don't need general knowledge about real numbers or anything.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Doc Hawkins posted:

People go...to college...for programming? :confused:

One of the best programmers I ever had the pleasure of working with learned programming by starting with CS 101 at his university. He had never written a single line of code before then.

The common stereotype of "you had to do it your entire life or you're a worthless piece of poo poo" isn't true, and it only discourages those who want to start learning in university. It needs to stop.

Practice and dedication are what's important, not at what age you first typed "hello world".

Jewel
May 2, 2009

Suspicious Dish posted:

One of the best programmers I ever had the pleasure of working with learned programming by starting with CS 101 at his university. He had never written a single line of code before then.

The common stereotype of "you had to do it your entire life or you're a worthless piece of poo poo" isn't true, and it only discourages those who want to start learning in university. It needs to stop.

Practice and dedication are what's important, not at what age you first typed "hello world".

Which is true for any skill. I see it in Art the most, too many people saying "well, I didn't start when I was six years old so I'll never be good" and quit or never begin. I've seen some people start at the age of 25 and within 5 years end up in art galleries. It's about effort, determination, and productive/targeted practice.

QuarkJets
Sep 8, 2008

If anything, teaching yourself is a good way to learn bad habits that have to be broken later. There's nothing wrong with a good formal education (although there's plenty of opportunity for bad formal education, too)

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Suspicious Dish posted:

The common stereotype of "you had to do it your entire life or you're a worthless piece of poo poo" isn't true, and it only discourages those who want to start learning in university. It needs to stop.

Practice and dedication are what's important, not at what age you first typed "hello world".

I agree! I personally didn't start until I was a few years out of college.

The joke was supposed to be about how people like me can get good careers with absolutely no formal education in the field, but apparently I am the humor-horror as well as the regular kind. :(

Tesseraction
Apr 5, 2009

QuarkJets posted:

If anything, teaching yourself is a good way to learn bad habits that have to be broken later. There's nothing wrong with a good formal education (although there's plenty of opportunity for bad formal education, too)

I think that your point here also touches on the fact that 'formal education' isn't the solution, really. Just like you say you can get good and bad formal education, you can get good self-taught and bad self-taught people. It's more about your interest in exploring what you're learning. I'd struggle to name an influential CS figure who wasn't primarily self-taught in their field of excellence.

Although I'll agree that for most of us mediocre programmers formal education is better than loving things up because of ignorance.

QuarkJets
Sep 8, 2008

But it's also true that a lot of those influential CS figures were learning programming back when there wasn't much formal education available.

evensevenone
May 12, 2001
Glass is a solid.
Stanford didn't even have an undergraduate CS program until the mid-80s.

Coffee Mugshot
Jun 26, 2010

by Lowtax
College courses that teach programming all vary wildly in structure in content with the only constant being that their structure and content almost assuredly sucks. Please do not ruin my world view with stories of your Stanford, MIT, and CMU CS courses, those obviously do not count.

For a related coding horror, I present some mime-type checking code I wrote for a school project where we had to make an application with the minimal functionality of Google Docs:

code:
function is_media_format($fileType, $fileName) {
  return (strstr($fileType, "video/") != false || 
          strstr($fileType, "audio/") != false || 
          strpos($fileName, ".webm") != false || 
          strpos($fileName, ".wmv") != false ||
          strpos($fileName, ".mkv") != false ||
          strpos($fileName, ".mp3"));
}
Honestly, I don't know how you're really supposed to do this anyways, but I know this isn't the right solution.

Speaking of compiler horrors in uni, we had to write an Android->JS transcompiler, so I chose to generate Coffeescript and compile that into JS using the `coffee` tool. To support overloaded functions in Coffeescript (since we used an ANTLR Java grammar and didn't know anything about Android), I mapped all function names of a class to a set of definitions of different argument lengths and parameter lists and in the generated Coffeescript I defined each class function by switching on argument length and then doing type checking on each argument for each length case.

Basically, the following code in Java:
code:
public class MultipleConstructor
{
        MultipleConstructor()
        {
        }
        MultipleConstructor(int a , int b, int c, int d)
        {
        }
}
would turn into this "equivalent" Coffeescript code:

code:
class MultipleConstructor
    MultipleConstructor:() ->
        switch arguments.length
            when 0
                ;
            when 1
                if a is Int and b is Int and c is Int and d is Int
                    ;

TL;DR: I'm a bad programmer and I apologize.

FamDav
Mar 29, 2008

Voted Worst Mom posted:

Honestly, I don't know how you're really supposed to do this anyways, but I know this isn't the right solution.

a set.

quote:

Speaking of compiler horrors in uni, we had to write an Android->JS transcompiler, so I chose to generate Coffeescript and compile that into JS using the `coffee` tool. To support overloaded functions in Coffeescript (since we used an ANTLR Java grammar and didn't know anything about Android), I mapped all function names of a class to a set of definitions of different argument lengths and parameter lists and in the generated Coffeescript I defined each class function by switching on argument length and then doing type checking on each argument for each length case.

if you weren't expected to have your output code work with other bits of javascript, you could've just output however many different versions of a function with a separate unique identifier. ex. getBones(Int,Int,Int) and getBones(List,List,List) would become getBonesIntIntInt and getBonesListListList (or something less brittle).

Coffee Mugshot
Jun 26, 2010

by Lowtax

I'm referring to actually populating that set to catch the correct video formats. It seemed like a "video/" filetype would be a catchall for videos. I just added the four other on, but I never tested whether any vulnerabilities could happen and I found out a couple of years later (with the site running on my linode still for some reason) that it was vulnerable to this old PHP hack since I couldn't think of better ways to find out if a file was really a video/audio file or not.

FoiledAgain
May 6, 2007

Back a few pages people were complaining about using exceptions for control flow. Here's some code you'll love:

code:
user_input = some_function()
#this returns either a string or a tuple
passed = False
try:
    user_input += ''
    #12 more lines of code for dealing with the case of a string
    passed = True
except TypeError:
    #15 lines of code for dealing with the case of a tuple
    passed = True
finally:
    if not passed:
        raise AttributeError('input needs to be a string or tuple')

theratking
Jan 18, 2012

FoiledAgain posted:

Back a few pages people were complaining about using exceptions for control flow. Here's some code you'll love:

This is exactly what I fear people really mean when they boast about their increased productivity with dynamically typed languages.

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.
But It's Better To Ask Forgiveness than Permission, wouldn't want to mess up that lovely duck typing!

Crosscontaminant
Jan 18, 2007

I'm inclined to think the horror is that the function's return type is one of multiple things - just because there's no restrictions on the return type for the function doesn't mean you should just return whatever sludge you come up with and let the caller sort it out.

Presumably "string or tuple" is an abbreviation of "string or tuple of strings" - just return a tuple with one element, it's probably closer to the semantics of the function in question ("returns all names matching a particular search query" or something of the sort) and means you don't have to play silly games to work out how to process the return value.

e: that said, I can acknowledge a deficiency in Python in that its tuples and lists are too similar given that there's a cultural expectation that they have different semantics. There should be a dedicated record type, freeing up tuples to be an invisible type for varargs and multiple assignments, and lists should be prohibited from containing heterogeneous data.

Crosscontaminant fucked around with this message at 05:44 on Jan 29, 2014

FoiledAgain
May 6, 2007

Crosscontaminant posted:

Presumably "string or tuple" is an abbreviation of "string or tuple of strings" - just return a tuple with one element, it's probably closer to the semantics of the function in question ("returns all names matching a particular search query" or something of the sort) and means you don't have to play silly games to work out how to process the return value.

No, it's either a string or a tuple of integers. This is from a simulation (this is an academic's code), and this part generates some objects for use in the simulation. There are only three kinds of objects. A tuple means the user wants to randomly generate them, with each of the numbers in the tuple representing how many of each kind of object, e.g. (10,3,5) means 10 objects of the first type, 3 of the second type, and 5 of the third. If the user gives a string, it's the name of a file that has specific information about how to generate the objects rather than doing it randomly.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
C code:
       else
       {
         // This cannot happen
-        assert(0);
+        //assert(0); LOL maybe it can...
       }

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Aleksei Vasiliev posted:

C code:
       else
       {
         // This cannot happen
-        assert(0);
+        //assert(0); LOL maybe it can...
       }

The real coding horror is that someone wrote "LOL" in your codebase

EAT THE EGGS RICOLA
May 29, 2008

Volmarias posted:

The real coding horror is that someone wrote "LOL" in your codebase

https://github.com/search?q=LOL&type=Code&ref=searchresults

:smith:

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

Aleksei Vasiliev posted:

C code:
       else
       {
         // This cannot happen
-        assert(0);
+        //assert(0); LOL maybe it can...
       }

Ugh. So many problems with this it hurts. :smith:

Large Hardon Collider
Nov 28, 2005


PARADOL EX FAN CLUB
Of course it's all PHP.

substitute
Aug 30, 2003

you for my mum
php:
<?
/**
 * myFunction()
 * @param  whatever $var
 * @return something, hopefully ;)
 */
public myFunction($var) 
{ 
...
}
?>

Strong Sauce
Jul 2, 2003

You know I am not really your father.






Interesting that XML is #2 mostly because of the billion laughs exploit.

substitute
Aug 30, 2003

you for my mum
When in doubt, just wrap it in a <div>. Within another <div>. Within another <div> Ad nauseam.

(I hate the "senior" graphic designer at my work.)

pre:
<div id="title" class="section">
	<div class="content txt-center maxwidth400">
		<h2>Welcome to BLAH BLAH BLAH.</h2>
	</div>
</div>
<div id="login" class="section">    
	<div class="content">
		<div class="form-container"> 
			<form name="loginForm" id="loginForm" action="/menu" method="post" data-eval="true">
				<label>Enter your email address</label>
				<input name="username" value="" type="email">
				<label>Enter your Password</label>
				<input name="password" value="" type="">  
				<p class="forgot-password"><a href="#">Forgot password.</a></p>
				<input name="submitHandler" class="submit" value="Login" type="submit">
			</form>
		</div>
	<p class="create-profile"><a href="/account/create.php">Create profile</a></p>
	</div>
</div>

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

substitute posted:

When in doubt, just wrap it in a <div>. Within another <div>. Within another <div> Ad nauseam.

(I hate the "senior" graphic designer at my work.)

pre:
<div id="title" class="section">
	<div class="content txt-center maxwidth400">
		<h2>Welcome to BLAH BLAH BLAH.</h2>
	</div>
</div>
<div id="login" class="section">    
	<div class="content">
		<div class="form-container"> 
			<form name="loginForm" id="loginForm" action="/menu" method="post" data-eval="true">
				<label>Enter your email address</label>
				<input name="username" value="" type="email">
				<label>Enter your Password</label>
				<input name="password" value="" type="">  
				<p class="forgot-password"><a href="#">Forgot password.</a></p>
				<input name="submitHandler" class="submit" value="Login" type="submit">
			</form>
		</div>
	<p class="create-profile"><a href="/account/create.php">Create profile</a></p>
	</div>
</div>

He should use HTML5 and make that last one a SECTION. :colbert:

evensevenone
May 12, 2001
Glass is a solid.

FoiledAgain posted:

No, it's either a string or a tuple of integers.

This is what is really the problem, not the exceptions. You're basically trying to pass data via the type system. This will always end up being a mess--you're either going to have to use try/except, or you're going to have to use something like type() or isinstance(), which can also be fragile. Any time a method returns multiple types, and the client is then supposed to infer meaning from the type is really suspicious.

The python way would be to just return the data already built. If that doesn't work (because it takes a long time or whatever), return an object that has a build() method or something that either builds the test data or loads it from a file. The point of duck typing is not really that you can return a string or a tuple and base later code off of the type, it's that you can pass and return in objects of different types that share an interface (or the subset of the interface that you actually need).

Tesseraction
Apr 5, 2009

I wonder if the original version of that code had them calling open() on Schrödinger's variable and catching the TypeError exception if it's a tuple.

FoiledAgain
May 6, 2007

evensevenone posted:

This is what is really the problem, not the exceptions. You're basically trying to pass data via the type system. This will always end up being a mess--you're either going to have to use try/except, or you're going to have to use something like type() or isinstance(), which can also be fragile. Any time a method returns multiple types, and the client is then supposed to infer meaning from the type is really suspicious.

The python way would be to just return the data already built. If that doesn't work (because it takes a long time or whatever), return an object that has a build() method or something that either builds the test data or loads it from a file. The point of duck typing is not really that you can return a string or a tuple and base later code off of the type, it's that you can pass and return in objects of different types that share an interface (or the subset of the interface that you actually need).

I agree. I went a looked at little more at the code, and here's why you end up with two different types:
For this simulation, users write a configuration file, which is just a text file with parameter=value on each line. The parameter 'objects' can take as a value either the name of a file that lists the specific objects you want to use (every possible object in the simulation has a unique ID) or else it can be three comma separated numbers indicating you want a random choice of objects. A parse_args() function reads the config file and returns either a string or a tuple back to the function that I referenced in my other post (actually it return a dictionary because there are other parameters too, but there is no weirdness in dealing with them so I left it out of the post). The try/except block is then used to figure out if it's a tuple or a string, and then either go read a file or do some random generation.

Adbot
ADBOT LOVES YOU

Look Around You
Jan 19, 2009

Aleksei Vasiliev posted:

C code:
       else
       {
         // This cannot happen
-        assert(0);
+        //assert(0); LOL maybe it can...
       }

I like how instead of letting it keep crashing and figuring out why "this cannot happen" happened, they just decided to say "gently caress it, let's keep on trucking" with the program in a potentially catastrophically invalid state.

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