Click here to Skip to main content
15,899,475 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Today Pin
Stephen Zelonis30-Apr-24 3:10
Stephen Zelonis30-Apr-24 3:10 
GeneralRe: Today Pin
Steve Naidamast30-Apr-24 4:07
professionalSteve Naidamast30-Apr-24 4:07 
GeneralRe: Today Pin
Choroid30-Apr-24 6:33
Choroid30-Apr-24 6:33 
GeneralDo you embed classes within classes? Pin
charlieg29-Apr-24 1:45
charlieg29-Apr-24 1:45 
GeneralRe: Do you embed classes within classes? Pin
pkfox29-Apr-24 2:02
professionalpkfox29-Apr-24 2:02 
GeneralRe: Do you embed classes within classes? Pin
trønderen29-Apr-24 5:25
trønderen29-Apr-24 5:25 
GeneralRe: Do you embed classes within classes? Pin
Maximilien29-Apr-24 2:06
Maximilien29-Apr-24 2:06 
GeneralRe: Do you embed classes within classes? Pin
trønderen29-Apr-24 5:22
trønderen29-Apr-24 5:22 
Pascal doesn't have classes, but defining local functions within an outer function is the common practice. If you see PROGRAM as a little more than a PROCEDURE with global initialization, every function/procedure that you write lies inside another function/procedure(/program).

You probably see great advantages of hiding some matters local to a class within that class inside the class definition. In Pascal, you would hide helper functions for a larger function inside that larger function - just like you have local variables and data structures. Also note that in Pascal, a parameterless function was called just by its name, with no empty ()s. So you could change a simple variable to a function calculating the value, without making changes to the code using it. (It took several decades before C# got properties, to do the same!) If I change a local simple variable to a calculated, but still local, value, I see no major reason for why I should have to move the declaration of it out to the global level.

During my student days, we migrated from Pascal to C, requiring all functions to be declared in a flat space. Also, the convention of creating a separate file for each function, even a three-line one, was introduced. What was a nice, closed set of a major function / procedure and its helper functions, was spread out all over the place. You couldn't use a simple editor search function to find definition and all its uses (calls) - you had to use an external 'search files' function, outside the editor. (Our editors at that time did not have a built-in 'search files'.) We did use a lot of hardcopy printouts of source code in those days, and having to print even a 3-line function as a separate file, on separate sheets, increased the amount of paper by a large factor. By Unix/C standards, conventions required a lot of formal blurb (copyleft etc.), as well as inclusion/processing of sometimes huge header files, which in turn lead to number of #ifdefs and stuff like that. In Pascal, a 3-line function was no more than a 3-line function, declared in the scope where it was used, just like the variables. Old Pascal programmers did not see C as any great progress ...

There is no principal difference between classes within classes or functions within functions. The arguments for using or not using it is the same.

One major argument against nested procedures/functions was related to Pascal visibility rules: The tiniest, innermost function doing the simplest helper function had access to all its own local variables, of course, but also everything in the enclosing function, and everything at the next outer level and so on all the way out to the program global variables and functions / routines.

Languages with static nesting was quite common in the 1970s and 80s, and it was used frequently used. (Ask someone learning compilers in those years to explain what a 'static link' is - maybe you'll learn something new!). To handle the issue of the innermost little helper function having the greatest access, to 'everything', some languages required you to export symbols not only to the outside, but also to the inner functions, and the inner functions to import them. (To reduce clutter, some languages let you export/import 'pervasively', so that no further import/export was required for the next levels.)

After shelving Pascal, I have not used much function nesting - for a couple decades, it wasn't possible in C based languages, so I got out of the habit. I cannot recall a single case of nested class definitions. But when I learned of C#, properties and accessors, I became a heavy user of that - which is certainly related.

Religious freedom is the freedom to say that two plus two make five.

GeneralRe: Do you embed classes within classes? Pin
Maximilien29-Apr-24 10:13
Maximilien29-Apr-24 10:13 
GeneralRe: Do you embed classes within classes? PinPopular
OriginalGriff29-Apr-24 2:56
mveOriginalGriff29-Apr-24 2:56 
GeneralRe: Do you embed classes within classes? Pin
charlieg29-Apr-24 3:31
charlieg29-Apr-24 3:31 
GeneralRe: Do you embed classes within classes? Pin
dandy7229-Apr-24 8:56
dandy7229-Apr-24 8:56 
GeneralRe: Do you embed classes within classes? Pin
obermd29-Apr-24 3:19
obermd29-Apr-24 3:19 
GeneralRe: Do you embed classes within classes? Pin
charlieg29-Apr-24 3:59
charlieg29-Apr-24 3:59 
GeneralRe: Do you embed classes within classes? Pin
Salvatore Terress29-Apr-24 15:00
Salvatore Terress29-Apr-24 15:00 
GeneralRe: Do you embed classes within classes? Pin
Matt Bond30-Apr-24 7:38
Matt Bond30-Apr-24 7:38 
GeneralRe: Do you embed classes within classes? Pin
englebart30-Apr-24 15:26
professionalenglebart30-Apr-24 15:26 
GeneralRe: Do you embed classes within classes? Pin
maze329-Apr-24 23:41
professionalmaze329-Apr-24 23:41 
GeneralRe: Do you embed classes within classes? Pin
BernardIE531730-Apr-24 0:28
BernardIE531730-Apr-24 0:28 
GeneralRe: Do you embed classes within classes? Pin
Gary Wheeler30-Apr-24 1:13
Gary Wheeler30-Apr-24 1:13 
GeneralRe: Do you embed classes within classes? Pin
charlieg30-Apr-24 16:45
charlieg30-Apr-24 16:45 
GeneralRe: Do you embed classes within classes? Pin
steve.tabler30-Apr-24 3:20
steve.tabler30-Apr-24 3:20 
GeneralRe: Do you embed classes within classes? Pin
charlieg30-Apr-24 16:49
charlieg30-Apr-24 16:49 
GeneralRe: Do you embed classes within classes? Pin
steve.tabler30-Apr-24 18:35
steve.tabler30-Apr-24 18:35 
GeneralRe: Do you embed classes within classes? Pin
charlieg2-May-24 11:05
charlieg2-May-24 11:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Straw Poll

Were you affected by the geomagnetic storms this past weekend?
Communication disruptions, electrified pipes, random unexplained blue-screens in Windows - the list of effects is terrifying.
  Results   465 votes