I have a structure called Employee. This structure contain another structures like EmployeeSalary and EmployeePerformanceData. I have to delete the structure EmployeePerformanceData from the parent structure Employee. How Can I acheive this in Coldfusion.
When wondering how to do stuff in a programming language, googling the problem is the best place to start. I googled "How to delete a structure inside another structure in ColdFusion" (ie: the title of your question), and two of the first five results (the first result is this question ;-) answer your question:
Deleting structure elements and structures
GETTING STARTED WITH STRUCTURES IN COLDFUSION
And a third would get you on the right track, as it lists all the possible struct functions in CFML: "Structure functions"
So having looked at those, the answer seems to be:
structDelete(Employee, "EmployeePerformanceData");
(When I say "seems to be", I mean "it is")
Well, sometimes googling these things doesn't point to the right answer.
To delete structures within other structures
<cfset StructDelete(myStruct.mySubStruct.mySubSubStruct,"keyName")>
Et voilĂ .
Related
I frequently see the use of tuples, in contrast to lists, which are mutable. As an intermediate programmer in high school, I am still confused as to the usefulness of tuples.
Are there any other reasons to use them besides their immutability (which is the major response I see to this question)? I know lists can be changed, but is that really such a big problem when programming, other than 'accidents' that might change a list you don't want changed?
Another reason I see, like in this post -- https://stackoverflow.com/questions/30518013/is-there-a-difference-between-a-list-and-a-tuple -- is that you can imagine them different conceptually, such as by imagining them as coordinates, rather than an array of numbers. But this isn't really a function, but a practice that arose because of the freedom for an unchanging structure that tuples supposedly give.
What I'm asking is there a need to have defined a totally new data structure that doesn't really serve a new purpose in my opinion. Thanks! hope this question isn't too dumb :\
Tuples are immutable
Tuples can describe things like coordinates and dimensionality better than list
To guard against accidents
Tuples can be put into set and used as keys for dict
This is for an assignment, so I don't need code or an exact answer, just a guide in the right direction. The problem states to create an array of student structs. The structs would hold basic student information. That part I can easily do. The next part of the question says to "write the same program without using structs". How on earth would I do this? The only somewhat crazy idea I can come up with would be to use a multidimensional array, in which each row corresponded to a student and each column held the varying information for that student. Is there a better way to do this? I am writing in C++
i'm self learning C++ (using schaum's programming with c++ book), and i can't find anything in the book that explains how to create a collection of objects?
For example say you have a class of books, and a class of stores, and you want to create a collection of book objects in the store class, how would this be implemented?
I'm confused as with arrays you have to give a set size don't you? So what if you don't yet know the size needed? I'm assuming an array is not the best thing to use...
Also sorry if the book/store class example is a bad example. :)
You seem to be catching on quickly. No, arrays are generally not the best thing to use.
The standard library has a number of collection classes such as vector, deque, list, set, map, etc. From the sound of things, you might want a vector or a multimap. A vector is pretty much like an array, except that it resizes as needed when you insert objects. A map gives you the ability to look things up based on a field, such as looking a book up based on the title or author.
The S of the famous Object Oriented Programming design stands for:
Single responsibility principle, the notion that an object should have
only a single responsibility.
I was wondering, can this principle, be extended even to arrays, variables, and all the elements of a program?
For example, let's say we have:
int A[100];
And we use it to store the result of a function, but somehow we use the same A[100] to check, for example, what indexes of A have we already checked and elaborated.
Could this be considered wrong? Shouldn't we create another element to store, for example, the indexes that we have already checked? Isn't this an hint of future messy code?
PS: I'm sorry if my question is not comprehensible but English is not my primary language. If you have any problem understanding the point of it please let me know in a comment below.
If same A instance is used in different program code portions you must follow this principle. If A is a auxiliary variable, local one for example, I think you don't need to be care about it.
If you are tracking the use of bits of the array that have been updated, then you probably shouldn't be using an array, but a map instead.
In any case, if you need that sort of extra control over the array, then basically, you should be considering a class that contains both the contents of the array and the various information about what has and hasn't been done. So your array becomes local to the class object, as do your controls, and voila. You have single responsibility again.
I have a quick question for you all. I'm trying to convert over some ActionScript code to C++ and am having a difficult time with this one line:
private var edges:Vector.<Array>
What is this exactly? Is this essentially a multidimensional vector then? Or is this simply declaring the vector as a container? I understand from researching that vectors, like C++ vectors, have to be declared with a type. However, in C++ I can't just put down Array, I have to use another vector (probably) so it looks like:
vector<vector<T> example;
or possibly even
vector<int[]> example;
I don't expect you guys to know the C++ equivalent because I'm primarily posting this with AS tags, but if you could confirm my understand of the AS half, that would be great. I did some googling but didn't find any cases where someone used Array as it's type.
From Mike Chambers (adobe evangelist) :
"Essentially, the Vector class is a typed Array, and in addition to ensuring your collection is type safe, can also provide (sometimes significant) performance improvements over using an Array."
http://www.mikechambers.com/blog/2008/08/19/using-vectors-in-actionscript-3-and-flash-player-10/
Essentially the vector in C++ is based on the same principles. As far as porting a vector of Arrays in AS3 to C++, well that's not a conversion that is clear cut in principle, as you could have a collection (array) of various types in C++, such as a char array. However, it appears you've got the idea, as you've pretty much posted examples of both avenues in your question.
I would post some code but I think you've got it exactly. Weather you use a vector within a vector or you declare a specifically typed collection I think comes down to a matter of what works best for you specific project.
Also you might be interested in:
http://www.mikechambers.com/blog/2008/09/24/actioscript-3-vector-array-performance-comparison/