日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

使用BigQuery分析GitHub上的C#代码

發布時間:2023/12/4 C# 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用BigQuery分析GitHub上的C#代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一年多以前,Google 在GitHub中提供了BigQuery用于查詢的GitHub上的開源代碼(open source code on GitHub available for querying),如果這還不夠,您可以免費每月運行1TB的查詢!

所以在這篇文章中,我將要收集GitHub上的所有我們可以訪問的C#源代碼。非常簡單,只包含C#,而且數據集已經收集完成(在BigQuery中,是按字節讀取收費的),稱為fh-bigquery:github_extracts.contents_net_cs?并具有

  • 5,885,933?不重復的“.cs”文件

  • 792,166,632?行代碼 (LOC)

  • 37.17 GB?(37,174,783,891 bytes) 數據

這是一套非常全面的C#源代碼!


這篇文章的剩余部分將?嘗試?回答以下問題:

  • Tab或空格?

  • regions:“應該被禁止”或“在某些情況下使用”?

  • “K&R” or “Allman”, C#開發者喜歡把它們的大括號放在哪里?(譯者注:關于‘K&R’ 與 ‘Allman’,請參考維基百科)

  • 然后轉到一些沒有爭議的C#主題:

  • 哪些using 聲明使用最廣泛?

  • 哪些NuGet軟件包常常被包含在.NET項目中

  • C#文件一般有多少行代碼(LOC)?

  • 使用最廣泛的“Exception”是哪一個?

  • 使用“async/await”?

  • C#開發人員是否喜歡使用“var”關鍵字?

  • 在我們最終看到Repository:

  • 包含C#代碼最流行的Repository是哪一些

  • 在一個Repository中一般有多少個文件?

  • 最受歡迎的C# Class 名稱中哪些?

  • “Foo.cs”,“Program.cs”或其它,最常見的文件是哪些?

  • 如果您想為自己嘗試查詢(或發現我的錯誤),那么所有這些查詢可以在github上面找到,鏈接地址。很有可能我的正則表達式遺漏了一些邊緣案例,畢竟正則表達式:現在有兩個問題:


    Tab或空格?

    在整個數據集中有5,885,933個文件,但是我們只包括一個從Tab或空格開始的10行以上的文件

    Tabs Tab(百分比) 空格 空格(百分比) 總計
    799,055 17.15% 3,859,528 82.85% 4,658,583

    顯然,C#開發人員(在GitHub上)喜歡空格超過Tab?!(我認為一些這可以通過Visual Studio中的事實來解釋:默認情況下使用“空格”)。

    如果您想了解C#與其它編程語言的比較,請查看40萬個GitHub資源庫,10億個文件,14太字節的代碼:空格或制表符?。

    regions:“應該被禁止”或“在某些情況下使用”?

    事實證明,有一個令人印象深刻的712,498 C#文件(總共580萬),至少包含一個#region語句(查詢方法),只有超過12%。(我希望很多這些文件已被工具自動生成!)

    “K&R” or “Allman” ,C#開發者喜歡把它們的大括號放在哪里?

    C#開發人員絕大多數喜歡將打開大括號{放在當單獨的行上(查詢方法)

    單獨行 同一行 同一個(初始化實例) 總計 (包括大括號) 總計(全部代碼)
    81,306,320 (67%) 40,044,603 (33%) 3,631,947 (2.99%) 121,350,923 (15.32%) 792,166,632

    (“同一行初始化實例”包括代碼new { Name = "", .. },new [] { 1, 2, 3.. })


    哪些 using 聲明 使用最廣泛?

    這是一個更實質的統計,C#代碼中,using?聲明 最廣泛的語句是哪一些?

    顯示前10名結果(全部統計結果在這里查看):

    using 聲明 總計
    using System.Collections.Generic; 1,780,646
    using System; 1,477,019
    using System.Linq; 1,319,830
    using System.Text; 902,165
    using System.Threading.Tasks; 628,195
    using System.Runtime.InteropServices; 431,867
    using System.IO; 407,848
    using System.Runtime.CompilerServices; 338,686
    using System.Collections; 289,867
    using System.Reflection; 218,369

    但是,當您在Visual Studio中添加新文件時,默認情況下包含前5個,許多人不會刪除它們。默認情況下,“AssemblyInfo.cs”中包含的“System.Runtime.InteropServices”和“System.Runtime.CompilerServices”也是一樣。

    所以如果我們考慮到這一點,調整一下統計規則,前10名的結果是:

    using 聲明 總計
    using System.IO; 407,848
    using System.Collections; 289,867
    using System.Reflection; 218,369
    using System.Diagnostics; 201,341
    using System.Threading; 179,168
    using System.ComponentModel; 160,681
    using System.Web; 160,323
    using System.Windows.Forms; 137,003
    using System.Globalization; 132,113
    using System.Drawing; 127,033

    最后,using?聲明不在System,Microsoft和Windows命名空間的前10名統計結果 :

    using 聲明 總計
    using NUnit.Framework; 119,463
    using UnityEngine; 117,673
    using Xunit; 99,099
    using Newtonsoft.Json; 81,675
    using Newtonsoft.Json.Linq; 29,416
    using Moq; 23,546
    using UnityEngine.UI; 20,355
    using UnityEditor; 19,937
    using Amazon.Runtime; 18,941
    using log4net; 17,297

    哪些NuGet軟件包常常被包含在.NET項目中

    還有一個單獨的數據集包含GitHub上的所有‘packages.config’文件,它被稱為contents_net_packages_config,有104,808個條目。通過查詢,我們可以看到Json.Net是完勝的贏家!

    package 總計
    Newtonsoft.Json 45,055
    Microsoft.Web.Infrastructure 16,022
    Microsoft.AspNet.Razor 15,109
    Microsoft.AspNet.WebPages 14,495
    Microsoft.AspNet.Mvc 14,236
    EntityFramework 14,191
    Microsoft.AspNet.WebApi.Client 13,480
    Microsoft.AspNet.WebApi.Core 12,210
    Microsoft.Net.Http 11,625
    jQuery 10,646
    Microsoft.Bcl.Build 10,641
    Microsoft.Bcl 10,349
    NUnit 10,341
    Owin 9,681
    Microsoft.Owin 9,202
    Microsoft.AspNet.WebApi.WebHost 9,007
    WebGrease 8,743
    Microsoft.AspNet.Web.Optimization 8,721
    Microsoft.AspNet.WebApi 8,179

    一般C#文件中有多少行代碼(LOC)?

    C#開發人員是否容易創建巨大的文件,可以為1000的行?

    注意Y軸是“代碼行”,原始數據。

    您是否想知道十大最大的C#文件是哪些呢!

    文件 行數
    MarMot/Input/test.marmot.cs 92663
    src/CodenameGenerator/WordRepos/LastNamesRepository.cs 88810
    cs_inputtest/cs_02_7000.cs 63004
    cs_inputtest/cs_02_6000.cs 54004
    src/ML NET20/Utility/UserName.cs 52014
    MWBS/Dictionary/DefaultWordDictionary.cs 48912
    Sources/Accord.Math/Matrix/Matrix.Comparisons1.Generated.cs 48407
    UrduProofReader/UrduLibs/Utils.cs 48255
    cs_inputtest/cs_02_5000.cs 45004
    css/style.cs 44366

    使用最廣泛的“Exception”是哪一個?

    這里有一些有趣的結果(查詢方式),誰知道這么多ApplicationExceptions被拋出來,NotSupportedException這么高令人有點擔心!

    Exception 總計
    throw new ArgumentNullException 699,526
    throw new ArgumentException 361,616
    throw new NotImplementedException 340,361
    throw new InvalidOperationException 260,792
    throw new ArgumentOutOfRangeException 160,640
    throw new NotSupportedException 110,019
    throw new HttpResponseException 74,498
    throw new ValidationException 35,615
    throw new ObjectDisposedException 31,129
    throw new ApplicationException 30,849
    throw new UnauthorizedException 21,133
    throw new FormatException 19,510
    throw new SerializationException 17,884
    throw new IOException 15,779
    throw new IndexOutOfRangeException 14,778
    throw new NullReferenceException 12,372
    throw new InvalidDataException 12,260
    throw new ApiException 11,660
    throw new InvalidCastException 10,510

    使用“async/await”?

    在C#語言中使用async和await關鍵字編寫異步代碼更容易:

    ? ?public async Task<int> GetDotNetCountAsync() ? ?{ ? ? ? ?// Suspends GetDotNetCountAsync() to allow the caller (the web server)// to accept another request, rather than blocking on this one.var html = await _httpClient.DownloadStringAsync("http://dotnetfoundation.org"); ? ?return Regex.Matches(html, ".NET").Count;}

    但它使用了多少?使用下面的查詢:

    SELECT Count(*) countFROM[fh-bigquery:github_extracts.contents_net_cs] ? ?WHEREREGEXP_MATCH(content, r'\sasync\s|\sawait\s')

    我發現有218,643個文件(總共5,885,933個)至少使用一個async、await關鍵字。

    C#開發人員是否喜歡使用“var”關鍵字?

    比async、await關鍵字使用的更少,只有130,590個文件至少有一個var關鍵字被使用。


    在一個Repository中一般有多少個文件?

    90%的Repository(具有任何C#文件)具有95個或更少的文件。95%具有170個文件或更少,99%具有535個或更少的文件。

    (Y軸(C##文件)是個數)

    根據C#文件數量排名前10的最大Repository如下所示:

    Repository C#文件數
    https://github.com/xen2/mcs 23389
    https://github.com/mater06/LEGOChimaOnlineReloaded 14241
    https://github.com/Microsoft/referencesource 13051
    https://github.com/dotnet/corefx 10652
    https://github.com/apo-j/Projects_Working 10185
    https://github.com/Microsoft/CodeContracts 9338
    https://github.com/drazenzadravec/nequeo 8060
    https://github.com/ClearCanvas/ClearCanvas 7946
    https://github.com/mwilliamson-firefly/aws-sdk-net 7860
    https://github.com/151706061/MacroMedicalSystem 7765

    最受歡迎的Repository是哪一些(其中有C#代碼)?

    這次我們將要統計包含至少50個C#文件(查詢方式)的最受歡迎的Repository(基于GitHub'stars' ):

    Repository stars 文件數
    https://github.com/grpc/grpc 11075 237
    https://github.com/dotnet/coreclr 8576 6503
    https://github.com/dotnet/roslyn 8422 6351
    https://github.com/facebook/yoga 8046 73
    https://github.com/bazelbuild/bazel 7123 132
    https://github.com/dotnet/corefx 7115 10652
    https://github.com/SeleniumHQ/selenium 7024 512
    https://github.com/Microsoft/WinObjC 6184 81
    https://github.com/qianlifeng/Wox 5674 207
    https://github.com/Wox-launcher/Wox 5674 142
    https://github.com/ShareX/ShareX 5336 766
    https://github.com/Microsoft/Windows-universal-samples 5130 1501
    https://github.com/NancyFx/Nancy 3701 957
    https://github.com/chocolatey/choco 3432 248
    https://github.com/JamesNK/Newtonsoft.Json 3340 650

    有趣的是,第一名是Google Repository!(其中的C#文件是使用.NET中的GRPC庫的示例代碼)

    最受歡迎的C# Class 名稱中哪些?

    假設我使用正則表達式,最流行的C#?class名稱如下:

    Class 名稱 總計
    class C 182480
    class Program 163462
    class Test 50593
    class Settings 40841
    class Resources 39345
    class A 34687
    class App 28462
    class B 24246
    class Startup 18238
    class Foo 15198

    Yay?Foo,偷偷進入前10!

    'Foo.cs','Program.cs'或其它,最常見的文件是哪些?

    最后,我們來看看class使用的不同的名稱,就像using聲明作為Visual Studio默認模板一樣:

    文件 總計
    AssemblyInfo.cs 386822
    Program.cs 105280
    Resources.Designer.cs 40881
    Settings.Designer.cs 35392
    App.xaml.cs 21928
    Global.asax.cs 16133
    Startup.cs 14564
    HomeController.cs 13574
    RouteConfig.cs 11278
    MainWindow.xaml.cs 11169

    原文:《Analysing C# code on GitHub with BigQuery》http://mattwarren.org/2017/10/12/Analysing-C-code-on-GitHub-with-BigQuery/
    翻譯:Sweet Tang
    本文地址:http://www.cnblogs.com/tdfblog/p/Analysing-C-code-on-GitHub-with-BigQuery.html


    .NET社區新聞,深度好文,微信中搜索dotNET跨平臺或掃描二維碼關注

    總結

    以上是生活随笔為你收集整理的使用BigQuery分析GitHub上的C#代码的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。