View Single Post
  #9   Spotlight this post!  
Unread 05-02-2009, 00:26
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,058
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: why encapsulation is required?

Quote:
Originally Posted by Mageofdancingdr View Post
Real engineers use encapsulation because it is more secure against malicious programmers and their programs.
No, definitely not. You *could* make a statement that it makes things easier to debug, and thus more secure, but even then that is not strictly true.

Quote:
This is also why proper memory allocation is important as well. Keeping code secure from outside influence is important so that
A) the code doesn't interfere with other processes on the same machine
B) outside programmers can't access it
While proper memory allocation is a good thing, these are totally different issues. This is a *type* of encapsulation, but it certainly isn't the encapsulation one talks about when talking about programming languages (and really, (B) isn't even true in many situations that we won't go into here... ).

As someone above has pointed out, WPILib is a great example of why encapsulation is a good thing. Clearly it does not contribute to the security of the program.

For example, just because you declare something in a class as 'private' does not mean someone cannot access it (in absolute terms). Generally, accessing private members in a class will not compile correctly -- however if you had a raw pointer to the member then you could easily change the item, despite it being private. Additionally, there are a few ways one could make something that accesses a private member compile if you wanted to be truly nasty: see http://www.gotw.ca/gotw/076.htm if you're interested.

Quote:
C) it allows for a more modular type of code where simple function calls change not entire blocks of code.
This is the correct answer (though its more generic than just simple function calls).
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff