Is it possible to rewrite any code that uses pointers (C#) without using pointers in Node.js?

Asked

Viewed 139 times

0

It is possible to rewrite any code in C/C# that uses pointers in a way that does the same thing without using them?

My fear is more complex codes. The simple ones I believe are not difficult to rewrite.

How to replace pointers using the same concept in Javascript?

  • 1

    @Lucas Duete, I believe the question is pertinent, but I’m sorry anyway. I’m editing the question to see if it improves and becomes more objective. Anyway, thank you very much.

2 answers

1


Possible is yes, all programming languages can do anything. The issue is the work that gives, is usually so much, the risk is so great, that rewriting will be bad, writing the same thing from scratch is much more interesting.

If the code is in C# it is unlikely to use any pointer. It is very rare to see the use of pointer in C#, and now almost all situations no longer need, and where it needs is in something that makes no sense to port to Node. C depends on a lot of things, but it doesn’t make much sense to do this kind of conversion.

Furthermore, if you have good code running in C or C++ or C# I don’t understand why you want to convert it to Javascript mainly to run on Node. O . NET has the same capacity and is absurdly faster than Node/Deno. If you have the code that solves your problem, use it directly. Why exchange for a language less robust?

If you think you’re going to take a language and turn the instruction-by-instruction code into another language, don’t start, because it’s not just that it doesn’t happen, it means you have an ingenuity that will surely result in the bad ending. There’s no magic, there’s no free lunch. Whatever you’re trying to do, there’s no guy that’s gonna work. An experienced person knows that even it would not have good result and probably would not do it. She would understand the problem and write code even better. Or she would use the right tool. If you want to do this you must master (really) all these languages, it is the only chance to work, and then it starts to make less sense to convert, so no one does it.

All objects in JS are types by reference. The pointer is what causes something to be accessed as a reference, so anything that encapsulates into an object is using a pointer. The fact that you don’t know this, and no problem people don’t know because you don’t need to use something like this, shows you’re not ready to do the conversion, this is the easy part, you’ll find a lot of difficulty in the way you won’t know how to handle, so it’s a doomed project. I’m sorry, but that’s not the answer.

  • Thanks for the answer. Maybe you misunderstood me... I understood perfectly what you meant, and I agree, it doesn’t make sense to rewrite something that’s ready. The question is this: I have a C# project and I would like to have it running on Node (for some reasons), this project uses a library written by a person using this resource, i would like to understand why and how it uses and write in Javascript something that had the same result (or even better), I needed to know if the fact to be using it in C# would not make it impossible to reproduce in Node.

  • It doesn’t really make sense, so I told you to use the language that already has what you want and not to rewrite, I told you to give up the Node and use what you have in C# ready, in C# even. You didn’t understand that. " I have a C# project and I would like to have it running on Node" this is desire, not need, so drop this idea and be happy. If the motivation were real, I would have even asked the question. In general, the answer is that everything can be converted, but it should not. In the specific also I answered. And I showed you the right way too, it’s all in the answer.

  • What he commented is the opposite of what he wants to do: "I would like to understand why and how he uses and write in Javascript something that has the same result (or even better)". Having the same result is not carrying the code is understanding and making another code, port does not work in almost all situations, and when it does it is just that it dominates a lot what it is doing. And it’s not going to be better at any rate, it’s going to be bad, you should just do it as a last resort, and admit it’s going to be bad. My experience is this, but it’s your right to do it the wrong way, the alert has been given.

  • As I said, I understood your point, but I still fear that you have expressed me badly and you have not understood me. I am accepting the answer. But I want to add that I managed to do what I needed, the application is done in C#. I want to play it in Nodejs (and it’s not just a matter of taste, it even involves costs). This question of pointers relates to a specific class that the application uses, and I needed to have this library rewritten in Node to complete the application. After some time studying, I managed.

0

I’ll give you a very superfluous answer but it’s easy to understand, (sorry the people who like things to the letter)

The first point is you understand what pointers do in languages like c Pointers are used to pass by reference and in object-oriented languages usually every object is already implied that there is a passage by reference

    function funcao(obj){
       //Qualquer codigo que altere o obj aqui dentro reflete fora do escopo da função pois é implicito que o objeto tem uma passagem por referência
    }

I mean you use pointers without knowing you’re using.

  • agree. in fact, for those who come to have this same doubt, just understand a little better how the pointers work (the question of reference, memory addresses and etc.), I studied a little more, made some simple codes and replicated them with Javascript. when the results were hitting, I followed the logic to write what I needed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.