Things that defined by WebIDL - firefox

After reading this post,
http://mcc.id.au/2013/lca-webidl/
I have some questions in the page 20,
What happens when you pass too many/few arguments.
What happens when you grab a Function corresponding to an IDL operation and apply it to some other type of object.
How interface inheritance corresponds to a prototype chain.
How DOM objects are stringified.
Can anyone give a specific explanation or example to these points.
Thanks

If you pass too many arguments the extra ones are ignored. Try document.getElementsByTagName("a", "b"). If you pass too few, you get an exception: document.getElementsByTagName().
If you apply a WebIDL operation to the wrong type of object, you get an exception. See http://heycam.github.io/webidl/#es-operations step 4 under "Try running the following steps". document.getElementsByTagName.call(document.body, "div") for example.
Interface inheritance corresponds to a prototype chain as described at http://heycam.github.io/webidl/#interface-prototype-object but in brief if you have interface Foo : Bar { }; then Object.getPrototypeOf(Foo.prototype) === Bar.prototype. So for example, the prototype of HTMLElement.prototype is Element.prototype.
DOM objects with a stringifier defined (e.g. HTMLAnchorElement) are stringified however the relevant specification defines them to be. All other objects become "[object MostDerivedInterfaceName]".

Related

How to check where a who calls this method?

I have a custom method in an ABAP class.
I used the 'Where used' tool to show where the class is called from but, as it turns out, it's called from somewhere else I didn't expect.
So what's the best way of showing a complete list of everything that calls the method?
Due to the wonders of object-oriented programming, an instance of a class can hide behind a reference to one of its base classes or interfaces it implements. For example:
DATA foo TYPE REF TO z_my_interface.
CREATE OBJECT foo TYPE z_my_class.
" lots of more code
foo->bar( ).
You can not find this reference to z_my_class->foo with its "Where Used" list, because at that code location foo could also be a reference to an instance of any other class which implements z_my_interface. But you might be able to find this if you don't just look at the where-used list of the method but at the where-used list of the whole class or the interface / base class which declares the method.
And then there are evil dynamic programming tricks like this which determine methods and classes at runtime:
DATA foo TYPE REF TO object.
CONSTANTS: classname TYPE string VALUE 'Z_MY_CLASS',
methodname TYPE string VALUE 'BAR'.
CREATE OBJECT foo TYPE (classname).
CALL METHOD foo->(methodname).
There is no chance to find this with the where-used tool. But if the class- and/or method name does actually appear in the code (it might not, for example if they are read from a customizing table) then you can use the report RS_ABAP_SOURCE_SCAN. This handy little tool allows you to select a set of ABAP programs and search for strings (and even regular expressions) within their sourcecodes.
However, if you know the method gets called when you do something specific as a user and just want to know where, then it can be easier to just set a debugger breakpoint in the method, run into it and check the call stack.
Sorted using the code_scanner transaction.

Why do Flux architecture examples use constants for action types instead of strings?

Throughout the examples and explanations of Flux architecture -- Facebook's counterpart to React -- action type names are referenced as enum constants rather than strings. (See examples at http://facebook.github.io/flux/) I am just looking for an articulation of why this is the preferred method.
I do not see a benefit in terms of authoring & convenience, because whether you type constants.actionTypes.UPDATE_DATA (enum constant) or 'UPDATE_DATA' (string), you have to know and type out the exact name. In fact, sometimes the use of non-strings adds complexity -- e.g. you can't as easily make an object with action types as keys and action handlers as values.
Are the benefits in organization, minification, or something else? I'm curious.
You touched on it at the end of your question, but there are a couple benefits. Minification is an obvious one; another is the fact that static analysis tools can more easily find usages and catch errors.
Depending on your flux implementation, they can also help you catch typos. For example, in Fluxxor, if you try to bind a store handler to an action type of undefined, you'll get an exception; that means that passing c.UPDATE_DTA will throw, but passing 'UPDATE_DTA' will not.
Finally, they can help serve as documentation. If all the action types that your application generates are defined centrally as constants, it becomes easier to tell at-a-glance what kinds of operations the system as a whole responds to.
There's an ES6 feature that is available with Babel or Traceur (but not with the JSX transform at this time) that helps create object literals; the syntax is:
var handlers = {
[const.UPDATE_DATA]: this.handleUpdateData,
[const.OTHER_THING]: this.handleOtherThing
};

In Xcode, is there a way to list only relevant methods for an object?

Is there some way in Xcode to enter an object's name, and then get a list of the methods that can be used with that object, sorted either hierarchically by inheritance or by return value type?
I know you can get a list of methods by pressing Control-Space after entering the object's name in standard bracket messaging syntax; however, this list often contains numerous methods that are not applicable to the given object. As a result, you still have to scroll through a bunch of garbage, and then look up the class definitions for the object, or reference custom object implementations you have created in order to see which methods will work.

Coding Style: How to Make Obvious Determination of Parameter's Type We Have To Pass To a Function?

What is the best way to document the type of parameters that a function expects to receive?
Sometimes a function uses only one or two fields of an object. Sometimes this fields have common names (get(), set(), reset(), etc.). In this situation we must leave a comments:
...
#staticmethod
def get( postId, obj ):
"""obj is instance of class Type1, not Type2"""
inner = obj.get()
Is there a more explicit way to make it obvious? Maybe an object name should contain expecting typename?
Given python's 'duck-typing' (late bound) behaviour, it would be a mistake to require a particular type.
If you know which types your function must not take, you can raise an exception after detecting those; otherwise, simply raise an exception if the object passed does not support the appropriate protocol.
As to documentation, just put the required protocol in the docstring.
One strength of python is "duck typing", that is not to rely on the actual type of a variable, but on its behaviour. So I'd suggest, that you document the field, that the object should contain.
"""obj should have a field 'foo' like in class 'bar' or 'baz' """
First of all, name your methods properly, and use properties if they make sense.
You should try to get the hang of duck-typing. It's pretty useful. And if not, try and see if abstract base classes helps you do what you want.

Philosophy Object/Properties Parameter Query

I'm looking at some code I've written and thinking "should I be passing that object into the method or just some of its properties?".
Let me explain:
This object has about 15 properties - user inputs. I then have about 10 methods that use upto 5 of these inputs. Now, the interface looks a lot cleaner, if each method has 1 parameter - the "user inputs object". But each method does not need all of these properties. I could just pass the properties that each method needs.
The fact I'm asking this question indicates I accept I may be doing things wrong.
Discuss......:)
EDIT: To add calrity:
From a web page a user enters details about their house and garden. Number of doors, number of rooms and other properties of this nature (15 in total).
These details are stored on a "HouseDetails" object as simple integer properties.
An instance of "HouseDetails" is passed into "HouseRequirementsCalculator". This class has 10 private methods like "calculate area of carpet", "caclulateExtensionPotential" etc.
For an example of my query, let's use "CalculateAreaOfCarpet" method.
should I pass the "HouseDetails" object
or should I pass "HouseDetails.MainRoomArea, HouseDetails.KitchenArea, HouseDetails.BathroomArea" etc
Based on my answer above and related to your edit:
a) You should pass the "HouseDetails"
object
Other thoughts:
Thinking more about your question and especially the added detail i'm left wondering why you would not just include those calculation methods as part of your HouseDetails object. After all, they are calculations that are specific to that object only. Why create an interface and another class to manage the calculations separately?
Older text:
Each method should and will know what part of the passed-in object it needs to reference to get its job done. You don't/shouldn't need to enforce this knowledge by creating fine-grained overloads in your interface. The passed-in object is your model and your contract.
Also, imagine how much code will be affected if you add and remove a property from this object. Keep it simple.
Passing individual properties - and different in each case - seems pretty messy. I'd rather pass whole objects.
Mind that you gave not enough insight into your situation. Perhaps try to describe the actual usage of this things? What is this object with 15 properties?, are those "10 methods that use upto 5 of these input" on the same object, or some other one?
After the question been edited
I should definitely go with passing the whole object and do the necessary calculations in the Calculator class.
On the other hand you may find Domain Driven Design an attractive alternative (http://en.wikipedia.org/wiki/Domain-driven_design). With regard to that principles you could add methods from calculator to the HouseDetails class. Domain Driven Design is quite nice style of writing apps, just depends how clean this way is for you.

Resources