Golang Static vs dynamic binding for objects [closed] - reflection

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have this application where requests are filtered based on the string in the struct and made to execute different functions.
My approach is to have a Map which maps the strings to the function pointers and execute them. However this approach is being contended by a teammate who wants to do this filtering by reflection. We are using Go and it is for monitoring the activity of our site.
Teammates approach: Use reflection to switch the object based on the string, pass the string to the function and let the function call the relevant function.
My approach: Simple map from string to functions
Any help is appreciated.

Downside of reflection based auto-discovery is that you forever have to be careful on what you add to the system because it can be automatically picked up.
vs map approach where you would need to explicitly expose each function.
Reflection is more cool and auto-magical, for sure. But auto-magical doesn't lend it self very well to security or long term maintainability.
Plus, a map[string]func(with specific signature) won't compile if you attempt register a non-matching function.
Where you will find stuff with reflection and then ponder why it's a runtime fail.

Related

The paradigm of annotations [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I'm new to Symfony and I was really surprised when I saw that very important parts of program logic are "hidden" in the annotations. Or actually in PHP comments. I understand, these annotations are used by the libraries, but is not it a bad solution overall - couldn't it be made differently? What is the logic behind that? From my prospective they make the code hard to understand, they are not processed by atom (or can I install some plugin for this?..), and it's overall strange idea. No?)
All That configuration can be stored in php/xml/yml files.
From my experience the idea of annotation is very convenient.
For example, you look at controller , and you see route (link to call controller action), data passed ( Parameter Converter).
If it is done right, you have all the important data in one place, just above your code.
Processing annotation by IDE it's a different story.
Check if there is any atom plugin for this , or change IDE that can handle this.
Personally, i'm using phpstrom , and i don't have any issue with annotations

Web API, where to put private methods? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
So I was wondering the other day, where to put private methods, that do some dirty work in Web API.
I need to extract certain things from JSON, methods will do the job and return some result.
So where do I keep those methods?
do I need to write a separate library (dll)?
or just do this stuff in the controller?
I don’t think it can have a single answer – it depends on…
If you think this private method can be reused from some other controller in future, better to have a separate class, if you think it can be reused from separate modules (not just from controllers), a separate class library project can be the answer.
But if you consider this private method is designed to support for a specific action of a controller, you can write within controller, before taking any decision a few more parameters to be considered like unit testability or slimness of API etc.
You should keep your controller thin as much as possible. You can move logic code to service package, for example JSONService class or JSONLib.
I often use following layout:
controller/
lib/
service/
model/

Webservice performance - Separate ASMX for each function or both functions inside the same ASMX? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am using ASMX web services.
I have two functions so, should I create two functions in a single ASMX or should I create separate ASMX for each function?
Does that impact performance? Which choice will have the highest performance?
With all things performance you need to profile it before making changes to increase performance otherwise you could end up optimizing the wrong thing.
Most of the times the Pareto principle applies, a small portion of code or a few modules in the entire application are responsible for most of the execution time. Making optimizations there will have the greatest impact on performance.
Have you optimized everything that could be optimized and drawn the conclusion that the service endpoint can cause performance issues?
You should write the code how it's easier to maintain. Do those two functions belong together or are they completely unrelated? Does it make sense to have them exposed through one ASMX or two? That should be your criteria for how to define your endpoints.
My guess is that both choices will have similar performance but if you absolutely need to know build them both ways, profile them, and see which one performs better.

Can I write go library to be used from another languages? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm writing relatively small, but not simple networking library which is going to be used at least from C,java,python,ruby and C#. Is there a way to make go bindings to the other languages the way in can be done form C? If not is there other way?
Right now, you can't write libraries in Go that can be used in other languages. Go has a runtime environment that does a lot of things (like sheduling go-routines, collecting garbage) for you. This runtime environment is written under the assumption that it controls the whole program. This assumption does not hold if Go code would be used from inside another language, as the Go library cannot influence the binary that uses it.
I imagine that a JSON service would do what you describe.
Have a look at the json test for a simple example
It wouldnt matter what languages you used to set and get data from your app

Symfony2 Service and Trait Best Practices for small chunks of code [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
In Symfony2 (could apply to other frameworks too) are there any factually based best practices defined for when to put a small chunk of reusable code in a trait as oppose to a service (or even in a model)?
e.g. scenario:
I had a small piece of code which modified a url slightly (added a specific port based on the current environment and machine). It was used by several controllers. I was told this would be best in a trait as a service would be overkill because it was only a few lines of code and there was only one parameter being passed to the function (the url).
Symfony2 manual defines a service as:
"a generic term for any PHP object that performs a specific task."
There may be some subjective opinions here, but the question guidelines say:
Great subjective questions inspire answers that explain “why” and
“how” and Great subjective questions insist that opinion be backed up
with facts and references
And that is what I am looking for. Factual reasons why or why not to use a trait over a service for a small chunk of code.
Update
A great suggestion has been: traits aren't easy to test whereas services are

Resources