Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "linq"
-
After listening to two of our senior devs play ping pong with a new member of our team for TWO DAYS!
DevA: "Try this.."
Junior: "Didn't work"
DevB: "Try that .."
Junior: "Still not working"
I ask..
Me:"What is the problem?"
Few ums...uhs..awkward seconds of silence
Junior: "App is really slow. Takes several seconds to launch and searching either crashes or takes a really long time."
DevA: "We've isolated the issue with Entity Framework. That application was written back when we used VS2010. Since that application isn't used very often, no one has had to update it since."
DevB: "Weird part is the app takes up over 3 gigs of ram. Its obviously a caching issue. We might have to open up a ticket with Microsoft."
Me: "Or remove EF and use ADO."
DevB: "That would be way too much work. The app is supposed to be fully deprecated and replaced this year."
Me: "Three of you for the past two days seems like a lot of work. If EF is the problem, you remove EF."
DevA: "The solution is way too complicated for that. There are 5 projects and 3 of those have circular dependencies. Its a mess."
DevB: "No fracking kidding...if it were written correctly the first time. There aren't even any fracking tests."
Me:"Pretty sure there are only two tables involved, maybe 3 stored procedures. A simple CRUD app like this should be fairly straight forward."
DevB: "Can't re-write the application, company won't allow it. A redesign of this magnitute could take months. If we can't fix the LINQ query, we'll going to have the DBAs change the structures to make the application faster. I don't see any other way."
Holy frack...he didn't just say that.
Over my lunch hour, I strip down the WPF application to the basics (too much to write about, but the included projects only had one or two files), and created an integration test for refactoring the data access to use ADO. After all the tests and EF removed, the app starts up instantly and searches are also instant. Didn't click through all the UI, but the basics worked.
Sat with Junior, pointed out my changes (the 'why' behind the 'what') ...and he how he could write unit tests around the ViewModel behavior in the UI (and making any changes to the data access as needed).
Today's standup:
Junior: "Employee app is fixed. Had some help removing Entity Framework and how it starts up fast and and searches are instant. Going to write unit tests today to verify the UI behaivor. I'll be able to deploy the application tomorrow."
DevA: "What?! No way! You did all that yesterday?"
Me: "I removed the Entity Framework over my lunch hour. Like I said, its basic CRUD and mostly in stored procedures. All the data points are covered by integration tests, but didn't have time for the unit tests. It's likely I broke some UI behavior, but the unit tests should catch those."
DevB: "I was going to do that today. I knew taking out Entity Framework wouldn't be a big deal."
Holy fracking frack. You fracking lying SOB. Deeeep breath...ahhh...thanks devRant. Flame thrower event diverted.13 -
I was searching through StackOverflow when I found this guy:
He is using a "dot operator" in LINQ at the end of the Query
Example:
a.Where().
Select();
Not
a.Where()
.Select();
How barbaric2 -
I just rewrote a linq-2sql query which cut the execution time down from 17 minutes to 20 seconds! I felt like a genius for all of five seconds, until I realised it was me who had written the original query... Now I don't know if I'm an idiot or a genius...8
-
I got a 9.8/10 for my programming test. I went to ask the teacher what the issue was. He showed me my test but there was no red mark anywhere. So I asked why, and he said it's because I used LINQ, and I couldn't use it because others students might not know it...
I bet you he doesn't understand it aswell...10 -
Hey I got reminded of a funny story.
A friend of mine and me were in internships in the same company. The company was specialized in territory resources management (managing water for agriculture, money to build industrial zones...). He got the interesting internship (water predictory modeling) and I got... The repairs of a reference sheet manager that never happened to work. It was in C# and ASP.NET and I was in second year of CS. I expected the code to be nice and clear since it was made by a just graduated engineer with +5years of studies.
I was very wrong.
This guy may never have touched a web server in his life, used static variables to keep sessions instead of... well... sessions, did code everything in the pages event handlers (even LinQ stuff et al) and I was told to make it maintainable, efficient and functional in 2 months. There were files with +32k LoC.
After 1week of immense despair, I decided I will refactor all the code. Make nice classes, mapping layer, something close to a MVC... So I lost time and got scoled for not being able to make all the modifications as fast as in a cleanly designed code...
After 4 weeks, everything was refactored and I got to wait for the design sheets to change some crystal report views.
At this moment I began to understand were was the problem in this company.
My friend next door got asked to stop his modeling stuff for an emergency project. He had to make an XML converter for our clients to be able to send decentralized electrics bills, and if it was not completed within a week, they would no longer be able to pay until it is done.
This XML converter was a project scheduled 5 years before that. Nobody wanted to do it.
At the same time, I was waiting for the Com Department to give me the design views.
I never saw the design views. Spent one month implementing a golden ratio calculator with arbitrary precision because they ain't give me anything to do until the design were implemented.
Ended with a poor grade because "the work wasn't finished".2 -
I've been using microsoft dev stack for as long as i remember. Since I picked up C#/.NET in 2002 I haven't looked back. I got spoiled by things like type safety, generics, LINQ and its functional twist on C#, await/async, and Visual Studio, the best IDE one could ask for.
Over the past few years though, I've seen the rise of many competing open source stacks that get many things right, e.g. command line tooling, package management, CI, CD, containerization, and Linux friendliness. In general many of those frameworks are more Mac friendly than Windows. Microsoft started sobering up to this fact and started open sourcing its frameworks and tools, and generally being more Mac/Linux friendly, but I think that, first, it's a bit too late, and second, it's not mature yet; not even comparable to what you get on VS + Windows.
More recently I switched jobs and I'm mainly using Mac, Python, and some Java. I've also used node in a couple of small projects. My feeling: even though I may be resisting change, I genuinely feel that C# is a better designed language than Java, and I feel that static type languages are far superior to dynamic ones, especially on large projects with large number of developers. I get that dynamic languages gives you a productivity boost, and they make you feel liberated, but most of the time I feel that this productivity is lost when you have to compensate for type safety with more unit tests that would not be necessary in a static type language, also you tend to get subtle bugs that are only manifested at runtime.
So I'm really torn: enjoy world class development platform and language, but sacrifice large ecosystem of open source tools and practices that get the devops culture; or be content with less polished frameworks/languages but much larger community that gets how apps should be built, deployed, monitored, etc.
Damn you Microsoft for coming late to the open source party.11 -
!rant
Reduced a page load time from 23.8 seconds to 0.5 seconds by disabling tracking of entities on the page. Felt awesome.4 -
I'm so fucking tired of OOP.
This bullshit never ends. Everyone treats OOP in their own, proper (of course) way. You read tons of those fashion books, like uncle bob and shit. and then comes a dumb asshole that starts reviewing your code, and tells you doing it wrong. FUCK. and you can't tell anything to your TL or PM cuz they are same dumb asholes. Because after you fix all the bullshit from the first asshole, those more responsible assholes come and tell you that you still doing it wrong.
- uh.. bruh, why don't you make interface for everything? that' S.O.L.I.D, you know.. it just right thing.
- bruh, why don't you use enum and switch case. we need a factory.
- bruh, we don't use abstract classes, use interface
- could you rewrite your linq/stream thing into a class and a method. it's just simpler for us. foreach loop is something everyone knows.
well,then go and LEARN the tool you're dealing with, coderfucker.
FUUUUCK.13 -
Oh man where to start:
Not wanting to use LINQ because he did not wanted to "download external dependencies"
Not wanting to use prepared statements on their php sql code, and refusing to use pdo because they will "always use mysql"(moved to postgreSQL shortly after I left)
For some reason including a php file that only had ?>......thats it....only ?>
Use c++ but refused to learn oop and use structs for everything, importing stdio.h and printf everything.....like really?
Maybe just nitpicking, but refusing to use the recyclerview pattern on am android app. The implementation was faster after I made the change.
Importing a library for promises instead of using the ones already in the language(JS)
Changing the style of aaaaall p tags instead of using classes as well as refusing to use divs in place of p tags...well...fuck
Not indent his ASP classic code
Use notepad on his asp classic code
Use ASP Classic in 2017, even for new projects6 -
How do you deal with massively poorly-performing and unknowledgeable teams?
For background, I've been in my current position for ~7 months now.
A new manager joined recently and he's just floored at the reality of the team.
I mean, a large portion of my interview (and his) was the existing manager explicitly warning about how much of a dumpster fire everything is.
But still, nothing prepares you for it.
We're talking things like:
- Sequential integer user ids that are passable as query string args to anonymous endpoints, thus enabling you to view the data read by that view *for any* user.
- God-like lookup tables that all manner of pieces of data are shoved into as a catch-all
- A continued focus on unnecessary stored procedures despite us being a Linq shop
- Complete lack of awareness of SOLID principles
- Actual FUD around the simplest of things like interfaces, inversion of control, dependency injection (and the list goes on).
I've been elevated into this sort of quasi-senior position (in all but title - and salary), and I find myself having to navigate a daily struggle of trying to not have an absolute shit fit every time I have to dive into the depths of some of the code.
Compounded onto that is the knowledge that most of the team are on comparable salaries (within a couple thousand) of mine, purely owing to length of service.
We're talking salaries for mid-senior level devs, for people that at market rates would command no more (if even close) than a junior rate.
The problem is that I'm aware of how bad things are, but then somehow I'm constantly surprised and confronted with ever more insane levels of shitfuckery, and... I'm getting tired.
It's been 7 months, I love the job, I'm working in the charity sector and I love the fact that the things I'm working on are directly improving people's lives, rather than lining some fintech fatcat's pockets.
I guess this was more a rant than a question, and also long time no see...
So my question is this:
- How do you deal with this?
- How do you go on without just dying inside every single day?8 -
Worst thing? Absuse LINQ and not in a fun sexy way.
Entity framework > check.
LINQ query > check.
Standard IEnunerable magic > check
The developer had decided that it would be a good idea to thread the enumerable all over the place and collapse it anytime they wanted access to the data.
I know it’s a rookie mistake a lot of people make, but it was some pretty core data that ended up being used all over the place, so it was a nightmare to correct and it really impacted performance.
Needless to say they felt very silly when we explained how LINQ was deferred. -
I had rough week last week. Accidentally deployed dev code to production, soon found out there was no production version of code to do a redeploy. Deployed another app to production, it was working fine then another Dev changed a data type in the database from bool to nullable Boolean which broke some Linq queries. Looked like I deployed crap code. 3rd week with company.
-
Right now I need to fix 10 years old php code handling data sets coming from a database. Normally I work mostly on C#.
God, do I miss LINQ!8 -
My C# class loves to come up with weird/unrealistic scenarios to teach a specific language feature... I feel like the more effective way to teach would be to mention a real life scenario where it makes more sense to use the feature and give it some context rather than coming up with some arbitrary series of classes to represent departments and employees and then say "write extension methods for them to write them out"
If you tell me that I'm going to go, ok this works, but is there a specific reason I should do this instead of using a for or foreach to do the exact same thing? Don't get me wrong I see the appeal of extension methods as well as LINQ but this class never gives any sort of context as to why we're doing stuff. This class could be good, I've had classes that focus on language specific features taught in ways that make sense... My Java prof did a great job...
Also all the slides are terribly written...
Like I attached an example of the description for extension methods... The slides then go on to explain how the syntax for them works and gives an example...
Like ok I guess technically you told me what they are and how to use them, but gave zero context...
On the opposite end of the spectrum, I go to MSDN for their definition of extension methods, and it is much more clearly written and gives context to where/why they're used... and this is supposed to be a 5th semester course...2 -
Ffs
var filteredList = HugeList. Where(Condition);
if(filteredList.Count() > 0)
DoSomething(filteredList.First());
Just no. Please.10 -
We are researching enhancing our current alerting system (we use Splunk) to be 'smarter' about who is emailed/texted/whatever when there are problems in our applications.
Currently, if there are over 50 errors logged within a 15 minute period, a email/phone/text blast to nearly 100 individuals ranging from developers, network admins, DBAs, and vice presidents.
Our plan is to group errors by team and let each team manage their own applications. Alert on 1 error, 5, 500...we don't care, let the team work out the particulars.
The trick was interfacing with Splunk's API (that's a long rant by itself)
In about a day or so I was able to use Splunk's WebHook feature to notify a WebAPI service I threw together to send myself an email with details about the underlying data (simulating the kind of alert we would send to the team)
I thought ...cool... it worked. Show it off to the team, most thought it was a good start, except one:
Dev: "The errors are not grouped by team."
Me: "No, I threw the webapi service together to demonstrate how we can extract the splunk bits to get access to the teams"
Dev: "Well...this won't work at all."
Me: "Um..what?"
Dev: "The specification c l e a r l y states the email will be team based. This email was only sent to you and has all the teams and their applications"
Me: "Um...uh...the service can, if we want to go using a service route. Grouping by team name is easy using a LINQ query. I just through this service together yesterday."
Dev: "I don't know. Sounds like I need to schedule a meeting to discuss what you are proposing. I don't think emailing all that to everyone is a good idea."
WTF! Did you not listen to what I said?!!!
Oh well..the dev's proposal is to use splunk's email notification and custom Exchange rules with callbacks into splunk that resend...oh good lord ...a fracking rube goldberg of a config nightmare ...
I suspect we'll go the service route once I finish the service before the meeting.1 -
I've been trying to query some data from an 18 GB xml DB through BaseX for about 9 hours without success.
Just wondered how LinQ would work with the same xml info. Just got the info I needed in less than 15 minutes.
God bless LinQ.5 -
Spending hours upon hours trying to understand C# entity framework relational data mappings, going to the extreme of looking at LINQ queries, writing and rewriting over 100 lines of code only to find I needed to write the joins in dot notation on the include!5
-
!@#GDSGA!Q@#@
In my absolute lack of genius, I just lost way too much time finally realizing that in C# linq-to-objects removes duplicates when you use Union().
At one point I knew this, but I forgot about it because I never want duplicates, slowly forgetting what Union() was doing.
*This time* however, the duplicates are required and it all goes to crap without them.
Save me, Concat()!
You can run but you can't hide from noobery.
Blahb;asdfabnahsdfa.3 -
I went down a rabbit hole of code changes to try and delete a stupid for loop with a break in it.
It was super stupid and I gave up and submitted to the fact that some battles are not worth the time and stress.
OK... But seriously, It was returning multiple entities from the database, but we only always want the first one. My logic is that we should just go in there and fix the LINQ so we are explicitly getting one entity out.
But fuck that logic. No I'll have to change fucking everything that's tied to that method and expects a list from it. Every fucking thing. That includes error handling, parsing, for loops..... Nevermind...
You can have your foreach and your break. I'm taking mine, now.rant break my back on this stupid code what do you want on the frontend last minute changes did this to me they couldn't decide1 -
So I did this https://devrant.io/rants/797965/... which works fine until medium sized data.
However for large data the ETL pegs a 6 core Xeon (2.2GHz) with 50GB of ram. Because of it ends up doing six threaded compares, so 12 different data sets. Other than "pull less data", any tips?
Code (C#) is basically a Linq multi column join between two DataTables and when the compared columns don't match it returns as a var which is turned into a third DataTable to be SqlBulk loaded into the DB.
Table1 is external API return data (no windowing) and Table2 is from our DW.7 -
When people mail me asking something i think is stupid question i reply with this pic,
(It is also my profile picture on Linq now) :( -
I am now going to attempt the problem solving ritual.
Requirements:
-have a problem or piece of unoptimized code and you don't know how tk fix/improve it
-be able to sleep/take a nap
Now before I fall asleep the ritual should provide me with an epiphany to solve my problem
Plan b:
I have a class ninja (model), with an observablecollection<property> properties and an observablecollection<gearslot> gearslots;
,a class gear with an observablecollection<property> properties and an Category category:
And a class gearslot with a Gear gear and a Category category;
Via entity framework this results in several property entries per ninja
And several property entries per gear item
All good so far.
I now actually want the ninja property values, to be the sum of the gear property values
So a ninja has int, agi and str of 0.
Gear has 0 or more stats.
If the ninja has two pieces of gear on with agi +1, then the ninja agi should be 2
If possible i would like the logic in the model.
Else i have to put it in the viewmodel.
That i can figure out, its just so inelegant.... -
// First rant
So I've spent the last three days trying to send requests to a website in C# (never had done that, so I had to learn from scratch) and using XPath to select certain nodes from the html.
Today, I port it to a new UWP project and turns out it doesn't support XPath. I guess I should learn LINQ now...fml1 -
Mine and @jacoKotze's final exams for the year (maybe for a while too) are finally starting today. Up first: programming! The most ~complicated~ subject according to our classmates. (Did you notice the sarcasm?)
C# events and delegates, file streams, and LINQ are the "new" content next to the tests where we did exception handling and inheritance.4 -
I'm still not over how LINQ is defined as a thin wrapper over both IQueryable (which can be efficiently queried) and IEnumerable (which can only be iterated), but IQueryable extends IEnumerable, so if you execute one unserializable operation anywhere in a query issued to your database it'll merrily pump whatever temporary collection happens to reside on the boundary through the C# program to execute that call on each row and process the rest as an IEnumerable.5
-
Just spent 3 fucking hours trying to find out why my tests are failing. I'm mocking ef with an in memory sqlite dB as THE FUCKING. Net docs say to.
My code does a simple decimal comparison in a linq statement and returns bullshit. Why? Sqlite does not have a decimal type, it does some sort of BULLSHIT to convert it into some sort of text value.
I change all my models to use doubles instead of decimals and all my tests turn green.
WTF IS THIS SHIT. If it doesn't work don't tell me to use it. I expect better of the. Net docs. Wtf are they doing.3 -
It's a shame that people don't want to use F# but prise C# for how cool it became and continue becoming. At the same time, little do they know that many of the features were simply drawn from F#.
It's just rediculous how far this OO and C-Style syntax crap has progressed. They keep copying things from functional langugages, making the initial language to be a monstrocity like C++ is now, insted of just using languages like C#. I mean, it was right there before C#: async/task, immutablility, records, indexes, lambdas, non-null by default, who the hell knows what else.
Besides, many people (in my company at least) are just blindly overengineering with patterns and shit, where a simple function would be just enogh.
Watch some some NDC talks about F#, in particular those of Scott Wlaschin. It's just better in so many ways: less noice (I'm looking at you, brackets, commas and semicolons), the whole LOT of type inference and less duplication (just look at the C# signatures of linq methods - it's difficult to read them), immutability by default, non-nullable by default, ADTs and pattern matching, some neat features like type providers (how many times have used "paste special" or an online tool to create C# classes from a JSON/XML file, and how many times have your regenrated it because of schema changes?) and units of measure.
Of course, in some cases it's not optimal, in some cases mutable datastructures of C# are better for performance. But dude, how many performance critical systems have you wrote in C#? I mean, if it comes to performance you should use Rust or C++ or C after all.
*sighs*15 -
Lambda style Linq statements should be no longer then 1 line in C#
Current task debug 10 line Linq statement. Fml -
Let's agree on something :when asking your coworker for help, follow stack overflows guidelines, and we will all be happy. No one should guess about a certain linq that failed to filter with a "It's not working".
-
If only more devs would use short, yet concise, modern constructs instead of archaic ones.
For example in C#: using lambdas, extension methods, LinQ,.. much easier to read through if you know how these work, rather than having to spend all day scanning tedious for-loops and over-engineered classes your colleagues wrote who don't know any better.
Examples:
vs.foreach(v => console.write(v));
initialList = secondList.Where(p => initialList.Contains(p, valueComparer))
.Concat(initialList.Where(p => !secondList.Contains(p, valueComparer))).ToList(); -
Pardon the rant; some of it can probably attributed to me, but please indulge me of you could.
I'm tasked with creating a report that pulls data from some sql tables in c#and presents it using javascript. My manager was nice enough to lend me his old sql query, so I run with that using sql connections. Now I find out AFTER I get my sql query string working and retrieving data properly that my manager wanted it done using linq and entity framework, so now I have to start over, a process made only more "fun" by the confusing and unintuitive column names of our sql tables.
Moral of the story: don't take the easy way out.
After I spend some time fixing that up, I have to print out the data using javascript and html, which my manager was kind enough to lend me. Cue me shutting off my brain and thinking that I should have the program open and display this stuff itself. Let me tell you that converting a console application to a Windows form application is not a fun experience, especially when entity framework makes classes named "application" and "form" from your database tables. After finally getting the WebBrowser form to work, I'm hit with a javascript error from the library my manager referenced (he is a programmer himself). I tell him about the error and he just tells me to write the html code to a .html on disk like he did, but never explicitly said he did until just now.
Fixed moral of the story: don't take the easy way out, unless you should.
I should clarify I was given the whole raw sql query and html with some embedded javascript and a reference to chart.js. -
I feel like we we not only 'advanced' various fields by pulling people off some lord of the flies island who only wanted to dance around with a severed pig head in reality and training them, but also depleted and destroyed many essential fields by removing all valid motivators from our environment by spreading so much cynicism and unguided lust for power over others in the absence of any of the unifying beliefs of former generations that the professions are going to implode in the years to come.
so I wasn't very experienced when i went to work some place years back. I'd worked on my own. and I was criticized by their 80k per year team lead as having 'only done some simple things'... when his project didn't work, and par for the course their criticisms were coming from people who took a standard backend on a very large project that actually had been designed to function and something else likely needed fixed, to 'HEY LETS USE LINQ TO SQL APPARENTLY WITHOUT TESTING RELATIVE PERFORMANCE !!!!! AND WE'LL THROW SOME AD HOC QUERIES GENERATED BY MICROSOFT AT OUR SERVER INSTALLATION AND WATCH THE PERFORMANCE 'GAINS' THEN WE'LL BACKTRACK AND PUT STORED PROCEDURES BACK AND GENERATE HOOKS TO THEM LIKE A CLASSICAL DAL. JUST USING LINQ TO SQL'S CONTEXT OBJECT ! HURRAY I HAVE A BACHELORS AND 15 YEARS EXPERIENCE !'
There are so many details to fill in teaching the mindset of how to do things right in the first place is kind of expensive to begin with and you don't necessarily learn that in school working on common comp sci projects in academia. But they should have known better. I'm actually embarassed to list linq to sql on my resume as I think back.8 -
First development job I had, I wasn't allowed to use LINQ. According to my boss, it was the "lazy" way. So many for loops :(1
-
LINQ queries or stored procedures? I prefer LINQ.
My boss says, if we are using LINQ we must be lazy and stupid.
What do you'll think?7 -
Today I (/ later together with some colleagues) spent almost 4 hours trying to improve a Entity Framework LINQ to SQL query.
The initial problem was, that one of our List API endpoints took longer the more you "page" (besides the long response time it had anyways).
So after
- brainstorming in the team
- brainstorming alone
- hacking around and
- shouting at screens
- googling
we
- got nothing optimized
- got confused about what EF does
- lost the believe in our development skills
So Entity Framework is really a nice thing. But as soon as you look deeper, trying to figure out what it really does between ToList() and "yeah my data arrived" it is just....demonic.3 -
Does anyone here have experience with LINQ? I was hoping that anyone with some experience with it might be willing to share some opinions or insights about it. Like:
- Do you like LINQ?
- Does LINQ have shortcomings or easy pits to fall into when using it? (especially as a beginner)
- Do you use something besides LINQ? If so, why?
Sorry for bothering anyone on here with this, I'm just curious about the tech as I'm trying to learn C# and I'm not sure S.O. would appreciate opinion based questions.3 -
!rant
I just found out that if you have a list of lists in C#, you can use a LINQ statement and specify indices inside the lambda instead of nested ForEaches.
This code is giving me the vapors7 -
1) IList doesn't have an AddRange.
2) WPF bindings must be ObservableCollections
3) Comboxes using Event Notification on PropertyChange are originally developed by some dope at Microsoft who still doesn't comprehend Big-O
4) LINQ can only do so much...
It's Christmas. My gift from Santa is trying to get through an end of year crunch on a project that is made entirely out of hot sweaty year old garbage, and the garbage collector is a halfwit who comes seemingly only when they want to, regardless of when I call Dispose().
It's 12:26pm here. That means it's time for bourbon and a good bit of "F*** this, I'm done for the day."7 -
Am I the only one that thinks Linq's .Any() and .All() methods are more appropriately named for the use case they cater to, as opposed to their JS counterparts .some() and .every() ?
.some() doesn't justify the fact that it returns true if *atleast* one item in the collection matches the predicate. Should've been named something like .atleastOne() or something else.
Moreover, there isn't any harm to just use the same method names as in Linq ¯\_(ツ)_/¯4 -
Genuine 1 line function found in a production system:
private bool NotExists(int typeId) {
return !collection.Any(item => item.typeId == typeId) ? false : true;
}
I can't decide how many double negatives are involved here!1 -
!Rant
I just LOVE working with GraphQL now
Last time I was so in love with a techno, it was introduction of LinQ in net2 -
When I finally got LINQ method syntax... and found that I could shape my data any way I wanted, all in a single line of code
-
Top 12 C# Programming Tips & Tricks
Programming can be described as the process which leads a computing problem from its original formulation, to an executable computer program. This process involves activities such as developing understanding, analysis, generating algorithms, verification of essentials of algorithms - including their accuracy and resources utilization - and coding of algorithms in the proposed programming language. The source code can be written in one or more programming languages. The purpose of programming is to find a series of instructions that can automate solving of specific problems, or performing a particular task. Programming needs competence in various subjects including formal logic, understanding the application, and specialized algorithms.
1. Write Unit Test for Non-Public Methods
Many developers do not write unit test methods for non-public assemblies. This is because they are invisible to the test project. C# enables one to enhance visibility between the assembly internals and other assemblies. The trick is to include //Make the internals visible to the test assembly [assembly: InternalsVisibleTo("MyTestAssembly")] in the AssemblyInfo.cs file.
2. Tuples
Many developers build a POCO class in order to return multiple values from a method. Tuples are initiated in .NET Framework 4.0.
3. Do not bother with Temporary Collections, Use Yield instead
A temporary list that holds salvaged and returned items may be created when developers want to pick items from a collection.
In order to prevent the temporary collection from being used, developers can use yield. Yield gives out results according to the result set enumeration.
Developers also have the option of using LINQ.
4. Making a retirement announcement
Developers who own re-distributable components and probably want to detract a method in the near future, can embellish it with the outdated feature to connect it with the clients
[Obsolete("This method will be deprecated soon. You could use XYZ alternatively.")]
Upon compilation, a client gets a warning upon with the message. To fail a client build that is using the detracted method, pass the additional Boolean parameter as True.
[Obsolete("This method is deprecated. You could use XYZ alternatively.", true)]
5. Deferred Execution While Writing LINQ Queries
When a LINQ query is written in .NET, it can only perform the query when the LINQ result is approached. The occurrence of LINQ is known as deferred execution. Developers should understand that in every result set approach, the query gets executed over and over. In order to prevent a repetition of the execution, change the LINQ result to List after execution. Below is an example
public void MyComponentLegacyMethod(List<int> masterCollection)
6. Explicit keyword conversions for business entities
Utilize the explicit keyword to describe the alteration of one business entity to another. The alteration method is conjured once the alteration is applied in code
7. Absorbing the Exact Stack Trace
In the catch block of a C# program, if an exception is thrown as shown below and probably a fault has occurred in the method ConnectDatabase, the thrown exception stack trace only indicates the fault has happened in the method RunDataOperation
8. Enum Flags Attribute
Using flags attribute to decorate the enum in C# enables it as bit fields. This enables developers to collect the enum values. One can use the following C# code.
he output for this code will be “BlackMamba, CottonMouth, Wiper”. When the flags attribute is removed, the output will remain 14.
9. Implementing the Base Type for a Generic Type
When developers want to enforce the generic type provided in a generic class such that it will be able to inherit from a particular interface
10. Using Property as IEnumerable doesn’t make it Read-only
When an IEnumerable property gets exposed in a created class
This code modifies the list and gives it a new name. In order to avoid this, add AsReadOnly as opposed to AsEnumerable.
11. Data Type Conversion
More often than not, developers have to alter data types for different reasons. For example, converting a set value decimal variable to an int or Integer
Source: https://freelancer.com/community/...2 -
!rant, reality check.
This may sound odd, but sometimes i deny wanting to learn a term or meaning of something because it is a severed thing from my knowledge.
E.I.: i read "Hey you can use LINQ for this!" as i am programming in C#. I do not mind reading up on what LINQ is, why LINQ is etc.
But, if i run into something like hey you can use XAML or whatever the hell, which i can't mentally link to anything i know, i flatout even refuse to look it up, or try to find out if it is related to my skills and if not, flat out ignore anything besides the basic concept.
Eventually i could still end up learning it, but if it doesn't click from where i am at right now as a programmer, i just skip it as unrelated noise.
Technically i deny to learn something, making me a bad "student" in a way. Otherwise i use my time optimally to only expand my knowledge on the borders or my current knowledge.
Does anyone else does this? Anyone longer then 4 years? Does anyone also apply this outside of programming? How did all that go for you? Is it a bad habbit or a good one?3 -
I don't know if this counts but wrote a generator that replaced a shitty linq to sql dal to use our system so I didn't have to mess with a web app I'd written. In place replacement with a few methods that made the other transaction lock field updates and calls etc
Most risky I can think of
Everything else was data migrations but there were always backups1 -
hand-wrote me some gnarly-ass SQL today to resolve a prod "emergency". I was kinda proud that I did so and only had to google syntax once. Then my pride turned to shame when I realized what a spoiled little bitch LINQ has made of me.1