what kind of language is that? - c#

I received a piece of code but I cannot understand what kind of language it is. It looks like C# but C# uses the "using" clause in order to import a library where on this programming language file it uses a "use" clause. I cannot find any information about the "use" clause and I am actually confused because this programming language looks like C#/Java/Visual Basic but on these languages I cannot find the use of the "use" clause. The weird thing is that the code doesn't use any methods and the file I received had a .txt extension.
the file starts like that:
use Collection, File, Stream, String, System;
use Date;
include globals.routines.global_routines_generic;
include globals.routines.global_routines_mcc;
include globals.routines.global_classifier;
after that they declare a bunch of variables with the "var" clause and then a part of code looks like that:
File.createFolder(settings.path_files);
foreach(i, Folder in Folders) {
if (dlc.allfolders || String.contains(Folder, dlc.specific_folder)) {
Bestanden = File.iterateFiles(Folder.path, true);
stop_word_list = load_stop_words();
foreach(j, Bestand in Bestanden) {
if (rerun) {
if (!String.contains(Bestand, "ONBEKEND")) {
continue ;
}
}
writeAuditTrail (logfile, String.join(["Processing file " , Bestand]), 0, savelog);
folder_items = String.split(Bestand, "\\\\", false);
last_folder_name = folder_items[Collection.length(folder_items)-2];
dossier_tab = get_dossier_tab(folder_items[Collection.length(folder_items)-1], dlc);
possible_docs = dlc.HR_dossier_tabs[dossier_tab];
Does anyone have any idea what kind of language is that?
Thank you in advance

The code is closest to c++. It is definitely not java due to the fact that java does not have the foreach loop, the use keyword, and var. It is also probably not C# because of the library include syntax. It could be low level pseudo code but it is unlikely due to the syntax being so close to a C based language. enter link description here

Related

The Split method in C# and VB.NET

Thanks for someone who might be able to help me further, as I can't find an answer in the www right now. I actually program VB.net, but since this language is now dissolved and not further developed, I want to switch to C#. I am getting on well, because a lot of things are similar. There is only one method where I am stuck.
In vb.net I always liked to use the method:
mystring.split(seperator)(part)
to get a certain string from a CSV line and work with it. How does this work in C#? I know that I can load everything into an array, but I don't want to do that in this case. A simple split and the number of the element is enough. Can someone help me?
Seems like the same split method is what you need? It returns an array which you could store or just access directly. The difference being in C# you use [index] instead. So something like this:
string myFile = File.ReadAllText("myfile.txt");
string firstLine = myFile.Split("\r\n")[0];

convert VB code to C#

I'm a beginner in programming and i would like to know how can i translate the following code into C#
Dim arrayAlumnos(ds.Tables(0).Rows.Count - 1) As Registro
To preserve the array idea I'd probably write it like:
var arrayAlumnos = new Registro[ds.Tables[0].Rows.Count];
But you could say this too:
Registro[] arrayAlumnos = new Registro[ds.Tables[0].Rows.Count];
But ChaosPandion is right... a List is what you'd want to use most likely.
You should be using a list so I think this is the proper translation.
List<Registro> students = new List<Registro>();
you'll probably have a lot of one off questions like this going through your travels of conversion, might want to take a look at:
http://msdn.microsoft.com/en-us/library/aa288436(v=vs.71).aspx
The basic idea behind the creation in C# is...
~ObjectType~ ~varName~ = new ~type~(~implement a type constructor here~);
anything in between ~~s you'll need to plug in the appropriate information. For your case it would likely be:
Registro[] arrayAlumnos = new Registro[ds.Tables[0].Rows.Count - 1];
Kind of hard since it's a different spoken language but based on your variable name i'm guessing it's an array, though as others pointed out it could easily be created as a list.
FYI, if you want to convert a lot of code from VB to C#, you can use the ILSpy disassebler. You can do this even if you don't have the original VB code. Do this:
Compile the VB code into a *.exe or a *.dll.
Open the *.exe or *.dll file in ILSpy.
In the language dropdown, select VB. (It's values are C#, VB, and MSIL).

c# - beginner wants to add code on the run from a string containing a math function

I learned basic algorithms on visual C# in highschool, and I made a simple code that numerically integrates a math function within given limits.
I want to be able to change the function the code integrates without actually editing the code, so I googled it for a while and found a lot of articles about how to do it. I tired to understand it but the problem is I can't understand any of what's written there because it's too much above my level.
I need a code that can add code on the run from a string containing a math function, that can accept a variable, log, ln, powers, sin, cos, tan and maybe pi and e, that is ready in a friendly "copy-paste" format, followed by instructions on where to paste it, and how to connect it to my code. To clarify:
I want to take something like this:
string s = "Sqrt(ln(1 + x ^ 2))";
and make it like this:
double x = 0;
double y = Math.Sqrt(Math.Log(1 + Math.Pow(x,2)));
I know it's a pretty annoying request and if it's not the right place to ask such a thing I apologize in advance.
This is actually fairly difficult to do in a language like C#, as it's statically compiled.
A good alternative would be to use an expression parsing library, such as NCalc. This library would allow you to create the expression (your string), parse it, and extract the result.

why is this code bad?

Below is a code in C# for rss reader, why this code is bad? this class generates a list of the 5 most recent posts, sorted by title. What do you use to analyze code in C#?
static Story[] Parse(string content)
{
var items = new List<string>();
int start = 0;
while (true)
{
var nextItemStart = content.IndexOf("<item>", start);
var nextItemEnd = content.IndexOf("</item>", nextItemStart);
if (nextItemStart < 0 || nextItemEnd < 0) break;
String nextItem = content.Substring(nextItemStart, nextItemEnd + 7 - nextItemStart);
items.Add(nextItem);
start = nextItemEnd;
}
var stories = new List<Story>();
for (byte i = 0; i < items.Count; i++)
{
stories.Add(new Story()
{
title = Regex.Match(items[i], "(?<=<title>).*(?=</title>)").Value,
link = Regex.Match(items[i], "(?<=<link>).*(?=</link>)").Value,
date = Regex.Match(items[i], "(?<=<pubDate>).*(?=</pubdate>)").Value
});
}
return stories.ToArray();
}
why don't use XmlReader or XmlDocument or LINQ to Xml?
It is bad because it's using string parsing when there are excellent classes in the framework for parsing XML. Even better, there are classes to deal with RSS feeds.
ETA:
Sorry to not have answered your second question earlier. There are a great number of tools to analyze correctness and quality of C# code. There's probably a huge list compiled somewhere, but here's a few I use on a daily basis to help ensure quality code:
StyleCop (code formatting standards)
Resharper (idiomatic programming, gotcha catching)
FxCop (code correctness, standards adherence, idiomatic programming)
Pex (white box testing)
Nitriq (code quality metrics)
NUnit (unit testing)
You shouldn't parse XML with string functions and regular expressions. XML can get very complicated and be formatted many ways that a real XML parser like XmlReader can handle, but will break your simple string parsing code.
Basically: don't try and reinvent the wheel (an xml parser), especially when you don't realize how complicated that wheel actually is.
I think the worst thing for the code is the performance issue. You should parse the xml string into a XDocument(or similar structure) instead of parse it again and again using regex.
simply because you are reinventing a xml parser , use Linq to xml instead, it is very simple and clean.I am sure that you can do all the above in three lines of code if you use Linq to XML , your code uses a lot of magic numbers (ex: 7-n ..), the thing that make it unstable and non generic
For starters, it uses byte as a indexer instead of int (what if items has more items in it than a byte can represent?). It doesn't use idiomatic C# (see user1645569's response). It also unnecessarily uses var instead of specific data types (that's more stylistic though, but for me I prefer not to, hence by my metric it's not ideal (and you've given no other metric)).
Let me clarify what I am saying about "unnecessarily using var": var in and of itself is not bad, and I am not suggesting that. I am (mostly) suggesting the usage here isn't very consistent. For example, explicitly declaring start as an int, but then declaring nextItemEnd as var (which will deduce to int) and assigning nextItemEnd to start seems (to me) like a weird mixture between wanting to automatically deduce a variable's type and explicitly declaring it. I think it's good that var was not used in start's declaration (because then it's not exactly clear if the intent is an integer or a floating point number), but I (personally) don't think it helps any to declare nextItemStart and nextItemEnd as var. I tend to prefer to use var for more complex/longer data types (similar to how I use auto in C++ for iterators, but not for "simpler" data types).

C# string translation

Does C# offer a way to translate strings on-the-fly or something similiar?
I'm now working on some legacy code, which has some parts like this:
section.AddParagraph(String.Format("Premise: {0}", currentReport.Tenant.Code));
section.AddParagraph(String.Format("Description: {0}", currentReport.Tenant.Name));
section.AddParagraph();
section.AddParagraph(String.Format("Issued: #{0:D5}", currentReport.Id));
section.AddParagraph(String.Format("Date: {0}", currentReport.Timestamp.ToString(
"dd MMM yyyy", CultureInfo.InvariantCulture)));
section.AddParagraph(String.Format("Time: {0:HH:mm}", currentReport.Timestamp));
So, I want to implement the translation of these strings on-the-fly based on some substitution table (for example, as Qt does).
Is this possible (probably, using something what C# already has or using some post-processing - may be possible with PostSharp)?
Does some generic internalization approach for applications built with C# (from scratch) exist?
Does some generic internalization approach for applications built with C# (from scratch) exist?
Yes, using resource files. And here's another article on MSDN.
In the C# project I currently work on, we wrote a helper function that works like this:
section.AddParagraph(I18n.Translate("Premise: {0}", currentReport.Tenant.Code));
section.AddParagraph(I18n.Translate("That's all");
At build time, a script searches all I18n.Translate invocations, as well as all UI controls, and populates a table with all english phrases. This gets translated.
At runtime, the english text is looked up in a dictionary, and replaced with the translated text.
Something similar happens to our winforms Dialog resources: they are constructed in english and then translated using the same dictionary.
The biggest strength of this scheme, is also the biggest weakness: If you use the same string in two places, it gets translated the same. This shortens the file you send to translater which helps to reduce cost. If you ever need to force a different translation of the same english word, you need to work around that. As long as we have the system (4ish years or so), we never had the need for it. There's also benefits: You read the english UI text inline with the source (so not hiding behind an identifier you need to name), and if you delete code, its automatically removed from the translated resources as well.

Categories

Resources