• 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

iapetus

Scary Euro Man
The most general things that could safely be applied to all programming languages are things like creating functions, conditional statements, loops, objects... all of which you should learn from any decent language specific book.

Even those don't apply to all programming languages.
 

Water

Member
Could any of you guys recommend some websites or books that teach the fundamentals underneath programming?

ie. Fundamentals that can be applied to all programming languages.
I'd consider the main categories of stuff that fits:

Algorithms and data structures.
The core of this is algorithm analysis (analyzing the time and space efficiency of a given algorithm) and then simply knowing all the usual data structures and their efficiency guarantees. If you have baseline competence in this, you can always go and google for more advanced algos or data structures for your specific needs, you don't have to memorize everything. I have not followed the books and materials available in this space. There's plenty of materials on individual algorithms and data structures on the web, but a textbook or taking an online course would be a good idea to give a you a wide picture. The only textbook I've had myself is the classic Cormen, Leiserson and Rivest book; it's huge and goes into a lot of detail so it's heavy to read, but isn't cryptic. One very good, compact book that shows applying this kind of knowledge is Bentley's Programming Pearls.

More computer science.
Things like language theory, parsing, compilers etc. Programming is about transforming data, and the same theory that goes into a compiler also allows you to e.g. robustly convert some data in a specific format to a new format. Cool guys sometimes think of solving problems in terms of building a mini-language in which that problem is easy.
An easily approachable, absolute classic in this category is Structure and Interpretation of Computer Programs aka SICP. It's simultaneously an intro to programming and a wealth of deeper information. Free to read on the web. It has a remake of sorts called How to Design Programs that is intended to be a better intro book but maybe doesn't go as deep - I haven't read it.
If you haven't dealt with things like functional programming or hardcore type systems, the best way to get into them is to try out a language with those things; what you learn will be applicable on a general level in other languages. For instance, SICP will have you using Scheme/Racket.

Good working practices, self-development, professionalism, ...
A catch-all category. There are some stand-out generalist books here like Pragmatic Programmer, and then books focusing on a more specific subject like debugging, unit testing, patterns, refactoring, etc.
 

iapetus

Scary Euro Man
There are some stand-out generalist books here like Pragmatic Programmer, and then books focusing on a more specific subject like debugging, unit testing, patterns, refactoring, etc.

If you want to prepare programmers for the real world then this is the way to do it.

1. Teach them how important debugging, unit testing and refactoring are, and what will happen to their code if they do not do them.
2. Set them a piece of work to do in class.
3. If any of them start by writing unit tests, make them stop, and tell them there isn't time to do them, and they can write them afterwards.
4. If any of them finish the work and start testing or refactoring, tell them to stop and add some new features instead.
5. Fail them all for not testing sufficiently.
 

maeh2k

Member
I'm looking for a book about unit testing / test driven development, but I'm not sure which one to get.

- Beck. Test Driven Development. By Example
- Osherove et al. The Art of Unit Testing: With Examples in C#
- Bender et al. Professional Test Driven Development with C#

Any opinions or other recommendations?
 

Tristam

Member
Any Qt users in here? Would love some advice!

I started developing a GUI app with a fairly straightforward structure. The main workspace consists of QWidget objects (each with their own set of basic widgets on them, like line edits, comboboxes, etc.) embedded on QTabWidget tabs. Navigation is supplemented by a QTreeWidget object that acts as a tab browser/explorer. The signals and slots are connected in a way that clicking on any item in the tree widget will activate the item's corresponding tab. To achieve this, I set each tab's widget as each corresponding tree widget item's data by using the QTreeWidgetItem class's setData method.

There's more to it, of course, but that's the crux of it. I'm seeking advice with respect to writing to and reading from disk. Although I'm toying with other methods, my initial inclination is to save in binary format via a QDataStream object. Unfortunately, objects subclassed directly from QWidget can't themselves be written to the stream. So, prior to writing each tree widget item, I need to write to the stream each QWidget object's component widgets (line edits, comboboxes, etc.), then reset the tree item's data to strip out the QWidget object, and finally write the tree widget item itself (the class of which has its own read/write methods to read from/write to a binary data stream). Of course, when I then read that data in, I've got a mass of unstructured data, and to re-structure (and, in essence, re-create) the file I more or less need to call my own custom tree-item/tab pair creation methods (which are used for creating tree-item/tab pairs outside of just reading/writing to disk) on each tree item that is read in.

Am I approaching this the right way? (I mean, I gave it a few cursory tests before going to bed last night, and it works, but it *feels* like a workaround hack, and I strive for something better than merely functioning, and since I was just toying around with this yesterday I haven't yet gotten the chance to see how long the read/write operations would take on a file heftier than a mere 20k.) Note that I'm using a Python binding for Qt, but that ought to be irrelevant for this.
 

tokkun

Member
If you want to prepare programmers for the real world then this is the way to do it.

1. Teach them how important debugging, unit testing and refactoring are, and what will happen to their code if they do not do them.
2. Set them a piece of work to do in class.
3. If any of them start by writing unit tests, make them stop, and tell them there isn't time to do them, and they can write them afterwards.
4. If any of them finish the work and start testing or refactoring, tell them to stop and add some new features instead.
5. Fail them all for not testing sufficiently.

"Agile" in a nutshell.

You may as well omit 3 & 4, since very few programmers actually like writing tests. At best, professionals will grudgingly put up with doing it, but students will not unless forced.

I used to teach the Verilog class at my university, and I got so fed up with students not adequately testing their designs that I started making them write up a formal Test Plan document, and that would be the first due-date for any large project.
 

Slavik81

Member
Any Qt users in here? Would love some advice!

I started developing a GUI app with a fairly straightforward structure. The main workspace consists of QWidget objects (each with their own set of basic widgets on them, like line edits, comboboxes, etc.) embedded on QTabWidget tabs. Navigation is supplemented by a QTreeWidget object that acts as a tab browser/explorer. The signals and slots are connected in a way that clicking on any item in the tree widget will activate the item's corresponding tab. To achieve this, I set each tab's widget as each corresponding tree widget item's data by using the QTreeWidgetItem class's setData method.

There's more to it, of course, but that's the crux of it. I'm seeking advice with respect to writing to and reading from disk. Although I'm toying with other methods, my initial inclination is to save in binary format via a QDataStream object. Unfortunately, objects subclassed directly from QWidget can't themselves be written to the stream. So, prior to writing each tree widget item, I need to write to the stream each QWidget object's component widgets (line edits, comboboxes, etc.), then reset the tree item's data to strip out the QWidget object, and finally write the tree widget item itself (the class of which has its own read/write methods to read from/write to a binary data stream). Of course, when I then read that data in, I've got a mass of unstructured data, and to re-structure (and, in essence, re-create) the file I more or less need to call my own custom tree-item/tab pair creation methods (which are used for creating tree-item/tab pairs outside of just reading/writing to disk) on each tree item that is read in.

Am I approaching this the right way? (I mean, I gave it a few cursory tests before going to bed last night, and it works, but it *feels* like a workaround hack, and I strive for something better than merely functioning, and since I was just toying around with this yesterday I haven't yet gotten the chance to see how long the read/write operations would take on a file heftier than a mere 20k.) Note that I'm using a Python binding for Qt, but that ought to be irrelevant for this.
This sounds weird to me. I'd expect you to be serializing the underlying data displayed by the views, not serializing the views themselves. Your file data is now directly coupled to how it is to be displayed. Overall, it sounds like there's a real lack of separation between model and view in your code. I could imagine an application in which that's reasonable, but for most programs I don't think that's the right choice.

Imagine that you discover you'd rather have a QTextEdit than a QLineEdit for a certain field. You've already deployed your application, and your customers have piles of saved files. How easy is it to change?

I think you may find it easier (though more verbose) to have the canonical state of the program stored somewhere outside the view. It's referred to as the model. Views pull data from the model when they are created and updated, and push data into the model when they are edited by the user. It results in more code, but it's easier to change how things are displayed, and you end up with fewer weird cases.

Then you can just save and load from this model, rather than from all the scattered view widgets. Your program would already be setup to update the view when the model is updated, so that bit would be nearly free once you wrote the model's serialization/deserialization.

"Agile" in a nutshell.
That's certainly not my experience with agile.
 

0xCA2

Member
Do you guys suggest doing GUIs in an IDE or by hand? I've heard both sides of the argument, and I want to hear you alls' take.

Note: I'm using Java and at this point I already have some familiarity with Swing. I've typically done it by hand and I wonder if doing so is a waste of time as long as I can debug IDE-generated code.
 
Do you guys suggest doing GUIs in an IDE or by hand? I've heard both sides of the argument, and I want to hear you alls' take.

Note: I'm using Java and at this point I already have some familiarity with Swing. I've typically done it by hand and I wonder if doing so is a waste of time as long as I can debug IDE-generated code.

Don't learn Swing. It is seriously outdated.
 

Tristam

Member
This sounds weird to me. I'd expect you to be serializing the underlying data displayed by the views, not serializing the views themselves. Your file data is now directly coupled to how it is to be displayed. Overall, it sounds like there's a real lack of separation between model and view in your code. I could imagine an application in which that's reasonable, but for most programs I don't think that's the right choice.

Imagine that you discover you'd rather have a QTextEdit than a QLineEdit for a certain field. You've already deployed your application, and your customers have piles of saved files. How easy is it to change?

I think you may find it easier (though more verbose) to have the canonical state of the program stored somewhere outside the view. It's referred to as the model. Views pull data from the model when they are created and updated, and push data into the model when they are edited by the user. It results in more code, but it's easier to change how things are displayed, and you end up with fewer weird cases.

Then you can just save and load from this model, rather than from all the scattered view widgets. Your program would already be setup to update the view when the model is updated, so that bit would be nearly free once you wrote the model's serialization/deserialization.


That's certainly not my experience with agile.

Slavik, I may have a few follow-up questions (for you or other experienced devs here), but just wanted to say thank you very much and that makes perfect sense. I think my sin here was in using a lot of convenience classes rather than the view classes they inherit from in conjunction with a proper model.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Do you guys suggest doing GUIs in an IDE or by hand? I've heard both sides of the argument, and I want to hear you alls' take.

Note: I'm using Java and at this point I already have some familiarity with Swing. I've typically done it by hand and I wonder if doing so is a waste of time as long as I can debug IDE-generated code.

I've found luck for my assignments by using an IDE such as IntelliJ, but I've never tried doing it by hand. That just sounds....overly difficult.
Edit: disregard this, I wasn't thinking incorrectly when I commented.

Don't learn Swing. It is seriously outdated.

It's required learning in my university course though, and I wouldn't be surprised if it was required elsewhere.

Not saying that it isn't outdated, but some universities enjoy teaching outdated material.
 

iapetus

Scary Euro Man
Do you guys suggest doing GUIs in an IDE or by hand? I've heard both sides of the argument, and I want to hear you alls' take.

By hand for me. I don't like auto-generated UI code as a rule, and if the UI's too complex to build in code then it's too complex period. I briefly enjoyed the stuff you could do with Visual Studio for Java back in the day, but as soon as I even considered maintatining it, I decided that manual was the way to go.

When the UI has a better separation between the pure visual representation and the code that backs it (hello, Android!) I'm happier to use IDE tools for editing them. Though even in Android I'm more likely to be using the text view with preview than the drag and drop view.
 

upandaway

Member
Don't learn Swing. It is seriously outdated.
I think it's pretty important to at least know it on some level. Handling things in JavaFX and other graphics libraries, knowing Swing helped make it easier for me to pick up quickly.
It shouldn't take more than a day to code some animation and input handling and move on
 
I've found luck for my assignments by using an IDE such as IntelliJ, but I've never tried doing it by hand. That just sounds....overly difficult.
Edit: disregard this, I wasn't thinking incorrectly when I commented.



It's required learning in my university course though, and I wouldn't be surprised if it was required elsewhere.

Not saying that it isn't outdated, but some universities enjoy teaching outdated material.

Ah gotcha. I've used this in the past - https://www.eclipse.org/windowbuilder/
I think it's pretty important to at least know it on some level. Handling things in JavaFX and other graphics libraries, knowing Swing helped make it easier for me to pick up quickly.
It shouldn't take more than a day to code some animation and input handling and move on

I can understand that. From a professional standpoint, there is a lot more JavaEE jobs out there than Swing/JavaFX. I'm just getting out of a job that used Swing as a client side GUI and couldn't be happier.
 

cyborg009

Banned
Has anyone here ever used heroku? I making a mobile application and websites and my friend suggested this. I wanted to hear some opinions on this...
 

Chris R

Member
So this github thing, what do I put on there? Obviously can't put 95% of my work material, but I don't do much coding off the clock.

Do I need to start? Just looking for something that will help take me to the next level if 4+ years experience doesn't do anything.
 
So this github thing, what do I put on there? Obviously can't put 95% of my work material, but I don't do much coding off the clock.

Do I need to start? Just looking for something that will help take me to the next level if 4+ years experience doesn't do anything.

There's no harm in having something to point employers towards.
 

NotBacon

Member
Any Android Devs using a cloud solution in here? I'm gaining my Android legs and have some ideas that use some sort of cloud server solution. Problem is I'm not sure what to choose. AWS, Google App Engine, Heroku, Parse, Rackspace, etc.
Google App Engine seemed promising but just trying to deploy a sample java app created all sorts of problems and really soured it for me. Is AWS really a lot of work?

But what the hell do I put in it :(

You don't have a single personal project?
 
But what the hell do I put in it :(

Anything you might like to show, or just store somewhere. If you don't have any personal projects then there's always the option of school work if there is any that is impressive/complex or you thought you did particularly well. Hell, you could even put up just some snippets of things just for your own reference.

If you're really lost for things and you still want to put some things up, the only option really is to start something new.
 

usea

Member
Steam just added tags. You can tag a game with anything, and some games have hilarious tags. I spent the last 2 hours writing a program that will search for a game by name, grab the top 16 tags for it, and then return those tags. Then I wrote an mirc script so that when people on irc say "!steam fez" they get the name of the game and up to 16 tags for it. It's fun because there are a lot of funny tags for games right now.

This is something I did on a whim. I don't do web programming, nor mirc scripting, so it took a while to figure out. It was fun. And I learned a bit about doing web requests from C#.

The code is terrible page scraping which probably won't work a week from now, but I'm going to throw it on github anyway. Because why not.

Solve a problem you're having, or make something that interests you personally. It doesn't even have to be nice.
 

Tonza

Member
Anyone familiar with licenses? I found a code snippet on Github Gist, which does not have license attached to it. But as Gist allows you to fork it, can I use it in my software project with MIT license? (will be put to Github)

Without a license, I think it has all copyrights reserved... Also it is quite a small class, though that doesn't really affect the rights.
 

usea

Member
Anyone familiar with licenses? I found a code snippet on Github Gist, which does not have license attached to it. But as Gist allows you to fork it, can I use it in my software project with MIT license? (will be put to Github)

Without a license, I think it has all copyrights reserved... Also it is quite a small class, though that doesn't really affect the rights.
I think you're best off contacting the person who owns the github account and asking them if it's their code, and if they'd be willing to grant you a license.

Git allowing you to fork it doesn't give you a license or any kind of ownership.

If you're licensing your code and you expect people to use your code, it's misleading if not all the code is strictly above board. Personally I don't have a problem using small snippets that I find without permission, but it's not the right thing to do and you should be considerate of others who might not be in the position to do that.

You could also just rewrite it (not copy it).
 

Tonza

Member
I think you're best off contacting the person who owns the github account and asking them if it's their code, and if they'd be willing to grant you a license.

Git allowing you to fork it doesn't give you a license or any kind of ownership.

If you're licensing your code and you expect people to use your code, it's misleading if not all the code is strictly above board. Personally I don't have a problem using small snippets that I find without permission, but it's not the right thing to do and you should be considerate of others who might not be in the position to do that.

You could also just rewrite it (not copy it).


Yeah, I think these are the best approaches. Thank you.
 

Fjolle

Member
I'm looking for a book about unit testing / test driven development, but I'm not sure which one to get.

- Beck. Test Driven Development. By Example
- Osherove et al. The Art of Unit Testing: With Examples in C#
- Bender et al. Professional Test Driven Development with C#

Any opinions or other recommendations?

Someone answer this. I'm looking for the same. Right now I'm leaning towards Art of Unit Testing, mainly because I can get a kindle version.
 

maeh2k

Member
Someone answer this. I'm looking for the same. Right now I'm leaning towards Art of Unit Testing, mainly because I can get a kindle version.

Yesterday, after asking, I ordered the second edition (which is apparently rather new) of The Art of Unit Testing. Got it today. Unsurprisingly, I haven't read it yet, but I was pleasantly surprised that with the paperback edition you get the electronic ones (pdf, kindle, epub) for free. The codes are in the book.

I thought I'd just go with a book on unit testing first and I'll tackle TDD after that.
 

Natural

Member
Been working through the 'csharp-station' tutorials to get to grips with programming again over the past few days but it looks like the website has died and is no longer available.

Can anyone recommend a similar website?
 

sdijoseph

Member
What you have inside the brackets is two applications of the comma operator (,). The value of the comma operator is always the value of the right-side argument, so this piece of code is equivalent to data[2].

Ok thanks. I gather there is no way to simplify

(data[0] == 'X' && data[1] == 'X' && data[2] == 'X')

then? Keeping in mind that the indices have to be the actual numbers, and can not be controlled by a variable (like i).
 

usea

Member
Ok thanks. I gather there is no way to simplify

(data[0] == 'X' && data[1] == 'X' && data[2] == 'X')

then? Keeping in mind that the indices have to be the actual numbers, and can not be controlled by a variable (like i).
You can put it in a function and call the function.
 
Ok thanks. I gather there is no way to simplify

(data[0] == 'X' && data[1] == 'X' && data[2] == 'X')

then? Keeping in mind that the indices have to be the actual numbers, and can not be controlled by a variable (like i).

data[0] == data[1] == data[2] == 'X'

at least I think so
 
Okay, I've got a programming problem on an assignment that has me stumped. I'm not looking for somebody to give me the answer, but perhaps nudge me in the right direction.

Paraphrased problem:

You have a class NetworkNode, with an attribute __load. Write a function called averageLoad that takes two NetworkNodes and returns their average.

However, you must compute it without ever accessing the __load attribute of either object, or by sending the __load from one object to another. In other words, the exact value of __load cannot leave its NetworkNode object.

Last sentence is a direct quote from the assignment.

I'm guessing this is something obvious that I'm missing, but how on earth do you compute the average of two elements that you can never access? The __load attribute can never leave the object, so there's no way for you to know the values in both objects at the same time, as far as I can tell.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Okay, I've got a programming problem on an assignment that has me stumped. I'm not looking for somebody to give me the answer, but perhaps nudge me in the right direction.

Paraphrased problem:



Last sentence is a direct quote from the assignment.

I'm guessing this is something obvious that I'm missing, but how on earth do you compute the average of two elements that you can never access? The __load attribute can never leave the object, so there's no way for you to know the values in both objects at the same time, as far as I can tell.


Are there any other objects or values that are affected by the _load attribute?
 
Are there any other objects or values that are affected by the _load attribute?

Not from the class outline he gave us, but maybe he's implying we should implement a method that does...if so, I think the question is poorly worded, because that would still mean at some point the value of __load leaves the object, even if it was obfuscated by another method.

Actually, it must be a poorly worded question unless I'm being really stupid today. Because that value MUST leave at least one of the objects at some point, even if it's not in the same member variable that it started in.

EDIT: Or, I could just have a member method that divides __load by two and returns that. And then add those together in averageLoad. Sounds kind of pointless and roundabout, but I guess it fits the description because the "exact" value of __load never leaves the object.
 

tokkun

Member
Not from the class outline he gave us, but maybe he's implying we should implement a method that does...if so, I think the question is poorly worded, because that would still mean at some point the value of __load leaves the object, even if it was obfuscated by another method.

Actually, it must be a poorly worded question unless I'm being really stupid today. Because that value MUST leave at least one of the objects at some point, even if it's not in the same member variable that it started in.

EDIT: Or, I could just have a member method that divides __load by two and returns that. And then add those together in averageLoad. Sounds kind of pointless and roundabout, but I guess it fits the description because the "exact" value of __load never leaves the object.

Let's assume that the node's actual load is sensitive information that cannot be exposed outside the node itself, but the average is not sensitive.

With your approach, some external code or eavesdropper could always determine the value of the node's load exactly just by multiplying by 2. However there are ways to compute the average without disclosing the exact value of a single node. Basically, you want to construct two mathematical functions, f & g, such that

g(f(load1), f(load2)) = (load1 + load2)/2

AND

f^-1(x), the function inverse, is difficult or impossible to compute.

I'm about to be late for a meeting, so I don't have time to explain this step by step, but basically you can keep a synchronized random number generator inside the node class, and use it to introduce a random element into f() that will not be known by the outside.

If you can't figure out a mathematical function to use, then make two different f() functions, and have one be e1 = (load1 + random) and the other be e2 = (load2 - random), then your average is (e1 + e2)/2, but the outside world can't figure out load1 or load2 without knowing the value of 'random'.
 
Top Bottom