New answers tagged

0

To parse a toy language, use a parser generator such as Antlr. The generated parser will keep track of the states for you. While there is no need to manage a state graph for your toy language, state machines in general benefit from the idea of composite states and sub states. See Harel statecharts. If the state machine becomes too messy, you probably did ...


4

I've used the approach you describe, and it does work. However, you have to be careful with what you use it for. You can only use it opportunistically to quickly find some of the places you need to edit. You cannot use it to find all of the places that need editing. The reason you can't do this (or, perhaps more pedantically, it is extremely difficult to ...


0

The answer to this depends 100% on who is going to read your code. What styles do they find most helpful? I have found the most general case is that one avoids reassigning values to function arguments because too many developers have mental models of how function calling works which assume that you never do this. This problem can be exacerbated by ...


-2

I have a completely diffrent problem with your code example: Your method's name is SanitizeName. In this case, I expect it to sanitize a name; because that is, what you tell the reader of your function. The only thing, which you function should do, is sanitizing a given name. Without reading your code, I would expect the following: string SanitizeName(...


6

When you are working on a code-base where you seriously consider this a good idea, it's a sign that you might be working with a horrible mess of spaghetti code. In a well-organized codebase such tags should not be necessary, because each of these functionalities you mention should be contained in a single place. Components should be encapsulated and loosely ...


0

If you use a static code analyzer for security purposes, it may get confused, and think you haven't validated or sanitized the input parameter variable prior to use. If you use Name in a SQL query, for example, it might claim a SQL injection vulnerability, which would cost you time in explaining away. That is bad. On the other hand, using a distinctly named ...


7

I think it depends on your coding conventions in your project. I personally let eclipse automatically add the final keyword to every variable and parameter. This way you see at the first glance if a parameter is reused. In the project at my job we do not recommend to reuse parameters, but if you just want to call e.g. .trim() or set a default in a null ...


-1

The biggest disadvantage of a Data-table is no fixed structure and zero help from IDE. A fellow developer will never know what all columns are present in your datatable unless they apply a break point or have access to the database. Always assume someone else will have to maintain your code.


2

Also some programmers said that there is a good reason to usenull first: if(null == someVariable) Using null first uses a default equality comparator. :-?


10

In general, when it comes to conditionals, it is usually easier to read a positive clause than a negative one. So someVariable == null would be better than someVariable != null - for readability.


1

It can be difficult to learn given the outset of 'I want to learn to code'. However if you can give yourself a small project, like a basic calculator, you'll then have some context to learn the aspects of the language you have chosen. Then just think of new features to add which will give you reason to explore more of the toolbox. To begin with, try and ...


-1

As long as you have interest on coding, you can do it. Not everyone remembers the syntax. It's all by practice and hands-on. You can definitely give it a try and i am sure you will not feel for it later.


1

It's hard to answer this without veering off into general philosophy. What does it mean to not be able to learn something? Is it always just a matter of there being some missing link that all your teachers have taken for granted, or are some people genuinely incapable of learning certain things? How to teach programming is a major topic of interest in ...


6

Programming is a skill like any other. Among other things, that means that learning it by following the outline of sites like codeacademy is probably unrealistic for some (most) people. That isn't to say that those people can't learn, rather that those sites by nature of their design tend to imply that if you've solved problem X you're proficient and ...


2

Since the logic you want to execute is conceptually the same for every "dimension", and the only thing that varies is the array you loop over and the function you call in that loop, I'd simply use a recursive function which takes array and function arguments. I don't know C# all that well, but I assume the core of that approach would look something like this:...


0

Is there any way to bypass the second for loop if dim2.Length = 0? Sure. Use an if statement that reads almost exactly like what you just wrote: int[] dim1, dim2, dim3; //Initialize dim1, dim2 and dim3 for(int i = 0; i < dim1.Length; i++) { DoSomething1(); if (dim2.Length == 0) { for(int k = 0; k < dim3.Length; k++) {...


0

Programming is almost as any other activity/profression you may know. To become a good professional or to reach some grade of "excelency" is matter of 3 things: practice, curiosity and will. The best thing that can happen to you is just what you are worried about. You need to do lot of mistakes and see even more from other programmers. The important thing ...


0

Software development is a trade like any other, except that building effective software is many times harder than building other things, like say a deck. When a carpenter builds a deck there might be 10-15 variables that he or she needs to keep in mind in the process. What wood do I use? What size is the deck? How many people do I need to get it done ...


1

Adobe Acrobat (and other PDF software, as well) has many annotation features. The one that I would recommend is the "rubber stamp". You could have a red X and a green check mark defined as stamps, as an example. You can then plop them down on the PDF image where you want and then re-save the PDF.


1

Well, see it this way: your input scan is already a raster image (the fact those raster grafics are in embedded in PDF is mostly irrelevant), so a raster image based process is all you can expect. Utilizing OCR might be an option, but it would probably only complicate the process with no real benefit and an additional source of potential errors. If you want ...


13

Assimilating the job of a programmer to coding is reductive. Your goal is not to write code, but to solve a given problem—usually through code, but not only code. Once you have a set of requirements, you have to do a set of tasks in order to fulfill them. It can consist of writing code, but also doing architecture, writing deployment scripts, setting up and ...


-1

wrapping each connection in an instance (of a class) allows for easily caching partial messages, thus allowing a single-threaded model to handle all the communications tasks without blocking. (assuming you can figure out how to do non-bloking reads and writes) by being single threaded you avoid the synchronization problems that can plague multi-threaded code....


1

I think the question can be applied to numbers in general (and other data types), not just to IP addresses and ports. Even though numbers are ostensibly just digits, how they're displayed can vary considerably. A common example is digit groupings. A value such as 1999 is often displayed as 1,999 here in the UK. How this number is displayed elsewhere in the ...


3

You should choose integer over string if the values an integer can have and the operations an integer supports are a better fit for the data in question than the values and operations a string has. It is okay if some of the values/operations of that type don't make sense for that data, simply because there are so many different kinds of real-world data that ...


2

When choosing a type, think about: How the variable is used, What are the valid/invalid values, if relevant, How and where the variable is stored and is efficient storage important. Example of an IPv4 address you use for filtering HTTP requests from unwanted machines: The IP will be used to match it with a range of IP addresses, Each part should be ...



Top 50 recent answers are included