|
Member
(05-16-2012, 03:27 AM)
|
#751
However, it's a pain in the ass if you don't work with objects. I recently found my new love: Doctrine ORM. <3 I don't think I can live without it.
![]() He sounds like a complete ignoramus.
Last edited by hateradio; 05-16-2012 at 03:30 AM.
|
|
|
|
Member
(05-17-2012, 11:37 PM)
|
#752
Heh
Heh heh. HAHAHAHAHAHAHAHAHA I'm laughing so as not to cry. Code review today. Dude shows his code. Why is this line of code here? -I don't know. But you wrote it, right? -Yes. So what does it do? -I'm not sure. And you wrote it. -Yes. So where did it come from? -I think I might have copied it. So what does it do? -I don't know. :( This dude is nice as can be. Good guy. Can't code. I can't trust him to write code. I can't trust him to read code. I can't trust him to have anything at all to do with code because he simply does not get code. He has probably programmed for ten years, but he is absolutely, 100% clueless. Cargo Cult to the extreme, and I think Cargo Cult programmers are better. They at least have a method to their madness. Maybe. This guy? Copy a little bit of this, a little bit of that, copy a whole bunch of what he doesn't need at all, copy, copy, copy, paste, done. So what does it do? "I don't know." |
|
(05-18-2012, 12:06 AM)
|
#753
Is there a description somewhere of how a typical code review is conducted? I've never had one :(
|
|
Member
(05-18-2012, 12:29 AM)
|
#754
The first thing you probably want to have is a set of coding standards the team must abide by. Non-negotiable. (Except when you have to negotiate*.) If people violate those rules, you must kill them. Then you simply want to delegate time as often as appropriate to go over the code. Our team devotes about 4 hours per week, and that is arguably not nearly enough. We are a distributed team, so we get together on a conference call, share our screens, and simply present our code. If your code is under review, you present it, driving the presentation to a large extent, although the questions can also drive it. "Tell me about why you did this." "Show me the unit tests." "What do you mean there's no unit tests? I thought you said this was done." That type of stuff. You show your code. People ask questions. People offer criticism and ways to improve the code. Suggested refactorings. We have also identified bugs in the code. (Proving the ineffectiveness of their testing efforts.) Whatever is identified in the review as needing improvement should be fixed and re-reviewed preferably as soon as possible, lest people forget and the code rots. It certainly helps if you have people that are passionate about the profession and continual improvement. ------ *An example of a non-negotiable negotiable rule. We have a hard limit on lines of code inside a method. A smallish number. One that you must not go over, and you would preferrably not even come near. The caveat being that sometimes, you simply cannot avoid it. For example, say you have a method whose only responsibility is to new up an object and initialize some properties. Let's say your coding standard is X LOC in a method. The class has X + 1 properties. Obviously, to initialize this thing, you have to technically violate the standard. This is obviously allowed. However, the idea is centered around not having the method responsible for too much. So while the absolute letter of the law is violated, the spirit of the law is maintained as long as that method does not do anything else. The LOC limit is really just about setting a cap that immediately calls to attention when a method might be doing too much. Like I said, our standard is a smallish number (20). I try not to come anywhere close to that. "Uncle Bob's: head would spin at such a number, after all. 20!? More like 3!
Last edited by Randolph Freelander; 05-18-2012 at 05:54 AM.
|
|
Member
(05-18-2012, 12:47 AM)
|
#755
My coworker believes he knows what everything he's copying/pasting does. He copies and pastes code that isn't applicable to the situation, and then when it doesn't work right he starts blaming 1) the person who wrote the code he copied. and 2) our entire development team (except himself) for having a terrible development process that leads to him getting confused. He has called more than one meeting trying to "fix" our process so that we do things "the same way, everywhere" so that he can copy and paste code and it will work right. We spend hours on this. It drives me insane. Not trying to one-up your story. I just need to type it out somewhere before it eats me up. I am getting an ulcer or something..
Last edited by usea; 05-18-2012 at 12:49 AM.
|
|
Member
(05-18-2012, 12:52 AM)
|
#756
We used to have a belligerent dude who thought his code was above reproach and would simply discard any critique. His standard for his code working was "it compiled." (If you ran the application, pulled up that screen, and it exploded, well, that was your problem.) When his code didn't meet the business need, he blamed the specification. So we would look at the requirement, see that it laid out exactly what the line of business wanted, saw that his code did nothing of the sort, and then he would blame a different specification. One he wrote. But it was still the LOB's fault. Right. |
|
Member
(05-18-2012, 01:03 AM)
|
#757
Speaking of ten years, it continually fascinates me just how many developers there are out there that absolutely cannot code. I've read all the blogs, the "199 out of 200 applicants cannot write code," all of that. Didn't believe it.
Then I started being involved in interviews. :/ I work in C#, .NET. There has been a lot of evolution in .NET over the past 10 years. Nearly every person I have interviewed has supposedly been involved in C# development for the better part of those 10 years. And nearly every person's skillsets are still mired in what wasn't even acceptable 10 years ago, let alone now. No OOP. No abstractions. Polymorphi-what? Collection of choice is still the ArrayList. We talked to a guy. 20 years on his resume, with a lot of the recent years centered around C#, VB, and Java. He had on his resume that he taught a Java course at a community college. So I decide to, even though we're interviewing for C#, toss him a softball Java/C# compare/contrast question just to break the ice a bit. He cut me off. "I don't know Java." Thank you, drive through. We talked to another guy. We typically slip them some code for them to talk about. The code will generally have some issues to improve. Maybe it needs some refactoring, maybe it needs a different abstraction, maybe there is even a COMPLETELY OBVIOUS bug. Small, small snippets of code. We just want them to talk about it and hopefully sound intelligent as they do so. We allow for nervousness. 9 out of 10 can't do that much. But this one guy literally snapped. "I don't want to do this. Maybe if I could take this home, I could do it, but I'm not doing it here." It is disheartening. I keep thinking there is good code out there. After these interviews over the past few months, I am coming to grips that the cargo cultists have won.
Last edited by Randolph Freelander; 05-18-2012 at 05:53 AM.
|
|
Member
(05-18-2012, 01:18 AM)
|
#758
Funny that you say that. The guy I mentioned above has stated that he would never analyze or produce code during an interview. He feels any shop who does that is just trying to get free consulting.
Which I am certain does happen. But come on, a single method? Really? Maybe if they asked you to write some fully functioning scheduling system or something. |
|
Member
(05-18-2012, 01:34 AM)
|
#759
"We are getting eaten alive by the competition. We really need to solve this FizzBuzz problem. Been trying for weeks. What if we were to... Bob, get this. Let's conduct interviews. Have those folks write this code, and then all we have to say is that we went with 'somebody else' for the hire. What do you think?"
"Jim, that's.... brilliant." |
|
Member
(05-18-2012, 04:34 AM)
|
#760
it really makes me glad i don't have to deal with this kinda thing, as everyone around me have been fairly competent, including myself. but wait... what? 20 lines max for a function??? that is such a tiny number that i cannot fathom. much of my stuff often exceed 20 lines. some of the biggest are a few hundreds, broken down into steps within, and where none of the steps really make sense to be exposed for others to use. do you have a boss tech guy? someone that oversees all development and maintains order? someone who knows what good practices are and has the power to be intolerant of the bad. i think a fresh grad who's been through proper engineering training would be better, because then they'd have a good base of knowledge, and can be molded than the veterans who refuse to adapt. (that is, until the noobs become such stodgies) |
|
Member
(05-18-2012, 05:46 AM)
|
#761
(actual code I wrote years ago) Code:
private void SendCommentViaEmail()
{
string fromAddress = "info@whatever.com";
var regex = new Regex(@"someEmailRegexPattern");
if (regex.IsMatch(tbEmail.Text))
{
fromAddress = tbEmail.Text;
}
var client = new SmtpClient("someemailhost.net");
var message = new MailMessage();
message.To.Add(new MailAddress("foo@bar.com"));
message.From = new MailAddress(fromAddress);
message.Subject = "Comment posted on your website";
message.Body = tbMain.Text;
message.IsBodyHtml = false;
client.Send(message);
MailMessage messageToPhone = new MailMessage();
messageToPhone.To.Add(new MailAddress("aphonenumber@phoneservice.com"));
messageToPhone.From = new MailAddress(fromAddress);
string body = "";
if (tbMain.Text.Trim().Length <= 80)
{
body = "From: " + tbName.Text + " (" + tbEmail.Text + ")";
body += " -- " + tbMain.Text.Trim();
}
else
{
body = "Comment posted on yourwebsite.com by " + tbName.Text + ", "
+ tbEmail.Text + " (too long)";
}
messageToPhone.Body = body;
client.Send(messageToPhone);
}
Code:
private void SendCommentViaEmail()
{
string fromAddress = GetSender();
var client = new SmtpClient("someemailhost.net");
var message = ComposeMessage(fromAddress, tbMain.Text);
client.Send(message);
string messageBody = GetMessageBodyForPhone(tbName.Text, tbEmail.Text, tbMain.Text);
MailMessage messageToPhone = ComposeMessageForPhone(fromAddress, messageBody);
client.Send(messageToPhone);
}
private string GetSender()
{
string fromAddress = "info@whatever.com";
var regex = new Regex(@"someEmailRegexPattern");
if (regex.IsMatch(tbEmail.Text))
{
fromAddress = tbEmail.Text;
}
return fromAddress;
}
private MailMessage ComposeMessage(string fromAddress, string emailBody)
{
var message = new MailMessage();
message.To.Add(new MailAddress("foo@bar.com"));
message.From = new MailAddress(fromAddress);
message.Subject = "Comment posted on your website";
message.Body = emailBody;
message.IsBodyHtml = false;
return message;
}
private string GetMessageBodyForPhone(string name, string emailAddress, string messageBody)
{
if (messageBody.Trim().Length <= 80)
{
return "From: " + name + " (" + emailAddress + ") -- " + messageBody.Trim();
}
else
{
return "Comment posted on yourwebsite.com by " + name + ", " + emailAddress + " (too long)";
}
}
private MailMessage ComposeMessageForPhone(string fromAddress, string messageBody)
{
MailMessage messageToPhone = new MailMessage();
messageToPhone.To.Add(new MailAddress("aphonenumber@phoneservice.com"));
messageToPhone.From = new MailAddress(fromAddress);
messageToPhone.Body = messageBody;
return messageToPhone;
}
So like I said, after my first refactoring pass, I feel better about the code, but I also see opportunity to clean it a bit more. Your mileage may vary.
Last edited by Randolph Freelander; 05-18-2012 at 05:51 AM.
|
|
got my tag in the OT
(05-18-2012, 05:52 AM)
|
#762
I used to run code reviews and they went sorta like this: - Have the developer explain what the problem their code is supposed to solve. - Look through the code see if it actually solves the problem - Look at the error handling make sure it's appropriate for what the code is doing - Look for any "overlap" issues the code might cause downstream (this is the most important one) - Look at unit test evidence - Look at performance - Make sure all objects are destroyed properly - Look for redunancy or bad code. Now I'm not talking about shooting everything down it's not about style but literally we had instances where someone wanted to do something and they just kept copy/pasting the same code over and over. We told them to go back and use a function. Like real brain dead stuff like that. Now I've sat in plenty of code reviews where people just sit there and beat up any developer unlucky enough to show up. |
|
Member
(05-18-2012, 06:15 AM)
|
#763
I'm currently volunteering some time to refactor a CMS code base, but the thing is fucked. It was coded in 2007 or so and it shows. It's in PHP, and practices of PHP4 are seen everywhere.
Class names are all in caps and use underscores, variables are okay since they're CamelCase, but methods and functions are lower cased with underscores. It's rare that variables and methods are declared private, protected, or public. There are pages with tons of functions, classes that are unorganized, xHTML being processed by the PHP, no templates, no SQL abstraction. It works, but it's a total nightmare. There was a plan to restructure and to appropriate a framework last year, but it was killed after the devs decided it would be too much work. They don't want to use a framework at this time because initializing their (the framework's) code takes a lot of resources. Once I started using an MVC pattern, I really started to notice that my methods and functions were becoming smaller, at least in the controllers. It's interesting to see that your code becomes lighter as you create a nice chain of command and better interaction between your objects. This is especially why I am in love with Doctrine's ORM now. It's a life changer. ;_;
Last edited by hateradio; 05-18-2012 at 06:22 AM.
|
|
Banned
(05-18-2012, 06:22 AM)
|
#764
OpenGL is some arcane ass shit.
Unless you're gonna be a namby pamby web "programmer" than forget what I just said.
I could probably write a decent sized guide on how to prepare for entry level job interviews as a programmer in the games industry.
Last edited by bluemax; 05-18-2012 at 06:29 AM.
|
|
(05-18-2012, 12:49 PM)
|
#765
My situation is that I'm the first and only programmer for my employer, so it's up to me to set the standards, but there's no one around to double-check my work. This isn't my first job, but I was just QA before, so I was never privvy to what goes on behind the scenes for the developer. |
|
Member
(05-18-2012, 01:12 PM)
|
#766
"How would you reverse the words in a string?" Yes, because I frequently run into complicated problems at work that must be solved within a couple minutes while being stared at by 3 interviewers. The good companies give you some sort of assignment and a week to complete it. The goal is just to show that the interviewee has competent programming skills regardless of language and doesn't write code that is bunched up into one 10,000 line file with no comments and variables named things like "temp","a_" or "num". Speaking of dumb interviews, I had a recruiter call me on the phone who obviously had no technical experience at all (why else would he be a recruiter?) who asked me the most inane questions that just completely drove me up the wall. "In your career, how many lines of code would you estimate you've written?" 0_o |
|
Member
(05-18-2012, 01:19 PM)
|
#767
|
|
Member
(05-18-2012, 02:15 PM)
|
#768
Tablename T_KK_LZ Fields LstPatIDRel, LstDeleted, LstLszIDRel, LstID, LstLszIDRel, LstDatum, LstPrxIDRel, LstVKNR, LstAbrDiaIDRel, LstLink, LstDocID, DaySeparation and more crap And that's one of maybe 400 tables, all named the same shitty way. And the shitty way isn't even consistent. I guess the developers could not be bothered typing a little more than a few letters. Too much work I guess. I had to reverse engineer this pos database that's used for documenting dialysis, just because that fine company isn't capable of exporting to HL7. |
|
Member
(05-18-2012, 04:44 PM)
|
#769
You need to be able to show that you're at least base-line competent in an interview. That means writing code on a whiteboard or on paper or maybe even typing it. It doesn't have to be perfect. But if your reaction is to get mad when asked to demonstrate that you can do your job then goodbye. An interview isn't just to make sure you don't name your variables stupidly. You need to demonstrate that you can actually code. Like, that you know what a for loop does. A week-long assignment? That's stupid. Just write 10 lines. They'll probably give you quite a lot of time to demonstrate your competency. I have zero problem writing code on paper. Most of the time the code will actually compile, but I certainly don't expect that from everybody. It can be english, as long as it describes your thought process. |
|
Member
(05-18-2012, 11:55 PM)
|
#770
What usea said.
You are being hired to read and write code. You should read and write code in your interview. Just look at some code, talk about it. Go to the whiteboard. Write pseudocode. Yes, you should be able to do that on the spot. Again, nothing intended to trip you up. Nothing that is going to make you rack your brain for hours and hours. But an hour of Q & A isn't going to reveal everything. Code, on the other hand, reveals much. |
|
Member
(05-19-2012, 12:15 PM)
|
#771
1. My handwriting (and I'm sure a lot of other people's) is *atrocious*
2. Whiteboards, yes. Small pieces of paper where you can't easily undo/shuffle lines and then expect perfect code for something rather complex? Hell no. I managed to do it, but it was a damned pain
Last edited by Turfster; 05-19-2012 at 12:20 PM.
|
|
(05-19-2012, 12:27 PM)
|
#772
|
|
Member
(05-19-2012, 12:39 PM)
|
#773
Finished my last exam last Friday and started work last Monday.
We mainly do web-apps and while I already had experienced some of it previously this was a big reminder of: -There's a stupid level of voodoo magic in getting your dev environment set up correctly -Having 8 different css files, 2 of which are for different IE versions can be a nightmare to debug, especially across different browsers and table column sizes with a mix auto sizeing and preset sizes. But work has been fun, have achieved nice little fixes/updates for the application. |
|
Member
(05-19-2012, 06:53 PM)
|
#775
If you're a good developer / programmer / architect /engineer you'll never have trouble finding work because there are so many bad programmers out there.
We are falling behind at work because we are having to drag deadweight behind us. I'm in a more supervisory role than I have been before and I'm really frustrated because I'm not even in a position to prop these people up or help them even. They are as dumb as rocks. |
|
Member
(05-19-2012, 06:58 PM)
|
#776
My last company did the more traditional route - when somebody was about done with a big project, they had to print the entire project out on paper and distribute it to the team a week before the meeting. Then we just brought up things we'd improve in the meeting. Review Board is pretty awesome though. It hooks into your existing source control, and you just upload diffs. It formats them all pretty and people just highlight code in their web browser to comment on it. We use it for cross-pollination as much as fixing potential problems. The entire team stays up to date on what's going on across the various codebases even if they're not currently working on each one. |
|
Member
(05-19-2012, 07:03 PM)
|
#777
Had to watch some bs video in a coding class about a guy working as a game programmer. They asked him to work overtime before the launch of their game, but he had tickets to a concert that weekend... Classed was asked what they would do if in a similar situation. Pretty much the entire class said they wouldn't work the overtime, and quit if it came to that. Saying they could find an equal or better job within a day or two. How is it possible people are still that naive? Shocker, but I don't go to MIT either.
|
|
Member
(05-19-2012, 07:04 PM)
|
#778
|
|
Member
(05-19-2012, 07:09 PM)
|
#779
In general, the phrase 'technically breaks the rule but not in spirit' is a red flag for there being a larger problem, and in this instance it seems to be a fat class. |
|
Member
(05-19-2012, 07:12 PM)
|
#780
|
|
Member
(05-19-2012, 07:13 PM)
|
#781
Last edited by Randolph Freelander; 05-19-2012 at 07:16 PM.
|
|
(05-19-2012, 07:49 PM)
|
#782
On the plus side, finding a job when I graduate might not be as tough as I'm expecting. |
|
Member
(05-19-2012, 08:28 PM)
|
#783
If any of you are or knows a Montreal/Quebec employer, tell them we have like 3 or 4 competent developers here in Venezuela looking for a good opportunity :D *waits endlessly*
|
|
Member
(05-20-2012, 08:08 PM)
|
#784
A few weeks ago I was charged with refactoring and adding some new features to a VB script in a MS Access document connected to an Oracle SQL database which is used by a notable number of employees all over the world.
The script had been written by an external consulting company, and the code was just horrible. The records had a country field, and the Access form should only display records with the same country as the user, whose country was read from a MS Active Directory. There were about 7 to 10 getters and global variables only for the country. The getCountry function checked if the country variable (a string) was empty and called another getCountry function if so. I can't remember what the second function did, but it was pretty similar to the first one and called another function too. Afterwards the return value of the second function was checked too, and if the string was empty, it read the value of the global DEFAULT_COUNTRY variable. If that one was empty, it called another function. Those methods should return just the name of the country, but the country code was used too. So, all of those functions again, just with the country code instead of the country name. And this bunch of functions was interwoven with the first bunch, some of them called each other... The database contained not a single primary key, I shit you not. The main table which contained the records for the Access form had an id field, but there were no constraints. They just looked if the id existed in the VB script when a record was added or edited and displayed an error message if so. So of course, the main tables country field actually stored the country names. A workmate told that their had been a typo in the country table once, so they had to edit all references in the other tables, which had caused several problems. I think that was the first thing I did, adding primary key ids. I can't remember most of the details from the remaining code, but it was a mess. Using the VB editor is a pain in the ass too. If you have a syntax error in a line and attempt to move the cursor to another one, the line is not underlined with an angular red line or something like that, but you get a fucking modale error dialog. Occasionally makes me wanna yell out of rage. To check for some semantic errors, you can compile the whole script, but instead of showing a table with all error descriptions and line numbers, you get a modale dialog again. It shows the error description of the first found error and puts the cursor to the corresponding line if you click ok. Fix it, compile again, message box about the second error. Fix it, compile again, and so on. The following paragraphs are no rant but a funny anecdote, again about the country id stuff. Without an ORDER BY clause, the sort order of the results of a SQL query is usually undefined. When adding the country ids, I wanted the alphabetically first country to have the id 1, the second 2 and so on. Of course there's no reason to do so, but it just looks nice in the database... Curiously, I tried the following statement:
Quote:
So I continued my work refactoring the script to use the ids instead. Some users had extended rights, they were able to view and edit records for other countries other than their own too. Previously, this was handled in the VB script.
Quote:
I dumped the CREATE TABLE and INSERT statements into a file to add the data to the test and production databases. Everything was working flawlessly, so after verifying it worked in the test environment too, it went into production. A few days later we got a call from another employee abroad. She couldn't access her records. Alright, so I had a look into the database. The country id in the RIGHTS table was off by one. Figured a typo, fixed it and right before I closed the window, I noticed that EVERY SINGLE COUNTRY ID IN THE WHOLE TABLE WAS OFF BY ONE. Meaning, not a single user would have been able to get access to his/her records.. luckily no one seemed to have used it for days, or else we would have got dozens of emails and calls. I was new at the company back then, and I panicked. I didn't even try to correct the ids via UPDATE statements, I fixed them manually line by line. Still slightly shaking, I investigated how this could be possible. The reason was this:
Quote:
In the test and production environments, which I guess are using a different Oracle version, it was regarded as an 'A' and got the id 3. So, in the dumped INSERT script of the RIGHTS table, all country ids greater than 2 were too low by one... |
|
Member
(05-20-2012, 08:34 PM)
|
#786
|
|
Member
(05-20-2012, 08:41 PM)
|
#788
For MySQL, you only need to use graves (`) if your database is older (legacy) or the name is reserved ie: LIKE and you have a field or table named like. So you would have to escape it with graves. However, you should avoid using reserved words. You should tweak it to avoid problems (use _like or likes).
You use single quotes for data. Depending on the language, you can also an abstraction layer, which can help with circumventing the use of quotes. :P But you'll still have to watch out for reserved words.
Last edited by hateradio; 05-20-2012 at 08:44 PM.
|
|
One day I realized that sadness is just another word for not enough coffee.
(05-20-2012, 08:43 PM)
|
Not exactly a rant but I thought I'd ask here anyway
#789
I have four classes: GameManager, InputManager, GUIManager and GUIMenu
User input should be passed to whichever GUIMenu is active, and the input should be responded to by changing the state of the GameManager in some way. My problem is that I can't really decide what is the best way to go about doing this. Solution 1: When GUIMenu is updated, it asks the InputManager for any input from the user then responds to it by telling the GameManager what it should do. This is the simplest solution, I think, but it requires a lot of inter-class mingling I'm not comfortable with. For example, if I have a stage select menu, the menu would tell the GameManager to load level 1, but then the GUIMenu would have to be aware of the LevelManager, or at least the GameManager. Solution 2: GameManager gets user input from InputManager, gives GUIManager a state and asks it for the menu that corresponds to that state. GameManager then passes on the input to the GUIMenu and asks what it should do next. GUIMenu returns a task like PUSH_PAUSE or LOAD_NEW_GAME, which the GameManager then passes on to whatever class handles that stuff. Solution 3: Like Solution 2 except it adds an extra layer of indirection by having GameManager pass input to GUIManager, which passes it on to the GUIMenu. Later, GameManager asks GUIManager if there's anything that should happen because of the input. Then GUIManager asks GUIMenu what should happen, and finally takes the response and sends it back up to GameManager. I like Solution 3 the most because it keeps all the classes nice and separate, but it also seems like I'm intentionally adding redundancies for the sake of organization. Since I'm still a student, stuff like this slips under the radar but I would like some opinions from on what I should do if I was in a professional setting. |
|
Member
(05-20-2012, 10:19 PM)
|
#790
Mind you, I myself havent dealt with this specific problem but a friend in my team has and I think this was his solution, although we still have got to see how it behaves ;) |
|
Junior Member
(05-20-2012, 10:48 PM)
|
#791
Subbed to this thread! Was surprised there is no (to my knowledge?) general programming thread, glad that this one showed up.
Don't have a question or anything right now, just a rant. I'm a programmer who can't design. It's so frustrating, and combined with how I constantly restart entire projects in an attempt to clean up code, I have just about nothing to show for the past six years of programming. For a year or so now I've been toying around with the idea of making a video game website. I know there are thousands of them out there, and this one probably wont do anything original or get more than 10 visitors per week, but it's something my friends have wanted to do and it sounds like a fun way for us to spend our free time together. So I did some of the server-side stuff in PHP with the Yii framework (which I can't recommend enough, it's a fantastic framework, maybe the best one around right now), but then started to design the front end site and have been stuck at that stage ever since. This was the closest I ever got to a usable design, but I still don't like it. Too much white space.
Quote:
|
|
Member
(05-21-2012, 06:03 AM)
|
#794
Hey. I learned procedural programming in a university course where I did C++. (The course was called problem solving for scientists and engineers). I like reading this thread, but something that's always bothered me is that I don't quite have a full handle on what exactly object oriented programming is. I think the source of this confusion is me trying to understand what it can achieve that procedural programming cannot.
I looked at the code from randolph earlier in the page and I understand what everything does there. So I look at it and say "is object oriented programming just having a bunch of functions floating around that take and pass variables around?" I mean, I see how it works, but I'm having trouble seeing what is there that can't be done in a procedural program. Is it the idea of inheritance? Isn't that just a little something that makes coding easier? I've read the wikipedia article about OOP a couple times now, and honestly, the criticisms seem to make more sense of OOP to me than the actual explanations. |
|
Member
(05-21-2012, 06:10 AM)
|
#795
And I actually like the whitespace, and it looks like it wouldn't be that hard to get the site looking good on mobile devices (seriously, huge push right now on making sites work well on iPads and iPhones) |
|
black folks = Newports
(05-21-2012, 06:26 AM)
|
#796
|
|
Member
(05-21-2012, 06:28 AM)
|
#797
Instead, OOP is just about three things in my opinion. Abstraction, People, and the "Noun." With OOP you engage in a lot of higher level constructs; code-hiding (encapsulation), polymorphism, inheritance, etc -- but really, you're interested in People, and people interact with things. Hence the "Noun" -- we want to escape the verb of code, that is "what you're doing, or how you're doing it" and replace it with a noun: "what are you interacting with." edit: For clarity; at the end of the day, you're modeling things with code. What you're modeling doesn't matter, but the manner in which you express your model can be drastically different depending on the paradigm. OOP is a paradigm; you're working with objects (even if you're working with functions and variables still). Depending upon what you're doing, certain programmers will tell you where the paradigm may break down, or where it can excel. The truth is, you're not going to fully understand it until you find a project where the paradigm makes sense, and you can see that it has a positive impact on your development (for example, others are able to better understand your code, or what-have-you). It's not so different from real-life. You can explain to me what your day to day is in terms of the things you do, or in terms of the things you've used (your bed, your phone, a door... etc). OOP is a tool like any other, made by people for people, for explicit organizational purposes and productivity. It is not always the correct tool for the job. Knowing when to use it versus when not to is an acquired ability over time, though it's possible to go your entire career using one or the other exclusively (though, highly unlikely in this day and age). Hope that helps.
Last edited by Spoo; 05-21-2012 at 06:32 AM.
|
|
Member
(05-21-2012, 08:23 AM)
|
#798
To me it's that your code is divided into several different aspects. That's not to say that you can't divide code into different parts or sections when you're doing procedural programing, but the result of OOP is a cohesive set of objects.
I won't do the example of a Person or Cat or Blog or whatever class, but essentially you're creating a relationship in your code that is more than the functions you're writing. If you want to create a function that returns the sum of some numbers you'd easily create it. But what if those numbers were not just part of a global scope? What if those numbers came from another function that worked with another function? You'd have four or five functions in your code for that one sum. Code:
function doAdd (x) {
r = 0
numbers = getNumbers()
processed = processNumbers(numbers)
total = processed + x
if (total > 0)
r = third
return r
}
Anyway, I don't know much about C++, but I'm sure most languages have built-in objects/prototypes. Things that relate to strings or integers or arrays, etc. When you need a string's length, you'd do something like characters = MyString.length. So you're working with objects even if you don't realize it. Lets say you need that aggregation. The aggregator has a very specific function (as any object should have) so you know how it will work before you even start writing it. The aggregator should be able to get the numbers, process them, add them to a given value, and return 0 or the total. Aggregator.getNumbers Aggregator.process Aggregator.doAdd They're part of that aggregator object, not the whole program. If you need it, you'll call it with new, if you don't, you won't need to have it around at all. Now, I know what you're thinking. Those methods could be normal functions because they're doing the same thing. However, as an object they're actually isolated from the rest of the program. If you instantiate an Aggregator to process your numbers, you'll be working within its scope, typically using this. Once you get your objects in place, all you might need to do when you want that sum is call something like the following. Code:
Sum = new Aggregator Total = Sum.doAdd(32) Code:
// Later on the user decided not to have that addition so they undo it Sum.undo() Moreover, within your aggregator you have control of what it will do once its instantiated -- its properties and methods can change when that happens. That's also the case when it's destroyed or copied or what have you. There's a lot more control over your code. I could go on and on, but that's, at least what I think, is the gist of OOP. You have an object, just as one of the native objects of your language (string, array, etc) that is specific to what you want to accomplish. And just like you can have thousands of different strings or arrays in your code, you can have thousands of these objects (if you required them) to do the work you need.
Last edited by hateradio; 05-21-2012 at 08:30 AM.
|
|
Junior Member
(05-21-2012, 08:58 AM)
|
#799
Thanks for the feedback on my site design guys. It's actually really reassuring! I see what you mean about having links in purple; all of the main colours are stored in SASS variables, so those can be changed easily.
I'll keep using that design for now and maybe post an update every now and then on how development is going. |
|
Scary Euro Man
(05-21-2012, 10:35 AM)
|
#800
|