• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

MiszMasz

Member
Thanks for the pointer. I'm thinking of using games like these to get students warmed up for actual programming. So far I have Zachtronics' Spacechem ready to go, and TIS-100 is on my shopping list.

Depending on the ages we're talking, these are two i've used as part of a club i've been running at a local school for while:
Code Kingdoms
Code Combat

There's some optional paid stuff in the second one (extra levels, characters etc.) but it's not obnoxious or forcing payment input boxes in your face all the time or anything quite like that. Most of it's still free and it can be 'completed' for free.

There's also Hack 'n' Slash, and though it's not out yet, Quadrilateral Cowboy's been on my radar for a while.
 
Learning C# and WPF at the same time might have been a bad decision. Hard mode activated.

WPF is some kooky shit. Makes hard things easy, and easy things hard.

There's probably about 10 people in the world that can put a dynamic context menu on a tree view control in WPF.

But if you need your UI to animate all over the screen with shade effects and drop-shadows, you've come to the right place.
 

RustyO

Member
Decided to start learning/teaching myself C++ and the Juce library for Audio/DSP development... this will be fun.

Learning C# and WPF at the same time might have been a bad decision. Hard mode activated.

Mmmm... I tried WPF once or twice, hated it with a passion, found I was getting bogged down for very little benefit, so I tapped out and went back to C#/WinForms.
 

Somnid

Member
I've built some big applications with WPF/Silverlight. I still don't remember how stuff works. When MS got on the XML bandwagon in the early 2000s it got on hard.
 

JesseZao

Member
Learning C# isn't so bad, but I could see it being difficult trying to learn it while getting acquainted with a framework simultaneously. I've only used WinForms for desktop/non-console apps. Web apps are nice if you use MVC, but WebForms is awful.
 
Helping a team that was trying to learn C# and a framework (this time, MVC) has been the story of my life for the past 3 months.

It went well. I've done everything and they've spent 3 months delivering 12 total hours worth of work.

(12 hours is generous and based on how long it would have taken me to do it.)
(To be fair to them, they've been balancing other work.)
(But for real... 12 hours of real work in 3 months? Good grief.)
 

Two Words

Member
I'm actually trying to learn C#. I know some Java and C++ and I'm finding a lot of the lessons redundant. Are there particular things I should really focus on learning that are especially unique to C#?
 

Makai

Member
I'm actually trying to learn C#. I know some Java and C++ and I'm finding a lot of the lessons redundant. Are there particular things I should really focus on learning that are especially unique to C#?
Structs are passed by value. Classes are passed by reference.

Use { get; set; } properties instead of getter/setter methods.

"var" can be used in method scope for type inference. Still static/strong typed.

Use Action and Func for all of your delegates.

? operator is shorthand for a null check.

.NET - libraries

LINQ - replacement for SQL
 
I'm actually trying to learn C#. I know some Java and C++ and I'm finding a lot of the lessons redundant. Are there particular things I should really focus on learning that are especially unique to C#?
Make sure you know how to use "using" and accessors. Those are two of the biggest improvements from Java (IIRC).

Other than that, most of the standard Java stuff is applicable.
 

Makai

Member
That implies the Zachtronics games somehow favor or exclude a particular gender. Writing assembly code for an imaginary computer is very nerdy, but last I checked, even tumblrites had not managed to invent high-level-programming-construct-genders and those would be the only ones oppressed in TIS-100.
I just imagine the fan base for SpaceChem being more male dominated than Human Resource Machine.
 

Chris R

Member
LINQ isn't a replacement for SQL, It's just a way to write queries in code that look and behave very much like SQL, as well as providing an interface to your SQL database.

It isn't the fastest method to interface with data, but damn if EF isn't so fucking easy. Spend a few minutes, properly setup your SQL Server database/tables and just drag shit over, done.
 

Makai

Member
Oh yeah, install Resharper. It will recommend changing your code to take advantage of language features (e.g. converting code into LINQ) and then do it for you.
 

Makai

Member
LINQ isn't a replacement for SQL, It's just a way to write queries in code that look and behave very much like SQL, as well as providing an interface to your SQL database.

It isn't the fastest method to interface with data, but damn if EF isn't so fucking easy. Spend a few minutes, properly setup your SQL Server database/tables and just drag shit over, done.
It basically has been for me. I avoid SQL because I don't get the peace of mind of compile-time checking.
 
Structs are passed by value. Classes are passed by reference.

Factually incorrect. Time to put on my pedant cap...

Structs and classes are both passed by value. It's just that with the latter, the value is a reference. However, saying something is passed by reference has special meaning. Either structs or classes can be passed by reference with the special "ref" modifier on the parameter and argument, and that simply results in modifications to the actual variable being observed at the call site.

Code:
private void A(ref object foo)
{
      foo = "hello world";
}

private void B(object foo)
{
      foo = "apple sauce";
}

...
object x = null;
A(ref x);
B(x);
Console.WriteLine(x);

In this code, the special meaning is demonstrated. If you said "apple sauce" is written to the screen, you have to stop what you're doing and go play Superman 64. If you said "hello world" is written to the screen, you get to play your favorite game ever. Without that "ref" keyword, the output would have been jack diddly squat.

Parameters are passed by value. References are values, but references can be written over with new references and such writes will not be observed unless you use keywords to make it so.

Now to take off my pedant cap and go about my business.
 

Somnid

Member
LINQ is very useful to know (not so much the ugly SQL version but at least the method chaining). I don't really care for Entity Framework or Linq-to-Sql. They're both slow and have weird non-obvious things about them. Lots of generated code and black magic.

For ORMs Dapper is where it's at. You still need to write your db but it's no config, no generated non-sense and stupid fast.
 

cocopuffs

Banned
Had a first programming test and completely bombed it. Passed and within course average (56%) but still did pretty terribly. Don't want this to ever happen again so it'd be appreciated if anyone could look at this and give any quick criticism for concepts/ideas I may have not understood completely.

While I see where I screwed up the last question, I don't get the 4th question at all. Man writing out code seems much more difficult than having to do it on a computer. Help please, ProgrammingGAF.

http://imgur.com/a/pZ6WU
 

Haly

One day I realized that sadness is just another word for not enough coffee.
I hope your professor is reviewing these in class because not giving any comments is awful for learning.

Question 4a

I think you have the right idea but the description is off. What amountOfOdd(n) does is sum all the odd numbers from 0 to n. Your description, parameters, and return are too vague, although I have never actually been tested on my ability to write docstrings so it's a pretty bizarre question. Your examples are only half right, the summing is actually inclusive. amountOfOdd(1) == 1, but amountOfOdd(5) == 9.

I would have named it "sumOddTo", so it would read: "sumOddTo(5)". It's nice when the function signature reflects the operation, and you can tell it's summing because the body uses the variable "s" as a return, which tends to be shorthand for "sum".

Code:
sumOddTo(n)
```
Return the sum of odd numbers from 0 to n, inclusive.
:param n: The upper limit of the range of numbers to sum
:return: The sum of odd numbers from 0 to n inclusive
Example: sumOddTo(5) == 9
Example: sumOddTo(10) == 25
```

Question 6
You print "What is your guess? 1" There shouldn't be a 1 at the end. That's the input.

You neglected to count the number of guesses. You should have a variable called "guesses = 0", and then you increment it after every input. This is why you lost a mark for each of the wrong guess lines I think, and then a further two points for not counting it at all.

Your function doesn't actually return the number of guesses. Look at the docstring, it's supposed to be returning a number in addition to printing it out. Returning is not the same thing as printing output. Otherwise you wouldn't be able to do this:

Code:
secret_number(10) == 5
 

cocopuffs

Banned
I hope your professor is reviewing these in class because not giving any comments is awful for learning.
Question 6 is honestly entirely on me. I spent too much time trying to figure out question 4 and by the time I reached that question, had to rush and didn't look over it completely.

Now figuring out what question 4 does, I do find that pretty difficult. Normally on a computer, I'd experiment and see what each line/the program did to figure out what it's supposed to do but doing it out by hand is a completely different ballgame. Guess it's something that I'll have to get better at with practice.

But thanks again.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Try running through the program by hand. Like, write out the variables during each iteration of the loop and go through all the checks. It's a pain but for something small you can do it pretty fast, and it'll get you used to doing it in your head.

For the record, I think not everyone is satisfied with the current emphasis on written tests in programming courses but change in education is slow.
 

Arkos

Nose how to spell and rede to
Hey ProgrammingGAF, I have some questions about going back to school and pursuing a career in programming, and I'd appreciate some advice/feedback about how worthwhile school is and what kind of options different kinds of schooling would give me. I apologize for the wall of text and links but I figured that would make it easiest for anybody who wants to actually give me some help.

First, about me. I have BA's in English and Philosophy (yes, laugh it up). I luckily got those degrees mostly on scholarship so I don't have any debt and have never taken on more than a few thousand in student debt. I've tried learning some programming on my own. I broached the basics of HTML and CSS and I took "Introduction to Computer Science and Programming Using Python" from edX.com. I felt like I "got" the edX course pretty well, although admittedly it was challenging as I haven't taken any formal math since high school (I substituted logic courses for the math requirements in college). I'll be starting the second part of that course, "Introduction to Computational Thinking and Data Science" soon.

What do I want out of further education? An interesting job that will allow me to make a decent salary. I don't need to be rich or do anything groundbreaking, I just want a secure job in a field that interests me (and from my experience, programming is interesting to me). I don't want to be a teacher, professional scholar, or Starbucks barista, so my current education just isn't cutting it. I can elaborate on my preferences/interests if you think that would help, but I'm especially looking for feedback on how much value I'm likely to get out of the different options I've found.

So, here are my main options. I'll just copy/paste some of the catalog descriptions of the programs near me, they seem to be pretty representative of what I've seen at schools in other places:

1. Tech School:

Tech School 1 Associate's Degree option said:
COMPUTER PROGRAMMING

Associate in Applied Science Degree

The Computer Programming curriculum prepares individuals for employment as computer programmers and related positions through study and applications in computer concepts, logic, programming procedures, languages, generators, operating systems, networking, data management, and business operations.

Students will solve business computer problems through programming techniques and procedures, using appropriate languages and software. The primary emphasis of the curriculum is hands-on training in programming and related computer areas that provide the ability to adapt as systems evolve. Graduates should qualify for employment in business, industry, and government organizations as programmers, programmer trainees, programmer/analysts, computer operators, systems technicians, or database specialists.

Fall Semester #1
ACA 115 Success & Study Skills 0-2-0-0-1
BUS 110 Introduction to Business 3-0-0-0-3
CIS 110 Introduction to Computers 2-2-0-0-3
CIS 115 Introduction to Programming & Logic 2-3-0-0-3
CSC 139 Visual BASIC Programming 2-3-0-0-3
ENG 111 Writing and Inquiry 3-0-0-0-3
MAT 143 Quantitative Literacy 2-2-0-0-3
Semester Total 19

Spring Semester #1
COM 110 Introduction to Communication 3-0-0-0-3
or COM 231 Public Speaking 3-0-0-0-3
CSC 151 JAVA Programming 2-3-0-0-3
CSC 239 Advanced Visual BASIC Programming 2-3-0-0-3
CTS 130 Spreadsheet 2-2-0-0-3
NOS 110 Operating System Concepts 2-3-0-0-3
SEC 110 Security Concepts 3-0-0-0-3
Humanities/Fine Arts Elective 3-0-0-0-3
Semester Total 21

Fall Semester #2
ACC 120 Principles of Financial Accounting 3-2-0-0-4
CSC 134 C++ Programming 2-3-0-0-3
CTS 285 System Analysis & Design 3-0-0-0-3
DBA 110 Database Concepts 2-3-0-0-3
NET 110 Networking Concepts 2-2-0-0-3
NOS 130 Windows Single User 2-2-0-0-3
Semester Total 19

Spring Semester #2
CSC 234 Advanced C++ Programming 2-3-0-0-3
CSC 289 Programming Capstone Project 1-4-0-0-3
CTS 120 Hardware/Software Support 2-3-0-0-3
NOS 120 Linux/UNIX Single User 2-2-0-0-3
WBL 111 Work-Based Learning I 0-0-0-10-1
Social/Behavioral Sciences Elective 3-0-0-0-3
Semester Total 16

TOTAL CREDITS FOR PROGRAM OF STUDY: 75

Tech School 1 Certificate option said:
Computer Programming Certificate

CIS 110 Introduction to Computers 2-2-0-0-3
CIS 115 Introduction to Programming & Logic 2-3-0-0-3
CSC 139 Visual BASIC Programming 2-3-0-0-3
CSC 151 JAVA Programming 2-3-0-0-3

TOTAL CREDIT HOURS IN PATHWAY: 12

Tech School 2 Software Development options said:
Software Development:

This track offers students a specialization in software development including programming JAVA and C programming languages, database programming and mobile application development. Graduates would be ready for work as software designers, associate software developers or engineers, software maintenance technicians, mobile app designers and technicians.

Associate's Degree

Something less than an Associate's Degree?

Certificate

Tech School 2 Web Development options said:
Web Development:

This track offers students a specialization in web development including web design using various languages such as JAVA or HTML, designing of web graphics to enhance websites, and topics on optimizing websites for marketing purposes and analytics. Graduates would be ready for work as web designers, website administrators, and internet marketing analysts

Associate's Degree

Certificate

Phew. So that's it for what seem to be the common tech school options. Associate's and certificates, focusing on applications or web. I feel like I would prefer applications to web, but I also would enjoy both and want to go in the direction that would give me the most options/variety/interesting work (as well as the best chances of getting a good job).

Alternatively, there is the option to go for a Master's degree. I enjoy school so I wouldn't necessarily mind going back to a university, but I also don't want to spend extra time/money if I won't see much of a relative benefit. Also, I would have to take some prerequisites (probably at least a semester's worth) at most places. Here's a description of the Master's program I've looked at:

2. Master's Degree

Master's Degree option said:
The Master of Science program in Computer Science prepares individuals for a Ph.D. program, research careers in industry, or advanced technical positions in industry and government. The program is designed for students who offer evidence of above average scholastic ability at the undergraduate level. During the M.S. program of study, the student will choose a concentration of study in one of six core areas and will choose courses in at least three other core areas for breadth:

Applications
Computing Foundations
Graphics and Visualization
Interactive Computing
Software Engineering
Systems and Implementation

Completion of the M.S. program normally requires from one and one-half years to two years beyond the undergraduate degree but may require additional time for students whose undergraduate degree is in an area other than computer science. Two academic years usually are required for the completion of the M.S. degree if financial assistance is provided.

So, those are the types of options that I'm looking at. There's also this option:

3. Fuck it, wing it

I could try to educate myself through free resources and practice as I have been doing, but honestly I don't know if I'm the type of person that can successfully do that. I think a formal setting would probably be best for me, but if you have any advice on this third option I'd be happy to hear it.

Any feedback? I know that's a lot of information, as I said I tried to lay it all out and be as explicit as possible. If you can chime in on what the best option may be, or what the different options might afford me, I would appreciate it sooo much.

Thanks a lot to anybody that responds, cheers.
 
Question 6 is honestly entirely on me. I spent too much time trying to figure out question 4 and by the time I reached that question, had to rush and didn't look over it completely.

Now figuring out what question 4 does, I do find that pretty difficult. Normally on a computer, I'd experiment and see what each line/the program did to figure out what it's supposed to do but doing it out by hand is a completely different ballgame. Guess it's something that I'll have to get better at with practice.

But thanks again.

I only had a brief look over it but it seems you never break out of your while loop so it just goes on forever. Not sure if there was anything else missed from that question as I said it was pretty brief. But I echo what others are saying that some of the questions are weird especially the one about writing a doc string....that's not really something you should be tested on I think.
 

Somnid

Member
Hey ProgrammingGAF, I have some questions about going back to school and pursuing a career in programming, and I'd appreciate some advice/feedback about how worthwhile school is and what kind of options different kinds of schooling would give me. I apologize for the wall of text and links but I figured that would make it easiest for anybody who wants to actually give me some help.

First, about me. I have BA's in English and Philosophy (yes, laugh it up). I luckily got those degrees mostly on scholarship so I don't have any debt and have never taken on more than a few thousand in student debt. I've tried learning some programming on my own. I broached the basics of HTML and CSS and I took "Introduction to Computer Science and Programming Using Python" from edX.com. I felt like I "got" the edX course pretty well, although admittedly it was challenging as I haven't taken any formal math since high school (I substituted logic courses for the math requirements in college). I'll be starting the second part of that course, "Introduction to Computational Thinking and Data Science" soon.

What do I want out of further education? An interesting job that will allow me to make a decent salary. I don't need to be rich or do anything groundbreaking, I just want a secure job in a field that interests me (and from my experience, programming is interesting to me). I don't want to be a teacher, professional scholar, or Starbucks barista, so my current education just isn't cutting it. I can elaborate on my preferences/interests if you think that would help, but I'm especially looking for feedback on how much value I'm likely to get out of the different options I've found.

So, here are my main options. I'll just copy/paste some of the catalog descriptions of the programs near me, they seem to be pretty representative of what I've seen at schools in other places:

1. Tech School:

Phew. So that's it for what seem to be the common tech school options. Associate's and certificates, focusing on applications or web. I feel like I would prefer applications to web, but I also would enjoy both and want to go in the direction that would give me the most options/variety/interesting work (as well as the best chances of getting a good job).

Alternatively, there is the option to go for a Master's degree. I enjoy school so I wouldn't necessarily mind going back to a university, but I also don't want to spend extra time/money if I won't see much of a relative benefit. Also, I would have to take some prerequisites (probably at least a semester's worth) at most places. Here's a description of the Master's program I've looked at:

2. Master's Degree

So, those are the types of options that I'm looking at. There's also this option:

3. Fuck it, wing it

Any feedback? I know that's a lot of information, as I said I tried to lay it all out and be as explicit as possible. If you can chime in on what the best option may be, or what the different options might afford me, I would appreciate it sooo much.

Thanks a lot to anybody that responds, cheers.

Many programming jobs generally are not concerned about education but rather how well you actually know your stuff. I definitely wouldn't bother with graduate level education unless you a going for a highly specific job doing algorithm design. Really it's about the quality of the program which is really hard to tell without materials. My fiancee is getting a certificate in web programming at a community college but their program is garbage. Self taught isn't a bad idea if you're cheap and really are willing to put in the effort. If your heart's not in it you will probably fail though.

Regardless of what you do, self-study is paramount. There's a lot of technologies and they change constantly, nearly any program will be outdated in some way.
 

Godslay

Banned
Learning C# isn't so bad, but I could see it being difficult trying to learn it while getting acquainted with a framework simultaneously. I've only used WinForms for desktop/non-console apps. Web apps are nice if you use MVC, but WebForms is awful.

I work with both.

They both have their pros and cons. I don't really consider one more awful than the other.

I always liked how Scott Hanselman described webforms as the dark matter of the Internet, simply because webforms are everywhere and with good reason.
 

Chris R

Member
LINQ is very useful to know (not so much the ugly SQL version but at least the method chaining). I don't really care for Entity Framework or Linq-to-Sql. They're both slow and have weird non-obvious things about them. Lots of generated code and black magic.

For ORMs Dapper is where it's at. You still need to write your db but it's no config, no generated non-sense and stupid fast.

I have to check Dapper out, because I really do love how easy EF is, but only use it in my personal projects and/or stuff that isn't time critical because of how slow it is.
 

Slavik81

Member
Hey ProgrammingGAF, I have some questions about going back to school and pursuing a career in programming, and I'd appreciate some advice/feedback about how worthwhile school is and what kind of options different kinds of schooling would give me. I apologize for the wall of text and links but I figured that would make it easiest for anybody who wants to actually give me some help.

First, about me. I have BA's in English and Philosophy (yes, laugh it up). I luckily got those degrees mostly on scholarship so I don't have any debt and have never taken on more than a few thousand in student debt. I've tried learning some programming on my own. I broached the basics of HTML and CSS and I took "Introduction to Computer Science and Programming Using Python" from edX.com. I felt like I "got" the edX course pretty well, although admittedly it was challenging as I haven't taken any formal math since high school (I substituted logic courses for the math requirements in college). I'll be starting the second part of that course, "Introduction to Computational Thinking and Data Science" soon.
I don't think you could start a master's degree in computer science with such a limited mathematical background. You'd need to spend a year or so with a full load of undergraduate classes to get up to speed first.

If you do want to go that route, you're best off talking to a CS professor. The easiest way to do that is to take a class with them, but you could also maybe look them up and email them. They're usually extraordinarily busy, so your mileage may vary on how successful email is.

I was an electrical engineer with a few years of professional experience as a software developer. I signed up for 3 CS courses as an open studies student, took a leave of absence from work, and tried my best. Talking with one of the professors after class, I expressed my desire to do a master's. He invited me to apply for grad school, and took me on as a student.

Academically, those classes were 'nice to haves', given my background. I used them to round-out my programming knowledge a little. They were just as valuable for learning about the school, getting academic references, and hunting for a supervisor.
 

TronLight

Everybody is Mikkelsexual
Guys I need some help with an algorithm.

I have this exercise:

Write an efficient algorithm that, given an array A of n integer elements, and an integer value v, verifies if, in array A there exists a couple of values (ai, aj) of which the sum results in the value v.

Now, the easy O(n-squared) way in which you test an element with all the others it's not really efficient. But I can't really think of a better way...

I thought that we could sort the array in O(n logn) with a quicksort, and then try checking all the elements that are smaller than v against each other, but that would still be O(n-squared) basically (like, if v is bigger than all the elements in the array).

Maybe if I take the first element A[1], test it against all the others from A[1] onwards ;
then, I take A[2], and test it against A[3] and onwards (because I already that A[1]+A[2] wouldn't work);
and then A[3] against A[4] and onwards (because I already know that A[1]+A[3] and A[2]+A[3] wouldn't work);
and so on...

Is that still O(n-squared)? Sounds more like O(n logn)... I'm not sure tough.
 

Water

Member
Guys I need some help with an algorithm.

I have this exercise:

Write an efficient algorithm that, given an array A of n integer elements, and an integer value v, verifies if, in array A there exists a couple of values (ai, aj) of which the sum results in the value v.
...
I thought that we could sort the array in O(n logn) with a quicksort, and then try checking all the elements that are smaller than v against each other, but that would still be O(n-squared) basically (like, if v is bigger than all the elements in the array).

Maybe if I take the first element A[1], test it against all the others from A[1] onwards ;
then, I take A[2], and test it against A[3] and onwards (because I already that A[1]+A[2] wouldn't work); ...

Is that still O(n-squared)? Sounds more like O(n logn)... I'm not sure tough.
That just halves the work to do, so you are still doing O(n) work for each element and O(n^2) total. It's trivially easy to drop that to O(log n) per element and achieve O(n log n) overall, though:
binary search for (v-currentElement)

That said, after you have the array sorted which takes O(n log n), I'm pretty sure you could also do the rest in O(n) total. The rough idea is
to run two iterators from the front and the back of the array towards the center until they meet, and check for any possible pairings on the way
 
So... let's talk about delegates and LINQ for C#. I can understand the idea just fine but I have a hard time thinking about WHEN to use it. So I pretty much don't use them right now.

Most of my time with C# is inside Unity so it's not overly complex windows stuff. Even so, anybody has some cases of using those features worth sharing? Doesn't need to be in a game programming context.
 

Water

Member
F# in Unity is still going well. Lazy keyword has saved my ass so many times.

F#'s a functional language - doesn't it have a lot of unavoidable memory churn?
I would love to program in a functional language but it seems like a no-go in Unity, at least outside editor scripts or strategy/puzzle/VN games, because you can't avoid memory churn and will get too much stutter for an action game intended to be smooth. Same for C# LINQ.
 

Makai

Member
F#'s a functional language - doesn't it have a lot of unavoidable memory churn?
I would love to program in a functional language but it seems like a no-go in Unity, at least outside editor scripts or strategy/puzzle/VN games, because you can't avoid memory churn and will get too much stutter for an action game intended to be smooth. Same for C# LINQ.
I haven't noticed anything, but I'm making a board game. I could do a test if you know what kind of things I should try. The only issue has been that F# is eagerly evaluated. Certain things are forbidden from being executed on the main thread by Unity, so I get a runtime error if I make a function that loads a resource or creates a GameObject. I can get around this by making those functions lazily evaluated, so they're first executed in a MonoBehaviour methods. John Carmack thinks we should move to Haskell or an ML-family language for AAA game development, so it's probably fine. I'm just getting started with functional programming, but my understanding is memory is not a real problem because Haskell garbage collects everything in constant time.

I actually used a lot of LINQ with Unity at my last job making iPad apps. No performance problems. Only build issues.
 

TronLight

Everybody is Mikkelsexual
That just halves the work to do, so you are still doing O(n) work for each element and O(n^2) total. It's trivially easy to drop that to O(log n) per element and achieve O(n log n) overall, though:
binary search for (v-currentElement)

That said, after you have the array sorted which takes O(n log n), I'm pretty sure you could also do the rest in O(n) total. The rough idea is
to run two iterators from the front and the back of the array towards the center until they meet, and check for any possible pairings on the way

Wait, what do you mean with (v-currentElement)?
Look for something that subtracted from (v-currentElement) gives zero?
 

Makai

Member
So... let's talk about delegates and LINQ for C#. I can understand the idea just fine but I have a hard time thinking about WHEN to use it. So I pretty much don't use them right now.

Most of my time with C# is inside Unity so it's not overly complex windows stuff. Even so, anybody has some cases of using those features worth sharing? Doesn't need to be in a game programming context.
Two main cases I have used delegates for are for storing an action for later and higher order functions.

For action storage, you might have something that stores what happens when you press a certain button. Normally, you jump, but after picking up a certain powerup, you fly. You would store what happens in a field, and set it to the fly action whenever you pick up the powerup. Now, your button code only executes the delegate, and doesn't have to check for state.

Higher order functions are when you pass a function as a parameter into another function. In C#, you can do this by making a method parameter with a delegate type. If you look for them, you will notice similar patterns in your code. And in the same way that you can use methods for procedure reuse, you can use higher order functions for method reuse. Here's three that I use all the time. If you're confused by the syntax, just ask! Action and Func are standard delegates in the .NET library. I always use them instead of defining my own. IEnumerable is the interface for virtually every collection in C#, so you can pass in lists, arrays, etc.

Code:
void For<T>(IEnumerable<T> collection, Action<T> action)
{
	foreach (var element in collection)
	{
		action(element);
	}
}

Code:
IEnumerable<TFormatted> Map<TRaw, TFormatted>(IEnumerable<TRaw> collection, Func<TRaw, TFormatted> func)
{
	foreach (var element in collection)
	{
		yield return func(element);
	}	
}

Code:
T Filter<T>(IEnumerable<T> collection, Func<T, bool> func)
{
	foreach (var element in collection)
	{
		if (func(element))
		{
			yield return element;
		}
	}
}

Then later, you use one of them as such:

Code:
var collection = [] { 0, 1, 3, 4, 5 };

Func<int, string> convertToString = integer => integer.ToString();

var strings = Map(collection, convertToString);
 

Water

Member
Wait, what do you mean with (v-currentElement)?
Look for something that subtracted from (v-currentElement) gives zero?

For every value ai in the array, you need to search for a value aj such that ai + aj = v. And aj = v - ai. After you have sorted the array, you can binary search for aj so it's only O(log n).
 

Godslay

Banned
LINQ isn't a replacement for SQL, It's just a way to write queries in code that look and behave very much like SQL, as well as providing an interface to your SQL database.

It isn't the fastest method to interface with data, but damn if EF isn't so fucking easy. Spend a few minutes, properly setup your SQL Server database/tables and just drag shit over, done.

It basically has been for me. I avoid SQL because I don't get the peace of mind of compile-time checking.

I agree with both of you.

As far as the performance, after the first query there is very little difference between Dapper and EF. 5-25 ms by benchmarks floating around. Which for most of us, probably isn't going to make much of a difference anyways. There are also performance tricks where you can squeeze additional speed out of EF, and if you are concerned about performance you should inspect what EF is generating or profile to make sure that EF is the bottleneck in the first place. It's only black magic if you let it be.

EF will never be as fast as Dapper, but the benefits you gain over using a full ORM over a Micro-ORM probably outweigh the speed that you gain. You can also use both if you have a troublesome query that has to be fast.

Really it always boils down to what you are doing and what performance you need. I wouldn't rule either out.
 
Hey ProgrammingGAF, I have some questions about going back to school and pursuing a career in programming, and I'd appreciate some advice/feedback about how worthwhile school is and what kind of options different kinds of schooling would give me. I apologize for the wall of text and links but I figured that would make it easiest for anybody who wants to actually give me some help.

Any feedback? I know that's a lot of information, as I said I tried to lay it all out and be as explicit as possible. If you can chime in on what the best option may be, or what the different options might afford me, I would appreciate it sooo much.

Thanks a lot to anybody that responds, cheers.

So just to distill your options:

1) Spend two years getting an associate degree with a technical college. My take on this is that it doesn't buy you that much since you already have a college degree, albeit in an unrelated field. On your resume putting in an associate degree in Software Development isn't all that great because it's somewhat trumped by your existing bachelor's degree. It would be fine if you didn't have the bachelors but since you do I just don't see the degree itself buying you a lot of options and opening up many doors.

The curriculum is actually pretty well in tune with lining up a junior programming position, a little on the softer side than an outright CS degree but not all that unreasonable. So you'd learn some stuff while you were there.

The big issue is the opportunity cost, which is very high for the amount of value you are getting. I wouldn't rule this out as an option but unless you can do this degree while bringing in a normal income with zero loans it seems fairly poor for you.

2) Master's Degree in CS - This is the objectively best option in terms of opening doors. The MS in CS will allow you to skip some work experience gating in job applications/interviews and get you into jobs at a level above pure entry level.
You will have a chance to operate in a research institution academic program, which with your previous degrees should be an easy cultural adjustment.

The challenge here is that you are coming from a background with zero computer science fundamentals. That may or may not be a big deal. You need to find out from your university exactly what criteria they expect graduate students to be up to. Do they want you to pass the math subject GRE (ETS doesn't have a CS subject test anymore)? Do they have a set of fixed coursework that must be completed (if so, find out if they are willing to allow you to test to get around it)? If you bring the heat with a github with cool stuff, will they look the other way on your complete lack of 'formal" programming classwork?

Once you have the answers to how long it would take to actually get you through the main program you'd have a better idea of how reasonable an option it is.

I wouldn't worry all that much about being able to actually do the work once you are there. You'll have plenty of time before getting in to get some code written and go through more online offerings to get some more substantial projects done. Computer Science coursework is still college coursework, and you beat it with good study habits and applying yourself. You don't need a special gene or nueral sequencing to get through a MS CS program.

Again, this is for sure your best option for your goals and I think it should be the one you pursue the hardest.

3) This can work for some people, but in order to transition it into a job you have to be smart about it.

I've seen people try this and fail because they lack the time management discipline tto get good results. You don't have to treat it like a full time job but, like a full time job, you want to be results-oriented. No one cares about how many online classes you took-what they might care about is what you produced and then what you did after you produced it.
So be focused on producing something that other people want to use.

If going this route, you should get hooked in with the local meetups (if you live in a city or tech hub) for the startup scene and the tech culture. They are generally free to attend and you will learn a great deal from seeing how they are trying to produce something cool while resource constrained. You will certainly get some ideas of things you can do on your won based on their approaches to problem solving and technology. It'll be smaller scale and not oriented towards getting customers and funding so don't sweat trying to be just like them.

Your end goal is to be at a point where you make something cool enough and have enough lessons learned while making it that you can present to this crowd. You also get a chance to network and if there's anything completely overpowered in getting a job it's knowing people.

So in summary:

1) doesn't buy you much
2) Is safe but has pretty high opportunity cost and you need to do some research.
3) Is risky and prone to failure but if you are self-motivated and passionate enough you can come out way ahead.
 

Makai

Member
My biggest beef with F# is there's no forward declarations - you have to declare a function before another function that calls it. Wasn't F# invented in this millennium? :mad:

In C#, I always put my submethods under the method that calls them. In F# I have to reverse that. At least there's no arguments about style.
 

Makai

Member
Thanks for the info Makai! Interesting stuff. Had to re-read the codes a few times but I figured it out =p
No prob. You'll start to notice all sorts of patterns, including more complex functions than the ones I showed. Your code will become a LOT more concise and encapsulated.

If you want to learn LINQ, install Resharper for Visual Studio. There's a 30 day trial. It'll point out, "hey, you could replace this code block with a LINQ statement" and then do it for you. It also will introduce you to other features of C#.
 

Water

Member
I haven't noticed anything, but I'm making a board game. I could do a test if you know what kind of things I should try. The only issue has been that F# is eagerly evaluated. Certain things are forbidden from being executed on the main thread by Unity, so I get a runtime error if I make a function that loads a resource or creates a GameObject. I can get around this by making those functions lazily evaluated, so they're first executed in a MonoBehaviour methods. John Carmack thinks we should move to Haskell or an ML-family language for AAA game development, so it's probably fine. I'm just getting started with functional programming, but my understanding is memory is not a real problem because Haskell garbage collects everything in constant time.

I actually used a lot of LINQ with Unity at my last job making iPad apps. No performance problems. Only build issues.

Unity's garbage collector is not fine. The only way to be smooth in a Unity game is to eliminate all continuous memory allocation+deallocation so the garbage collector won't run a cleanup sweep and cause a chug. Even something as simple as running a C# foreach loop on a list will reserve memory and release it when the loop is done, and also be slower than a plain for loop. LINQ is worse, and I'm assuming F# would probably be worse still.
http://www.somasim.com/blog/2015/04/csharp-memory-and-performance-tips-for-unity/
Throughput performance is not the problem.
 

Godslay

Banned
No prob. You'll start to notice all sorts of patterns, including more complex functions than the ones I showed. Your code will become a LOT more concise and encapsulated.

If you want to learn LINQ, install Resharper for Visual Studio. There's a 30 day trial. It'll point out, "hey, you could replace this code block with a LINQ statement" and then do it for you. It also will introduce you to other features of C#.

This can be good and bad, it recommends some goofy looking LINQ code at times, and makes the code a bit harder to read than say a foreach loop. Plus it's not going to drill down into the details.

He could also download LINQPad, and practice there with say with C# in a Nutshell book (which has a LINQ section that ties in with LINQPad). LINQPad is also a great general scratchpad tool which does a ton of other stuff as well.
 

Makai

Member
This can be good and bad, it recommends some goofy looking LINQ code at times, and makes the code a bit harder to read than say a foreach loop. Plus it's not going to drill down into the details.

He could also download LINQPad, and practice there with say with C# in a Nutshell book (which has a LINQ section that ties in with LINQPad). LINQPad is also a great general scratchpad tool which does a ton of other stuff as well.
He just wants to know wehn he'd use it, and it'll tell him.
 
Top Bottom